X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fget_genome_seq;h=e219c5188a993fd54e0af1b2c363abbb45ba9720;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=cde18f90d07b9f6f51fb592443867554646b0f57;hpb=9854397f83abe8d5a8c614b799ef3107d3f85f80;p=biopieces.git diff --git a/bp_bin/get_genome_seq b/bp_bin/get_genome_seq index cde18f9..e219c51 100755 --- a/bp_bin/get_genome_seq +++ b/bp_bin/get_genome_seq @@ -1,4 +1,4 @@ -#!/usr/bin/env perl -w +#!/usr/bin/env perl # Copyright (C) 2007-2009 Martin A. Hansen. @@ -26,28 +26,31 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; +use Data::Dumper; use Maasha::Biopieces; use Maasha::Filesys; +use Maasha::Fasta; use Maasha::Seq; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $genome_file, $index_file, $fh, $genome, - $beg, $end, $len, $index_beg, $index_len, @begs, @lens, $index, $seq, $i, %lookup_hash ); +my ( $options, $in, $out, $record, $genome_file, $index_file, $fh, $genome, + $beg, $end, $len, $index_beg, $index_len, @begs, @lens, $index, $seq, $i ); $options = Maasha::Biopieces::parse_options( [ - { long => 'genome', short => 'g', type => 'genome', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'chr', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'beg', short => 'b', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, - { long => 'end', short => 'e', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, - { long => 'len', short => 'l', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, - { long => 'flank', short => 'f', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef }, - { long => 'mask', short => 'm', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'splice', short => 's', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'genome', short => 'g', type => 'genome', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'chr', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'beg', short => 'b', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, + { long => 'end', short => 'e', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, + { long => 'len', short => 'l', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 }, + { long => 'flank', short => 'f', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef }, + { long => 'mask', short => 'm', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'splice', short => 's', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] ); @@ -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 ( 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; @@ -104,28 +105,34 @@ if ( $options->{ "genome" } ) } } - 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 "BLAST" 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 $index->{ $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; @@ -191,26 +198,22 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) Maasha::Biopieces::put_record( $record, $out ); } +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BEGIN { - $run_time_beg = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::log_biopiece(); + Maasha::Biopieces::status_set(); } END { - Maasha::Biopieces::close_stream( $in ); - Maasha::Biopieces::close_stream( $out ); - - $run_time_end = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); + Maasha::Biopieces::status_log(); } @@ -218,4 +221,3 @@ END __END__ -