]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/bowtie_seq
fixed encoding bug in bowtie_seq
[biopieces.git] / bp_bin / bowtie_seq
index 44d09ae14db52bef69c0578b11900ed1f4de0193..07374216593d0a6f24d7fd858f6de3b21c6377ec 100755 (executable)
@@ -35,6 +35,11 @@ use Maasha::Fastq;
 use Maasha::Fasta;
 use Maasha::Calc;
 
+use constant {
+    SEQ_NAME => 0,
+    SEQ      => 1,
+    SCORES   => 2,
+};
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
@@ -75,6 +80,7 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
     if ( $entry = Maasha::Fastq::biopiece2fastq( $record ) )
     {
         Maasha::Common::error( "Mixed FASTA and FASTQ entries in stream" ) if defined $type and $type ne "FASTQ";
+        Maasha::Common::error( "Sequence longer than 1024 not allowed")    if length( $entry->[ SEQ ] ) > 1024;
         Maasha::Fastq::put_entry( $entry, $fh_out );
 
         $type = "FASTQ";
@@ -82,6 +88,7 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
     elsif ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
     {
         Maasha::Common::error( "Mixed FASTA and FASTQ entries in stream" ) if defined $type and $type ne "FASTA";
+        Maasha::Common::error( "Sequence longer than 1024 not allowed")    if length( $entry->[ SEQ ] ) > 1024;
         Maasha::Fasta::put_entry( $entry, $fh_out );
 
         $type = "FASTA";
@@ -96,6 +103,7 @@ push @args, "-n $options->{ 'mismatches' }";
 push @args, "-v $options->{ 'mismatches' }";  # DANGER: using seed mismatches as alignment mismatches - may work, may not!
 push @args, "-f" if $type eq "FASTA";
 push @args, "-p $options->{ 'cpus' }";
+push @args, "--phred33-quals" unless $type eq "FASTA";
 
 if ( defined $options->{ 'max_hits' } ) {
     push @args, "-k $options->{ 'max_hits' }";
@@ -153,21 +161,9 @@ sub bowtie2biopiece
 
     my ( $record, $s_id, $s_len, $hits );
 
-    # S_ID: contig00005 length=75232   numreads=13115
-
-    if ( $entry->[ 2 ] =~ /^(.+) length=(\d+)\s+numreads=(\d+)$/ )
-    {
-        $record->{ 'S_ID' }  = $1;
-        # $record->{ 'S_LEN' } = $2;
-        $record->{ 'HITS' }  = $3;
-    }
-    else
-    {
-        Maasha::Common::error( qq(BAD S_ID: "$entry->[ 2 ]") );
-    }
-
     $record->{ 'Q_ID' }       = $entry->[ 0 ];
     $record->{ 'STRAND' }     = $entry->[ 1 ];
+    $record->{ 'S_ID' }       = $entry->[ 2 ];
     $record->{ 'S_BEG' }      = $entry->[ 3 ];
     $record->{ 'SEQ' }        = $entry->[ 4 ];
     $record->{ 'SCORES' }     = $entry->[ 5 ];
@@ -176,9 +172,9 @@ sub bowtie2biopiece
     $record->{ 'S_LEN' }      = length $entry->[ 4 ];
     $record->{ 'SEQ_LEN' }    = length $entry->[ 4 ];
     $record->{ 'S_END' }      = $record->{ 'S_BEG' } + $record->{ 'SEQ_LEN' } - 1;
-    $record->{ 'SCORES' }     =~ s/(.)/ord( $1 ) - 33 . ";"/ge; # http://maq.sourceforge.net/fastq.shtml
-    $record->{ 'SCORE_MEAN' } = sprintf( "%.2f", Maasha::Calc::mean( [ split /;/, $record->{ 'SCORES' } ] ) );
+    $record->{ 'SCORES' }     =~ s/(.)/chr( ( ord( $1 ) - 33 ) + 64 )/ge; # convert phred scores to illumina scores
 
+    $record->{ 'HITS' }       = '.';
     $record->{ 'REC_TYPE' } = "BOWTIE";
 
     return wantarray ? %{ $record } : $record;