把FASTA序列文件和QUAL质量文件合并成FASTQ文件

资料来源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl -w
 
use strict;
 
use Bio::SeqIO;
use Bio::Seq::Quality;
use Getopt::Long;
 
die "pass a fasta and a fasta-quality filen" unless @ARGV;
 
my ( $seq_infile, $qual_infile ) =
 ( scalar @ARGV == 1 ) ? ( $ARGV[0], "$ARGV[0].qual" ) : @ARGV;
 
## Create input objects for both a seq (fasta) and qual file
my $in_seq_obj = Bio::SeqIO->new(
   -file   => $seq_infile,
   -format => 'fasta',
);
 
my $in_qual_obj = Bio::SeqIO->new(
   -file   => $qual_infile,
   -format => 'qual',
);
 
my $out_fastq_obj = Bio::SeqIO->new( -format => 'fastq' );
 
while (1) {
   ## create objects for both a seq and its associated qual
   my $seq_obj = $in_seq_obj->next_seq || last;
   my $qual_obj = $in_qual_obj->next_seq;
   die "foo!n" unless $seq_obj->id eq $qual_obj->id;
   ## Here we use seq and qual object methods feed info for new BSQ
   ## object.
   my $bsq_obj = Bio::Seq::Quality->new(
       -id   => $seq_obj->id,
       -seq  => $seq_obj->seq,
       -qual => $qual_obj->qual,
   );
   ## and print it out.
   $out_fastq_obj->write_fastq($bsq_obj);
}