Example #1
0
 def LoadExonBoundaryCoordinatesFromFile(self, path): #{
   DebugMsg(self, "Gene annotation file: %s" % path)
   # open the annotations file
   annotations_file = GeneAnnotationParserCls(path, log_info=self.log_info)
   skipped_chroms = set()
   # get the coordinates from the file
   for transcript in annotations_file: #{
     # fix chromosome names, if needed
     chrom = NormalizeChrID(transcript.chrom)
     if (NonStandardChr(chrom)): #{
       ExtremeDebugMsg(self, "Skipping transcript in strange chromosome: "
         "%s (%s)" % (chrom, transcript.chrom))
       skipped_chroms.add(chrom)
       continue
     #} end if
     prev_exon = None
     for (index, exon) in enumerate(transcript.SortedExons()): #{
       (exon.left, exon.right) = (exon.min, exon.max)
       # assume that exon list is sorted by left coordinate
       if (None != prev_exon and prev_exon.min > exon.min): #{
         raise ExonBoundCounterError("Transcript %s exons are not in "
           "order: %s, %s" % (transcript.transcript_id,
           prev_exon.ToString(), exon.ToString()))
       #} end if
       prev_exon = exon
       # do not include the left side of the first exon
       if (0 == index): #{
         exon.left = None
       #} end if
       # do not include the right side of the last exon
       if (len(transcript.exons) == (index+1)): #{
         exon.right = None
       #} end if
       # exon_bound_coords[chrom][prime_side][coord1][coord2] = gene_list
       for side in SIDES: #{
         if (None != getattr(exon, side)): #{
           keys = [chrom, side, getattr(exon, side),
             getattr(exon, OtherSide(side))]
           AddToMultiDict(self.exon_bound_coords, keys,
             transcript.transcript_id)
         #} end if
       #} end for
     #} end for
   #} end for
   if (0 < len(skipped_chroms)): #{
     DebugMsg(self, "Skipped transcripts in chromosomes: %s" %
       ", ".join(sorted(skipped_chroms)))
   #} end if
   # close the file
   annotations_file.close()