def _collapse_region_docs(cls, docs): ''' If the document is a hit then find parent region; pad all regions for build_info.''' hits = [doc for doc in docs if doc.type() == 'hits'] regions = [doc for doc in docs if doc.type() == 'region'] if len(hits) > 0: regions = Region.hits_to_regions(hits) return regions
def _collapse_region_docs(docs): ''' If the document is a hit then find parent region; pad all regions for build_info.''' hits = [doc for doc in docs if doc.type() == 'hits'] regions = [doc for doc in docs if doc.type() == 'region'] if len(hits) > 0: regions = Region.hits_to_regions(hits) for doc in hits: docs.remove(doc) regions = [Region.pad_region_doc(doc) for doc in regions] for doc in regions: if doc in docs: docs.remove(doc) docs.append(doc) return len(docs)
def get_overlapping_features(self, build, seqid, start, end): features = [] study_hits = self.get_overlapping_hits(build, seqid, start, end) if len(study_hits) == 0: return features regions = Region.hits_to_regions(study_hits) for doc in regions: doc = Region.pad_region_doc(doc) loc = doc.get_position(build=build).split(':') pos = loc[1].replace(',', '').split('-') feature = { 'name': doc.get_name(), 'id': doc.doc_id(), 'chr': loc[0], 'start': int(pos[0]), 'end': int(pos[1]) if len(pos) > 1 else int(pos[0]), 'strand': doc.get_strand_as_int(), 'attributes': {} } loci = doc.get_disease_loci() sub_features = [] for locus in loci: attributes = {} loc = locus.get_position(build=build).split(':') pos = loc[1].replace(',', '').split('-') sub_feature = { 'name': locus.get_name(), 'id': locus.doc_id(), 'chr': loc[0], 'start': int(pos[0]), 'end': int(pos[1]) if len(pos) > 1 else int(pos[0]), 'strand': locus.get_strand_as_int() } if hasattr(locus, "disease") and getattr(locus, "disease") is not None: attributes['disease'] = getattr(locus, "disease") sub_feature['attributes'] = attributes sub_features.append(sub_feature) feature['sub_features'] = sub_features features.append(ElasticObject(feature)) return features
def _collapse_region_docs(docs): ''' If the document is a hit then find parent region; pad all regions for build_info.''' hits = [doc for doc in docs if doc.type() == 'hits'] regions = [doc for doc in docs if doc.type() == 'region'] if len(hits) > 0: regions = Region.hits_to_regions(hits) for doc in hits: disease_locus = getattr(doc, "disease_locus") for region in regions: disease_loci = getattr(region, "disease_loci") if disease_locus in disease_loci: region.__dict__['_meta']['highlight'] = doc.highlight() docs.remove(doc) regions = [Region.pad_region_doc(doc) for doc in regions] for doc in regions: if doc in docs: docs.remove(doc) docs.append(doc) return len(docs)