ac0b61420ab00d96616349e7ea289406b9054932
hiram
  Thu Feb 20 13:01:15 2025 -0800
tolerant of missing CpG bbi files refs #29545

diff --git src/hg/utils/automation/asmHubCpG.pl src/hg/utils/automation/asmHubCpG.pl
index d3b943ebbfb..51e2bd7b22b 100755
--- src/hg/utils/automation/asmHubCpG.pl
+++ src/hg/utils/automation/asmHubCpG.pl
@@ -11,35 +11,30 @@
 
 if ($argc != 3) {
   printf STDERR "usage: asmHubCpG.pl asmId asmId.names.tab bbi/asmId\n";
   printf STDERR "where asmId is the assembly identifier,\n";
   printf STDERR "and   asmId.names.tab is naming file for this assembly,\n";
   printf STDERR "and bbi/asmId is the prefix to .cpgIslandExtUnmasked.bb and cpgIslandExt.bb.\n";
   exit 255;
 }
 
 my $asmId = shift;
 my $namesFile = shift;
 my $bbiPrefix = shift;
 my $unmaskedBbi = "$bbiPrefix.cpgIslandExtUnmasked.bb";
 my $maskedBbi = "$bbiPrefix.cpgIslandExt.bb";
 
-if ( ! -s $maskedBbi ) {
-  printf STDERR "ERROR: can not find CpG masked file:\n\t'%s'\n", $maskedBbi;
-  exit 255;
-}
-
 my $em = "<em>";
 my $noEm = "</em>";
 my $assemblyDate = `grep -v "^#" $namesFile | cut -f9`;
 chomp $assemblyDate;
 my $ncbiAssemblyId = `grep -v "^#" $namesFile | cut -f10`;
 chomp $ncbiAssemblyId;
 my $organism = `grep -v "^#" $namesFile | cut -f5`;
 chomp $organism;
 
 print <<_EOF_
 <h2>Description</h2>
 <p>
 This track shows the CpG annotations on the $assemblyDate $em${organism}$noEm/$asmId genome assembly.
 </p>
 
@@ -89,38 +84,42 @@
 <p>The CpG count is the number of CG dinucleotides in the island.  
 The Percentage CpG is the ratio of CpG nucleotide bases
 (twice the CpG count) to the length.  The ratio of observed to expected 
 CpG is calculated according to the formula (cited in 
 Gardiner-Garden <em>et al</em>. (1987)):
 
 <pre>    Obs/Exp CpG = Number of CpG * N / (Number of C * Number of G)</pre>
 
 where N = length of sequence.</p>
 <h2>CpG item counts</h2>
 <p>
 <ul>
 _EOF_
    ;
 
+
+if ( -s $maskedBbi ) {
   my $maskedCount = `bigBedInfo $maskedBbi | egrep "itemCount:|basesCovered:" | xargs echo | sed -e 's/itemCount/item count/; s/basesCovered/bases covered/;'`;
   chomp $maskedCount;
   printf "<li>masked sequence: %s</li>\n", $maskedCount;
+}
 
+if ( -s $unmaskedBbi ) {
   my $unmaskedCount = `bigBedInfo $unmaskedBbi | egrep "itemCount:|basesCovered:" | xargs echo | sed -e 's/itemCount/item count/; s/basesCovered/bases covered/;'`;
   chomp $unmaskedCount;
-
   printf "<li>unmasked sequence: %s</li>\n", $unmaskedCount;
+}
 
 print <<_EOF_
 </ul>
 </p>
 <h2>Credits</h2>
 
 <p>This track was generated using a modification of a program developed by G. Miklem and L. Hillier 
 (unpublished).</p>
 
 <h2>References</h2>
 
 <p>
 Gardiner-Garden M, Frommer M.
 <a href="http://www.sciencedirect.com/science/article/pii/0022283687906899" target="_blank">
 CpG islands in vertebrate genomes</a>.