]> git.donarmstrong.com Git - biopieces.git/commitdiff
finished biopiece merge_records
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 29 Jul 2008 02:21:10 +0000 (02:21 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 29 Jul 2008 02:21:10 +0000 (02:21 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@198 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Biopieces.pm

index 0a6c8478316337c23c6e29df28a50afac74fea28..9e2d81a2eff6665952b2529d3e5951f433de28d1 100644 (file)
@@ -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 );
+    }
 }