Beispiel #1
0
 def get_common_location(location_array):
     """Merges a compound location array into an overall location"""
     contig = location_array[0][0]
     strand = location_array[0][2]
     min_pos = min([get_start(loc) for loc in location_array])
     max_pos = max([get_end(loc) for loc in location_array])
     common_length = max_pos - min_pos + 1
     common_start = min_pos if strand == '+' else max_pos
     return [contig, common_start, strand, common_length]
Beispiel #2
0
 def feature_sort(feat):
     order = ('gene', 'mRNA', 'CDS')
     if feat.get('children'):
         priority = 0
     elif feat['type'] not in order:
         priority = len(order)
     else:
         priority = order.index(feat['type'])
     return get_start(self.get_common_location(
         feat['location'])), priority
Beispiel #3
0
 def make_feature(self, location, in_feature, is_gtf):
     """Make a single feature line for the file"""
     try:
         out_feature = {
             'seqname': location[0],
             'source': 'KBase',
             'type': in_feature.get('type', 'exon'),
             'start': str(get_start(location)),
             'end': str(get_end(location)),
             'score': '.',
             'strand': location[2],
             'frame': '0',
         }
         if is_gtf:
             out_feature['attribute'] = self.gen_gtf_attr(in_feature)
         else:
             out_feature['attribute'] = self.gen_gff_attr(in_feature)
     except Exception as e:
         traceback.print_exc()
         raise Exception(f'Unable to parse {in_feature}:{e}')
     return out_feature