| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use Data::Dumper; | ||
| 7 | use Carp; | ||
| 8 | |||
| 9 | use 5.010; | ||
| 10 | |||
| 11 | use Bio::SeqIO; | ||
| 12 | use Bio::Seq::Quality; | ||
| 13 | |||
| 14 | use Getopt::Long::Descriptive; | ||
| 15 | |||
| 16 | my ( $opt, $usage ) = describe_options( | ||
| 17 | '%c %o <seq_file> <qual_file>', | ||
| 18 | [], | ||
| 19 | [ 'variant|v=s', "can be solexa, illumina, sanger", { default => 'sanger' } ], | ||
| 20 | [ 'help', "print usage message and exit" ], | ||
| 21 | ); | ||
| 22 | |||
| 23 | print( $usage->text ), exit if $opt->help; | ||
| 24 | |||
| 25 | die "pass a fasta and a fasta-quality file\n" | ||
| 26 | unless @ARGV; | ||
| 27 | |||
| 28 | my ( $seq_infile, $qual_infile ) = ( scalar @ARGV == 1 ) ? ( $ARGV[0], "$ARGV[0].qual" ) : @ARGV; | ||
| 29 | |||
| 30 | ## Create input objects for both a seq (fasta) and qual file | ||
| 31 | |||
| 32 | my $in_seq_obj = Bio::SeqIO->new( | ||
| 33 | -file => $seq_infile, | ||
| 34 | -format => 'fasta', | ||
| 35 | ); | ||
| 36 | |||
| 37 | my $in_qual_obj = Bio::SeqIO->new( | ||
| 38 | -file => $qual_infile, | ||
| 39 | -format => 'qual', | ||
| 40 | ); | ||
| 41 | |||
| 42 | my $out_fastq_obj = Bio::SeqIO->new( -format => 'fastq', -variant => $opt->variant ); | ||
| 43 | |||
| 44 | while (1) { | ||
| 45 | ## create objects for both a seq and its associated qual | ||
| 46 | my $seq_obj = $in_seq_obj->next_seq || last; | ||
| 47 | my $qual_obj = $in_qual_obj->next_seq; | ||
| 48 | |||
| 49 | die "foo!\n" | ||
| 50 | unless $seq_obj->id eq $qual_obj->id; | ||
| 51 | |||
| 52 | ## Here we use seq and qual object methods feed info for new BSQ | ||
| 53 | ## object. | ||
| 54 | my $bsq_obj = Bio::Seq::Quality->new( | ||
| 55 | -id => $seq_obj->id, | ||
| 56 | -seq => $seq_obj->seq, | ||
| 57 | -qual => $qual_obj->qual, | ||
| 58 | ); | ||
| 59 | |||
| 60 | ## and print it out. | ||
| 61 | $out_fastq_obj->write_fastq($bsq_obj); | ||
| 62 | } | ||
| 63 |