- #!/usr/bin/perl
- use Bio::SeqIO;
- $in = Bio::SeqIO->new( -format => 'fasta', -file => 'example.ta' );
- $out = Bio::SeqIO->new( -format => 'fastq', -file => '>out' );
- while ( my $seq = $in->next_seq ) {
- my $id_ta = $seq->id;
- my $seq_ta = $seq->seq;
- my $hash = Qual('example2.txt');
- my $seq_tq = Bio::Seq::Quality->new(
- -qual => $hash->{$id_ta},
- -seq => $seq_ta,
- -id => $id_ta,
- #-trace_indices => $trace,
- #-accession_number => '',
- #-verbose => -1 # to silence deprecated methods
- );
- $out->write_seq($seq_tq);
- }
- sub Qual {
- my $file = shift;
- local $/ = '+';
- open my $FH, "<$file";
- my %hash;
- while ( my $line = <$FH> ) {
- my ( $id, $q1, $q2 ) = split( "\n", $line );
- my $qual = $q1 . ' ' . $q2;
- $hash{$id} = $qual;
- }
- close $FH;
- return \%hash;
- }
- __END__
- 转换fasta到fastq格式:
- 1、序列:(example.ta)
- ">NG-5065_R-0-18_1_1_1_5_743/1
- AACAAACCAACAAACNCTAACAAACCCTTTCCGNTTCCANAAANTNTNCNNNNAANNCNNNNGNCANNNCNAANAN
- >NG-5065_R-0-18_1_1_1_5_1184/1
- TTCGAAGGCCTTCCCGGCACGACGAACGGATGTCCAATTGGTTTCGTAGTAGTGTCANNNNNNNNTCGATCANGACA";
- 2、其对应的序列质量为:(example2.txt)
- +NG-5065_R-0-18_1_1_1_5_743/1
- 22 34 32 32 28 32 32 32 30 32 32 31 26 33 30 4 29 34 34 34 32 29 32 25 33 33 30 33 34 34 31 28 29 4 29 34 33 34 2 2 2 2 2 2 2 2 2 2 2
- 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
- +NG-5065_R-0-18_1_1_1_5_1184/1
- 33 23 29 21 32 32 32 32 25 31 33 28 26 31 14 4 19 33 33 32 30 25 28 32 22 10 11 9 28 32 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
- 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
01-13 04:30