本文整理匯總了Python中xbrowse.Variant類的典型用法代碼示例。如果您正苦於以下問題:Python Variant類的具體用法?Python Variant怎麽用?Python Variant使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Variant類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_variants_from_note_tuples
def get_variants_from_note_tuples(project, note_tuples):
variants = []
for note_t in note_tuples:
variant = get_datastore(project.project_id).get_single_variant(
project.project_id, note_t[3], note_t[0], note_t[1], note_t[2]
)
if not variant:
variant = Variant(note_t[0], note_t[1], note_t[2])
get_annotator().annotate_variant(variant, project.get_reference_population_slugs())
# variant.annotation = get_annotator().get_variant(note_t[0], note_t[1], note_t[2])
variant.set_extra("family_id", note_t[3])
variant.set_extra("project_id", project.project_id)
variants.append(variant)
return variants
示例2: mendelian_variant_search_spec
def mendelian_variant_search_spec(request):
project, family = get_project_and_family_for_user(request.user, request.GET)
# TODO: use form
search_hash = request.GET.get('search_hash')
search_spec_dict, variants = cache_utils.get_cached_results(project.project_id, search_hash)
search_spec = MendelianVariantSearchSpec.fromJSON(search_spec_dict)
if variants is None:
variants = api_utils.calculate_mendelian_variant_search(search_spec, family.xfamily())
else:
variants = [Variant.fromJSON(v) for v in variants]
add_extra_info_to_variants_family(get_reference(), family, variants)
return_type = request.GET.get('return_type')
if return_type == 'json' or not return_type:
return JSONResponse({
'is_error': False,
'variants': [v.toJSON() for v in variants],
'search_spec': search_spec_dict,
})
elif request.GET.get('return_type') == 'csv':
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="results_{}.csv"'.format(search_hash)
writer = csv.writer(response)
indiv_ids = family.indiv_ids_with_variant_data()
headers = xbrowse_displays.get_variant_display_headers(get_mall(project.project_id), project, indiv_ids)
writer.writerow(headers)
for variant in variants:
fields = xbrowse_displays.get_display_fields_for_variant(get_mall(project.project_id), project, variant, indiv_ids)
writer.writerow(fields)
return response
示例3: get_single_variant
def get_single_variant(self, project_id, family_id, xpos, ref, alt):
collection = self._get_family_collection(project_id, family_id)
variant = collection.find_one({'xpos': xpos, 'ref': ref, 'alt': alt})
if variant:
return Variant.fromJSON(variant)
else:
return None
示例4: get_variants
def get_variants(self, project_id, family_id, genotype_filter=None, variant_filter=None):
db_query = _make_db_query(genotype_filter, variant_filter)
collection = self._get_family_collection(project_id, family_id)
for variant_dict in collection.find(db_query).sort('xpos'):
variant = Variant.fromJSON(variant_dict)
if passes_variant_filter(variant, variant_filter)[0]:
yield variant
示例5: get_variants_in_range
def get_variants_in_range(self, project_id, family_id, xpos_start, xpos_end):
collection = self._get_family_collection(project_id, family_id)
if not collection:
raise ValueError("Family not found: " + str(family_id))
for variant_dict in collection.find({'$and': [{'xpos': {'$gte': xpos_start}}, {'xpos': {'$lte': xpos_end}}]}):
variant = Variant.fromJSON(variant_dict)
self.add_annotations_to_variant(variant, project_id)
yield variant
示例6: get_variants_from_variant_tuples
def get_variants_from_variant_tuples(project, variant_tuples, user=None):
datastore = get_datastore(project)
population_slugs = project.get_reference_population_slugs()
variant_tuples_by_family_id = {}
for xpos, ref, alt, family_id in variant_tuples:
if family_id not in variant_tuples_by_family_id:
variant_tuples_by_family_id[family_id] = []
variant_tuples_by_family_id[family_id].append((xpos, ref, alt))
variants = []
for family_id, variant_tuples in variant_tuples_by_family_id.items():
variants_for_family = datastore.get_multiple_variants(
project.project_id,
family_id,
variant_tuples,
user=user
)
for (xpos, ref, alt), variant in zip(variant_tuples, variants_for_family):
if not variant:
variant = Variant(xpos, ref, alt)
get_annotator().annotate_variant(variant, population_slugs)
variant.set_extra('created_variant', True)
variant.set_extra('family_id', family_id)
variant.set_extra('project_id', project.project_id)
variants.append(variant)
return variants
示例7: get_variants_cohort
def get_variants_cohort(self, project_id, cohort_id, variant_filter=None):
db_query = self._make_db_query(None, variant_filter)
collection = self._get_family_collection(project_id, cohort_id)
for i, variant in enumerate(collection.find(db_query).sort('xpos').limit(settings.VARIANT_QUERY_RESULTS_LIMIT+5)):
if i > settings.VARIANT_QUERY_RESULTS_LIMIT:
raise Exception("ERROR: this search exceeded the %s variant result size limit. Please set additional filters and try again." % settings.VARIANT_QUERY_RESULTS_LIMIT)
yield Variant.fromJSON(variant)
示例8: get_variants_from_variant_tuples
def get_variants_from_variant_tuples(project, variant_tuples):
variants = []
for t in variant_tuples:
variant = get_datastore(project.project_id).get_single_variant(
project.project_id,
t[3],
t[0],
t[1],
t[2]
)
if not variant:
variant = Variant(t[0], t[1], t[2])
get_annotator().annotate_variant(variant, project.get_reference_population_slugs())
variant.set_extra('family_id', t[3])
variant.set_extra('project_id', project.project_id)
variants.append(variant)
return variants
示例9: get_single_variant
def get_single_variant(self, project_id, family_id, xpos, ref, alt, user=None):
collection = self._get_family_collection(project_id, family_id)
if not collection:
return None
variant_dict = collection.find_one({'xpos': xpos, 'ref': ref, 'alt': alt})
if variant_dict:
variant = Variant.fromJSON(variant_dict)
self.add_annotations_to_variants([variant], project_id, family_id=family_id)
return variant
else:
return None
示例10: get_variants_in_range
def get_variants_in_range(self, project_id, family_id, xpos_start, xpos_end):
collection = self._get_family_collection(project_id, family_id)
if not collection:
raise ValueError("Family not found: " + str(family_id))
for i, variant_dict in enumerate(collection.find({'$and': [{'xpos': {'$gte': xpos_start}}, {'xpos': {'$lte': xpos_end}}]}).limit(MONGO_QUERY_RESULTS_LIMIT+5)):
if i > MONGO_QUERY_RESULTS_LIMIT:
raise Exception("ERROR: this search exceeded the %s variant result size limit. Please set additional filters and try again." % MONGO_QUERY_RESULTS_LIMIT)
variant = Variant.fromJSON(variant_dict)
self.add_annotations_to_variant(variant, project_id)
yield variant
示例11: get_variants
def get_variants(self, project_id, family_id, genotype_filter=None, variant_filter=None):
db_query = self._make_db_query(genotype_filter, variant_filter)
collection = self._get_family_collection(project_id, family_id)
if not collection:
print("Error: mongodb collection not found for project %s family %s " % (project_id, family_id))
return
for variant_dict in collection.find(db_query).sort('xpos'):
variant = Variant.fromJSON(variant_dict)
self.add_annotations_to_variant(variant, project_id)
if passes_variant_filter(variant, variant_filter)[0]:
yield variant
示例12: get_variants
def get_variants(self, project_id, variant_filter=None):
variant_filter_t = VariantFilter(**(variant_filter if variant_filter else {}))
db_query = self._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
示例13: get_variants
def get_variants(self, project_id, family_id, genotype_filter=None, variant_filter=None):
db_query = self._make_db_query(genotype_filter, variant_filter)
collection = self._get_family_collection(project_id, family_id)
if not collection:
print("Error: mongodb collection not found for project %s family %s " % (project_id, family_id))
return
for i, variant_dict in enumerate(collection.find(db_query).sort('xpos').limit(MONGO_QUERY_RESULTS_LIMIT+5)):
if i >= MONGO_QUERY_RESULTS_LIMIT:
raise Exception("ERROR: this search exceeded the %s variant result size limit. Please set additional filters and try again." % MONGO_QUERY_RESULTS_LIMIT)
variant = Variant.fromJSON(variant_dict)
self.add_annotations_to_variant(variant, project_id)
if passes_variant_filter(variant, variant_filter)[0]:
yield variant
示例14: get_variants
def get_variants(self, project_id, family_id, genotype_filter=None, variant_filter=None, quality_filter=None, indivs_to_consider=None, user=None):
db_query = self._make_db_query(genotype_filter, variant_filter)
collection = self._get_family_collection(project_id, family_id)
if not collection:
logger.error("Error: mongodb collection not found for project %s family %s " % (project_id, family_id))
return
for i, variant_dict in enumerate(collection.find({'$and' : [{k: v} for k, v in db_query.items()]}).sort('xpos').limit(settings.VARIANT_QUERY_RESULTS_LIMIT+5)):
if i >= settings.VARIANT_QUERY_RESULTS_LIMIT:
raise Exception("ERROR: this search exceeded the %s variant result size limit. Please set additional filters and try again." % settings.VARIANT_QUERY_RESULTS_LIMIT)
variant = Variant.fromJSON(variant_dict)
variant.set_extra('project_id', project_id)
variant.set_extra('family_id', family_id)
self.add_annotations_to_variants([variant], project_id)
if passes_variant_filter(variant, variant_filter)[0]:
yield variant
示例15: get_variants_in_gene
def get_variants_in_gene(self, project_id, gene_id, variant_filter=None):
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 = self._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