X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fget_genome_seq;h=e219c5188a993fd54e0af1b2c363abbb45ba9720;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=5292b72f58efe1f98933e11b19a44d5c7e3a4193;hpb=5aed4676ad1bf35abbade6215ac90ee591e6d8fe;p=biopieces.git diff --git a/bp_bin/get_genome_seq b/bp_bin/get_genome_seq index 5292b72..e219c51 100755 --- a/bp_bin/get_genome_seq +++ b/bp_bin/get_genome_seq @@ -26,9 +26,12 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; +use Data::Dumper; use Maasha::Biopieces; use Maasha::Filesys; +use Maasha::Fasta; use Maasha::Seq; @@ -36,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( [ @@ -64,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; @@ -89,7 +88,9 @@ if ( $options->{ "genome" } ) $beg = $index_beg; } - $len = $index_beg + $index_len - $beg if $beg + $len > $index_beg + $index_len; + if ( $beg + $len > $index_beg + $index_len ) { + $len = $index_beg + $index_len - $beg; + } next if $beg > $index_beg + $index_len; @@ -108,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;