def get_es_variants_for_variant_ids(families, variant_ids, dataset_type=None, user=None): variants = EsSearch(families, user=user).filter_by_location(variant_ids=variant_ids) if dataset_type: variants = variants.update_dataset_type(dataset_type) return variants.search(num_results=len(variant_ids))
def get_single_es_variant(families, variant_id, return_all_queried_families=False): variants = EsSearch( families, return_all_queried_families=return_all_queried_families, ).filter_by_location(variant_ids=[variant_id]).search(num_results=1) if not variants: raise Exception('Variant {} not found'.format(variant_id)) return variants[0]
def get_es_variants_for_variant_tuples(families, xpos_ref_alt_tuples): variant_ids = [] for xpos, ref, alt in xpos_ref_alt_tuples: chrom, pos = get_chrom_pos(xpos) if chrom == 'M': chrom = 'MT' variant_ids.append('{}-{}-{}-{}'.format(chrom, pos, ref, alt)) variants = EsSearch(families).filter_by_location( variant_ids=variant_ids).search(num_results=len(xpos_ref_alt_tuples)) return variants
def _parse_variant_items(search_json): raw_items = search_json.get('rawVariantItems') if not raw_items: return None, None, None invalid_items = [] variant_ids = [] rs_ids = [] for item in raw_items.replace(',', ' ').split(): if item.startswith('rs'): rs_ids.append(item) else: try: chrom, pos, _, _ = EsSearch.parse_variant_id(item) get_xpos(chrom, pos) variant_ids.append(item.lstrip('chr')) except (KeyError, ValueError): invalid_items.append(item) return rs_ids, variant_ids, invalid_items