From cf26ecba326857ad28eeeee926e19d5e978d82b7 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 29 Jul 2008 02:21:10 +0000 Subject: [PATCH] finished biopiece merge_records git-svn-id: http://biopieces.googlecode.com/svn/trunk@198 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/Biopieces.pm | 70 ++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 0a6c847..9e2d81a 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -754,6 +754,7 @@ sub get_options { @options = qw( keys|k=s + merge|m=s ); } elsif ( $script eq "grab" ) @@ -1016,6 +1017,10 @@ sub get_options { Maasha::Common::error( qq(Character '$options{ $opt }' is not allowed in table names) ); } + elsif ( $opt eq "merge" and $options{ $opt } !~ /^(AandB|AorB|BorA|AnotB|BnotA)$/ ) + { + Maasha::Common::error( qq(Argument to --$opt must be AandB, AorB, BorA, AnotB, or BnotA - not "$options{ $opt }") ); + } } Maasha::Common::error( qq(no --database specified) ) if $script eq "create_blast_db" and not $options{ "database" }; @@ -4615,9 +4620,11 @@ sub script_merge_records # Returns nothing. - my ( $record, $file1, $file2, $fh1, $fh2, $key1, $key2, @keys1, @keys2, @vals1, @vals2, + my ( $merge, $record, $file1, $file2, $fh1, $fh2, $key1, $key2, @keys1, @keys2, @vals1, @vals2, $num1, $num2, $num, $cmp, $i ); + $merge = $options->{ "merge" } || "AandB"; + $file1 = "$BP_TMP/merge_records1.tmp"; $file2 = "$BP_TMP/merge_records2.tmp"; @@ -4683,6 +4690,8 @@ sub script_merge_records while ( $num1 > 0 and $num2 > 0 ) { + undef $record; + if ( $num ) { $cmp = $vals1[ 0 ] <=> $vals2[ 0 ]; } else { @@ -4691,27 +4700,46 @@ sub script_merge_records if ( $cmp < 0 ) { + if ( $merge =~ /^(AorB|AnotB)$/ ) + { + for ( $i = 0; $i < @keys1; $i++ ) { + $record->{ $keys1[ $i ] } = $vals1[ $i ]; + } + + put_record( $record, $out ); + } + @vals1 = Maasha::Common::get_fields( $fh1 ); $num1--; } elsif ( $cmp > 0 ) { + if ( $merge =~ /^(BorA|BnotA)$/ ) + { + for ( $i = 0; $i < @keys2; $i++ ) { + $record->{ $keys2[ $i ] } = $vals2[ $i ]; + } + + put_record( $record, $out ); + } + @vals2 = Maasha::Common::get_fields( $fh2 ); $num2--; } else { - undef $record; - - for ( $i = 0; $i < @keys1; $i++ ) { - $record->{ $keys1[ $i ] } = $vals1[ $i ]; - } + if ( $merge =~ /^(AandB|AorB|BorA)$/ ) + { + for ( $i = 0; $i < @keys1; $i++ ) { + $record->{ $keys1[ $i ] } = $vals1[ $i ]; + } - for ( $i = 1; $i < @keys2; $i++ ) { - $record->{ $keys2[ $i ] } = $vals2[ $i ]; + for ( $i = 1; $i < @keys2; $i++ ) { + $record->{ $keys2[ $i ] } = $vals2[ $i ]; + } + + put_record( $record, $out ); } - - put_record( $record, $out ); @vals1 = Maasha::Common::get_fields( $fh1 ); @vals2 = Maasha::Common::get_fields( $fh2 ); @@ -4725,6 +4753,28 @@ sub script_merge_records unlink $file1; unlink $file2; + + if ( $num1 > 0 and $merge =~ /^(AorB|AnotB)$/ ) + { + undef $record; + + for ( $i = 0; $i < @keys1; $i++ ) { + $record->{ $keys1[ $i ] } = $vals1[ $i ]; + } + + put_record( $record, $out ); + } + + if ( $num2 > 0 and $merge =~ /^(BorA|BnotA)$/ ) + { + undef $record; + + for ( $i = 0; $i < @keys2; $i++ ) { + $record->{ $keys2[ $i ] } = $vals2[ $i ]; + } + + put_record( $record, $out ); + } } -- 2.39.5