]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/UCSC.pm
minor fixes
[biopieces.git] / code_perl / Maasha / UCSC.pm
index 73558a9fe4cfa004070b95417daf796814cb957a..84663db27285ed6585c146891f3f4f75055d2ddb 100644 (file)
@@ -998,13 +998,13 @@ sub ucsc_update_config
 
     # Returns nothing.
 
-    my ( $file, %entry, $fh_out );
+    my ( $file, $entry, %new_entry, $fh_in, $fh_out, $was_found );
 
     $file = $ENV{ "HOME" } . "/ucsc/my_tracks.ra";
 
     Maasha::Filesys::file_copy( $file, "$file~" );   # create a backup
 
-    %entry = (
+    %new_entry = (
         database   => $options->{ 'database' },
         track      => $options->{ 'table' },
         shortLabel => $options->{ 'short_label' },
@@ -1017,13 +1017,29 @@ sub ucsc_update_config
         type       => $type,
     );
 
-    $entry{ 'mafTrack' }        = "multiz17way" if $type eq "type bed 6 +";
-    $entry{ 'maxHeightPixels' } = "50:50:11"    if $type eq "wig 0";
+    $new_entry{ 'mafTrack' }        = "multiz17way" if $type eq "type bed 6 +";
+    $new_entry{ 'maxHeightPixels' } = "50:50:11"    if $type eq "wig 0";
+
+    $fh_in  = Maasha::Filesys::file_read_open( "$file~" );
+    $fh_out = Maasha::Filesys::file_write_open( $file );
+
+    while ( $entry = ucsc_config_entry_get( $fh_in ) )
+    {
+        if ( $entry->{ 'database' } eq $new_entry{ 'database' } and $entry->{ 'track' } eq $new_entry{ 'track' } )
+        {
+            ucsc_config_entry_put( \%new_entry, $fh_out );
 
-    $fh_out = Maasha::Filesys::file_append_open( $file );
+            $was_found = 1;
+        }
+        else
+        {
+            ucsc_config_entry_put( $entry, $fh_out );
+        }
+    }
 
-    ucsc_config_entry_put( \%entry, $fh_out );
+    ucsc_config_entry_put( \%new_entry, $fh_out ) if not $was_found;
     
+    close $fh_in;
     close $fh_out;
 
     Maasha::Common::run( "ucscMakeTracks.pl", "-b > /dev/null 2>&1" );