def get_merged_exons(self): """Returns a list of non-redundant exon coordinates for this gene. Overlapping exons are merged.""" # get redundant, sorted list of all exons exon_list = [] for tr in self.transcripts: exon_list.extend(tr.exons) coord.sort_coords(exon_list, use_strand=False) # create coordinate group from first exon cur_exon = coord.CoordGroup(exon_list[0]) merged_exons = [cur_exon] # merge overlapping exons for ex in exon_list[1:]: if ex.overlaps(cur_exon): # expand current exon cur_exon.add_coord(ex) else: # new exon group cur_exon = coord.CoordGroup(ex) merged_exons.append(cur_exon) return merged_exons
def group_transcripts(trs): """Creates a list of genes created from overlapping sets of transcripts. The provided list of transcripts is sorted in-place by this function.""" if len(trs) == 0: return [] # sort transcripts, and then find overlapping transcripts on same strand coord.sort_coords(trs, use_strand=True) # start first gene with first transcript cur_gene = Gene([trs[0]]) genes = [cur_gene] for tr in trs[1:]: if tr.overlaps(cur_gene, use_strand=True): # keep adding overlapping transcripts to current gene cur_gene.add_transcript(tr) else: # start a new gene cur_gene = Gene([tr]) genes.append(cur_gene) return genes