From: martinahansen Date: Wed, 17 Jun 2009 11:09:22 +0000 (+0000) Subject: fixed a number of bugs in PSL X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=68b0d2096e200e63bb06f1e20c04761ddb9bc68b;p=biopieces.git fixed a number of bugs in PSL git-svn-id: http://biopieces.googlecode.com/svn/trunk@539 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/blast_seq b/bp_bin/blast_seq index 00270a3..de78c35 100755 --- a/bp_bin/blast_seq +++ b/bp_bin/blast_seq @@ -212,8 +212,6 @@ sub get_tab_entry @fields = split /\s+/, $line; - use Data::Dumper; - return wantarray ? @fields : \@fields; } diff --git a/bp_bin/blat_seq b/bp_bin/blat_seq index e7dbc3a..342c5cd 100755 --- a/bp_bin/blat_seq +++ b/bp_bin/blat_seq @@ -87,11 +87,15 @@ $blat_args .= " -q=$type"; $result_file = "$tmp_dir/blat.psl"; -Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file > /dev/null 2>&1" ); +if ( $options->{ 'verbose' } ) { + Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file" ); +} else { + Maasha::Common::run( "blat", "$genome_file $query_file $blat_args $result_file > /dev/null 2>&1" ); +} unlink $query_file; -$fh_in = Maasha::Filesys::file_read_opem( $result_file ); +$fh_in = Maasha::Filesys::file_read_open( $result_file ); while ( $entry = Maasha::UCSC::PSL::psl_entry_get( $fh_in ) ) { diff --git a/bp_bin/write_psl b/bp_bin/write_psl index 404e21a..6956a23 100755 --- a/bp_bin/write_psl +++ b/bp_bin/write_psl @@ -57,8 +57,8 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) if ( $record->{ "REC_TYPE" } and $record->{ "REC_TYPE" } eq "PSL" ) { - Maasha::UCSC::psl_put_header( $fh ) if $first; - Maasha::UCSC::psl_put_entry( $record, $fh ); + Maasha::UCSC::PSL::psl_put_header( $fh ) if $first; + Maasha::UCSC::PSL::psl_put_entry( $record, $fh ); $first = 0; } } diff --git a/code_perl/Maasha/UCSC.pm b/code_perl/Maasha/UCSC.pm index fad1401..5a8ad95 100644 --- a/code_perl/Maasha/UCSC.pm +++ b/code_perl/Maasha/UCSC.pm @@ -683,68 +683,6 @@ CREATE TABLE $table ( } -sub psl_put_header -{ - # Martin A. Hansen, September 2007. - - # Write a PSL header to file. - - my ( $fh, # file handle - OPTIONAL - ) = @_; - - # Returns nothing. - - $fh = \*STDOUT if not $fh; - - print $fh qq(psLayout version 3 -match mis- rep. N's Q gap Q gap T gap T gap strand Q Q Q Q T T T T block blockSizes qStart match match count bases count bases name size start end name size start end count ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -); -} - - -sub psl_put_entry -{ - # Martin A. Hansen, September 2007. - - # Write a PSL entry to file. - - my ( $record, # hashref - $fh, # file handle - OPTIONAL - ) = @_; - - # Returns nothing. - - $fh = \*STDOUT if not $fh; - - my @output; - - push @output, $record->{ "MATCHES" }; - push @output, $record->{ "MISMATCHES" }; - push @output, $record->{ "REPMATCHES" }; - push @output, $record->{ "NCOUNT" }; - push @output, $record->{ "QNUMINSERT" }; - push @output, $record->{ "QBASEINSERT" }; - push @output, $record->{ "SNUMINSERT" }; - push @output, $record->{ "SBASEINSERT" }; - push @output, $record->{ "STRAND" }; - push @output, $record->{ "Q_ID" }; - push @output, $record->{ "Q_LEN" }; - push @output, $record->{ "Q_BEG" }; - push @output, $record->{ "Q_END" } + 1; - push @output, $record->{ "S_ID" }; - push @output, $record->{ "S_LEN" }; - push @output, $record->{ "S_BEG" }; - push @output, $record->{ "S_END" } + 1; - push @output, $record->{ "BLOCK_COUNT" }; - push @output, $record->{ "BLOCK_LENS" }; - push @output, $record->{ "Q_BEGS" }; - push @output, $record->{ "S_BEGS" }; - - print $fh join( "\t", @output ), "\n"; -} - - sub psl_upload_to_ucsc { # Martin A. Hansen, September 2007. diff --git a/code_perl/Maasha/UCSC/PSL.pm b/code_perl/Maasha/UCSC/PSL.pm index 75dfb59..d0ff611 100644 --- a/code_perl/Maasha/UCSC/PSL.pm +++ b/code_perl/Maasha/UCSC/PSL.pm @@ -109,11 +109,13 @@ sub psl_entry_get while ( $line = <$fh> ) { + next if $line !~ /^\d/; + chomp $line; @fields = split "\t", $line; - return wantarray ? @fields : \@fields if scalar @fields == 21; + return wantarray ? @fields : \@fields; # 21 fields } return undef; @@ -135,27 +137,27 @@ sub psl2biopiece %record = ( REC_TYPE => "PSL", - BLOCK_LENS => $psl->{ 'blockSize' }, - SNUMINSERT => $psl->{ 'tNumInsert' }, - Q_END => $psl->{ 'qEnd' }, - SBASEINSERT => $psl->{ 'tBaseInsert' }, - S_END => $psl->{ 'tEnd' }, - QBASEINSERT => $psl->{ 'qBaseInsert' }, - REPMATCHES => $psl->{ 'repMatches' }, - QNUMINSERT => $psl->{ 'qNumInsert' }, - MISMATCHES => $psl->{ 'misMatches' }, - BLOCK_COUNT => $psl->{ 'blockCount' }, - Q_LEN => $psl->{ 'qSize' }, - S_ID => $psl->{ 'tName' }, - STRAND => $psl->{ 'strand' }, - Q_ID => $psl->{ 'qName' }, - MATCHES => $psl->{ 'matches' }, - S_LEN => $psl->{ 'tSize' }, - NCOUNT => $psl->{ 'nCount' }, - Q_BEGS => $psl->{ 'qStarts' }, - S_BEGS => $psl->{ 'tStarts' }, - S_BEG => $psl->{ 'tStart' }, - Q_BEG => $psl->{ 'qStart ' }, + BLOCK_LENS => $psl->[ blockSizes ], + SNUMINSERT => $psl->[ tNumInsert ], + Q_END => $psl->[ qEnd ], + SBASEINSERT => $psl->[ tBaseInsert ], + S_END => $psl->[ tEnd ], + QBASEINSERT => $psl->[ qBaseInsert ], + REPMATCHES => $psl->[ repMatches ], + QNUMINSERT => $psl->[ qNumInsert ], + MISMATCHES => $psl->[ misMatches ], + BLOCK_COUNT => $psl->[ blockCount ], + Q_LEN => $psl->[ qSize ], + S_ID => $psl->[ tName ], + STRAND => $psl->[ strand ], + Q_ID => $psl->[ qName ], + MATCHES => $psl->[ matches ], + S_LEN => $psl->[ tSize ], + NCOUNT => $psl->[ nCount ], + Q_BEGS => $psl->[ qStarts ], + S_BEGS => $psl->[ tStarts ], + S_BEG => $psl->[ tStart ], + Q_BEG => $psl->[ qStart ], ); $record{ "SCORE" } = $record{ "MATCHES" } + int( $record{ "REPMATCHES" } / 2 ) - $record{ "MISMATCHES" } - $record{ "QNUMINSERT" } - $record{ "SNUMINSERT" }; @@ -189,6 +191,70 @@ sub psl_calc_score } +sub psl_put_header +{ + # Martin A. Hansen, September 2007. + + # Write a PSL header to file. + + my ( $fh, # file handle - OPTIONAL + ) = @_; + + # Returns nothing. + + $fh = \*STDOUT if not $fh; + + print $fh qq(psLayout version 3 +match mis- rep. N's Q gap Q gap T gap T gap strand Q Q Q Q T T T T block blockSizes qStart match match count bases count bases name size start end name size start end count +--------------------------------------------------------------------------------------------------------------------------------------------------------------- +); +} + + +sub psl_put_entry +{ + # Martin A. Hansen, September 2007. + + # Write a PSL entry to file. + + my ( $record, # hashref + $fh, # file handle - OPTIONAL + ) = @_; + + # Returns nothing. + + $fh = \*STDOUT if not $fh; + + my @output; + + push @output, $record->{ "MATCHES" }; + push @output, $record->{ "MISMATCHES" }; + push @output, $record->{ "REPMATCHES" }; + push @output, $record->{ "NCOUNT" }; + push @output, $record->{ "QNUMINSERT" }; + push @output, $record->{ "QBASEINSERT" }; + push @output, $record->{ "SNUMINSERT" }; + push @output, $record->{ "SBASEINSERT" }; + push @output, $record->{ "STRAND" }; + push @output, $record->{ "Q_ID" }; + push @output, $record->{ "Q_LEN" }; + push @output, $record->{ "Q_BEG" }; + push @output, $record->{ "Q_END" } + 1; + push @output, $record->{ "S_ID" }; + push @output, $record->{ "S_LEN" }; + push @output, $record->{ "S_BEG" }; + push @output, $record->{ "S_END" } + 1; + push @output, $record->{ "BLOCK_COUNT" }; + push @output, $record->{ "BLOCK_LENS" }; + push @output, $record->{ "Q_BEGS" }; + push @output, $record->{ "S_BEGS" }; + + print $fh join( "\t", @output ), "\n"; +} + + + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<