src/hg/utils/automation/blastz-run-ucsc 1.10

1.10 2009/05/13 00:04:56 hiram
Tolerate empty results when running lineage specific repeats and tolerate previously existing results
Index: src/hg/utils/automation/blastz-run-ucsc
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/automation/blastz-run-ucsc,v
retrieving revision 1.9
retrieving revision 1.10
diff -b -B -U 4 -r1.9 -r1.10
--- src/hg/utils/automation/blastz-run-ucsc	19 Dec 2008 21:25:40 -0000	1.9
+++ src/hg/utils/automation/blastz-run-ucsc	13 May 2009 00:04:56 -0000	1.10
@@ -360,8 +360,9 @@
 sub plainBlastz {
   # just run blastz -- target and query can have "[$start,$end]" specifiers
   # where $start is 1-based.  Put output in file name $raw.
   my ($target, $query, $options, $raw) = @_;
+  my $answer = 1;  # default answer is that blastz was run OK
   my $blastz = $defVars{'BLASTZ'} || "lastz";
   #  these variables will be 1 if there is zero usable sequence
   #  this could be a more extensive check than just for zero.
   my $targetNoSequence = 0;
@@ -381,11 +382,13 @@
   }
   chomp $queryNoSequence;
   if ($targetNoSequence || $queryNoSequence) {
     &emptyLav($raw);
+    $answer = 0;  # not really running blastz
   } else {
     &run("$blastz $target $query $options > $raw");
   }
+  return($answer);
 }
 
 sub selectRpts {
   # This used to be an awk, piped to select_rpts, piped to sort -n.  
@@ -461,21 +464,28 @@
   &run("strip_rpts $TS1 $TS1X > $TS1S");
   &run("strip_rpts $TS2 $TS2X > $TS2S");
 
   # Run blastz on query forward strand and restore repeats:
-  &plainBlastz($TS1S, $TS2S, "B=0" . $blastzOptions, $TZF);
+  my $blastzOK = &plainBlastz($TS1S, $TS2S, "B=0" . $blastzOptions, $TZF);
+  if ($blastzOK ) {
   &run("restore_rpts $TZF " .
             "$TS1 \"\\\"$tFname\\\" $tStart $tEnd\" " .
             "$TS2 \"\\\"$qFname\\\" $qStart $qEnd\" " .
             "$TS1X $TS2X > $raw");
-
+  } else {
+    &run("/bin/cp -p $TZF $raw");
+  }
   # Run blastz on query reverse strand and restore repeats:
   &run("revcomp $TS2S > $TS2SR");
-  &plainBlastz($TS1S, $TS2SR, "B=0" . $blastzOptions, $TZR);
+  $blastzOK = &plainBlastz($TS1S, $TS2SR, "B=0" . $blastzOptions, $TZR);
+  if ($blastzOK ) {
   &run("restore_rpts $TZR " .
             "$TS1 \"\\\"$tFname\\\" $tStart $tEnd\" " .
             "$TS2 \"\\\"$qFname-\\\" $qStart $qEnd\" " .
             "$TS1X $TS2X reverse >> $raw");
+  } else {
+    &run("/bin/cat $TZF >> $raw");
+  }
 }
 
 sub liftLav {
   # Run blastz-normalizeLav to lift up chunk coords to sequence level.
@@ -514,9 +524,12 @@
 
 &usage(1) if (scalar(@ARGV) != 4);
 my ($target, $query, $DEF, $out) = @ARGV;
 
-&cleanDie("$out already exists\n") if (-f "$out");
+# It is OK to have a previous result existing
+if ( -f "$out") {
+   exit 0;
+}
 
 &loadDef($DEF);
 my $seq1Dir = $defVars{'SEQ1_CTGDIR'} || $defVars{'SEQ1_DIR'};
 my $seq2Dir = $defVars{'SEQ2_CTGDIR'} || $defVars{'SEQ2_DIR'};