def get_variants(self, project_id, variant_filter=None): variant_filter_t = VariantFilter(**(variant_filter if variant_filter else {})) db_query = _make_db_query(None, variant_filter) collection = self._get_project_collection(project_id) for variant_dict in collection.find(db_query).sort('xpos'): variant = Variant.fromJSON(variant_dict) if variant_filter is None: yield variant if passes_variant_filter(variant, variant_filter_t)[0]: yield variant
def get_variants_in_gene(self, project_id, gene_id, variant_filter=None): if variant_filter is None: modified_variant_filter = {} else: modified_variant_filter = copy.deepcopy(variant_filter) if variant_filter is None: modified_variant_filter = VariantFilter() else: modified_variant_filter = copy.deepcopy(variant_filter) modified_variant_filter.add_gene(gene_id) db_query = _make_db_query(None, modified_variant_filter) collection = self._get_project_collection(project_id) variants = [] for variant_dict in collection.find(db_query).hint([('gene_ids', pymongo.ASCENDING), ('xpos', pymongo.ASCENDING)]): variant = Variant.fromJSON(variant_dict) if passes_variant_filter(variant, modified_variant_filter): variants.append(variant) variants = sorted(variants, key=lambda v: v.unique_tuple()) return variants