From c6822593fba7a4ae2a86d269450fa1f3f1a93417 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 30 Sep 2009 07:55:35 +0000 Subject: [PATCH] fixed bug in get_genome_seq git-svn-id: http://biopieces.googlecode.com/svn/trunk@688 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/get_genome_seq | 27 ++++++++++++--------------- code_perl/Maasha/SAM.pm | 2 ++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bp_bin/get_genome_seq b/bp_bin/get_genome_seq index 0e8d1f7..e219c51 100755 --- a/bp_bin/get_genome_seq +++ b/bp_bin/get_genome_seq @@ -28,6 +28,7 @@ use warnings; use strict; +use Data::Dumper; use Maasha::Biopieces; use Maasha::Filesys; use Maasha::Fasta; @@ -38,7 +39,7 @@ use Maasha::Seq; my ( $options, $in, $out, $record, $genome_file, $index_file, $fh, $genome, - $beg, $end, $len, $index_beg, $index_len, @begs, @lens, $index, $seq, $i, %lookup_hash ); + $beg, $end, $len, $index_beg, $index_len, @begs, @lens, $index, $seq, $i ); $options = Maasha::Biopieces::parse_options( [ @@ -66,13 +67,9 @@ if ( $options->{ "genome" } ) $fh = Maasha::Filesys::file_read_open( $genome_file ); $index = Maasha::Fasta::index_retrieve( $index_file ); - shift @{ $index }; # Get rid of the file size info - - map { $lookup_hash{ $_->[ 0 ] } = [ $_->[ 1 ], $_->[ 2 ] ] } @{ $index }; - - if ( defined $options->{ "chr" } and exists $lookup_hash{ $options->{ "chr" } } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) ) + if ( defined $options->{ "chr" } and exists $index->{ $options->{ "chr" } } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) ) { - ( $index_beg, $index_len ) = @{ $lookup_hash{ $options->{ "chr" } } }; + ( $index_beg, $index_len ) = @{ $index->{ $options->{ "chr" } } }; $beg = $index_beg + $options->{ "beg" } - 1; @@ -112,30 +109,30 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) { if ( $options->{ "genome" } and not $record->{ "SEQ" } ) { - if ( $record->{ "REC_TYPE" } eq "BED" and exists $lookup_hash{ $record->{ "CHR" } } ) + if ( $record->{ "REC_TYPE" } eq "BED" and exists $index->{ $record->{ "CHR" } } ) { - ( $index_beg, $index_len ) = @{ $lookup_hash{ $record->{ "CHR" } } }; + ( $index_beg, $index_len ) = @{ $index->{ $record->{ "CHR" } } }; $beg = $record->{ "CHR_BEG" } + $index_beg; $len = $record->{ "CHR_END" } - $record->{ "CHR_BEG" } + 1; } - elsif ( $record->{ "REC_TYPE" } eq "PSL" and exists $lookup_hash{ $record->{ "S_ID" } } ) + elsif ( $record->{ "REC_TYPE" } eq "PSL" and exists $index->{ $record->{ "S_ID" } } ) { - ( $index_beg, $index_len ) = @{ $lookup_hash{ $record->{ "S_ID" } } }; + ( $index_beg, $index_len ) = @{ $index->{ $record->{ "S_ID" } } }; $beg = $record->{ "S_BEG" } + $index_beg; $len = $record->{ "S_END" } - $record->{ "S_BEG" } + 1; } - elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and exists $lookup_hash{ $record->{ "S_ID" } } ) + elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and exists $index->{ $record->{ "S_ID" } } ) { - ( $index_beg, $index_len ) = @{ $lookup_hash{ $record->{ "S_ID" } } }; + ( $index_beg, $index_len ) = @{ $index->{ $record->{ "S_ID" } } }; $beg = $record->{ "S_BEG" } + $index_beg; $len = $record->{ "S_END" } - $record->{ "S_BEG" } + 1; } - elsif ( $record->{ "REC_TYPE" } eq "BLAST" and exists $lookup_hash{ $record->{ "S_ID" } } ) + elsif ( $record->{ "REC_TYPE" } eq "BLAST" and exists $index->{ $record->{ "S_ID" } } ) { - ( $index_beg, $index_len ) = @{ $lookup_hash{ $record->{ "S_ID" } } }; + ( $index_beg, $index_len ) = @{ $index->{ $record->{ "S_ID" } } }; $beg = $record->{ "S_BEG" } + $index_beg; $len = $record->{ "S_END" } - $record->{ "S_BEG" } + 1; diff --git a/code_perl/Maasha/SAM.pm b/code_perl/Maasha/SAM.pm index 79f697d..6a53274 100644 --- a/code_perl/Maasha/SAM.pm +++ b/code_perl/Maasha/SAM.pm @@ -116,6 +116,8 @@ sub sam2biopiece $record->{ 'S_BEG' } -= 1 if $record->{ 'S_BEG' } != 0; $record->{ 'S_BEG' } -= 1 if $record->{ 'S_BEG2' } != 0; + $record->{ 'S_END' } = $record->{ 'S_BEG' } + length( $record->{ 'SEQ' } ) - 1; + if ( $record->{ 'FLAG' } & 0x0010 ) { $record->{ 'STRAND' } = '+'; } else { -- 2.39.5