本文整理汇总了Python中elastic.query.Query.ids方法的典型用法代码示例。如果您正苦于以下问题:Python Query.ids方法的具体用法?Python Query.ids怎么用?Python Query.ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elastic.query.Query
的用法示例。
在下文中一共展示了Query.ids方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_region_attributes
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def test_region_attributes(self):
''' test region attributes '''
idx = ElasticSettings.idx(RegionDataTest.IDX_KEY, 'REGION')
(idx, idx_type) = idx.split('/')
docs = ElasticUtils.get_rdm_docs(idx, idx_type, qbool=Query.match_all(), sources=[], size=1)
newRegion = utils.Region.pad_region_doc(docs[0])
if len(getattr(newRegion, "genes")) > 0:
query = ElasticQuery(Query.ids(getattr(newRegion, "genes")))
resultObject = Search(query, idx=ElasticSettings.idx('GENE', 'GENE'),
size=len(getattr(newRegion, "genes"))).search()
self.assertEqual(len(getattr(newRegion, "genes")), resultObject.hits_total,
"All genes on region found in GENE index")
if len(getattr(newRegion, "studies")) > 0:
query = ElasticQuery(Query.ids(getattr(newRegion, "studies")))
resultObject = Search(query, idx=ElasticSettings.idx('STUDY', 'STUDY'),
size=len(getattr(newRegion, "studies"))).search()
self.assertEqual(len(getattr(newRegion, "studies")), resultObject.hits_total,
"All study ids for region found in STUDY index")
if len(getattr(newRegion, "pmids")) > 0:
query = ElasticQuery(Query.ids(getattr(newRegion, "pmids")))
resultObject = Search(query, idx=ElasticSettings.idx('PUBLICATION', 'PUBLICATION'),
size=len(getattr(newRegion, "pmids"))).search()
self.assertEqual(len(getattr(newRegion, "pmids")), resultObject.hits_total,
"All PMIDs for region found in PUBLICATION index")
示例2: gene2ensembl_parse
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def gene2ensembl_parse(cls, gene2ens, idx, idx_type):
''' Parse gene2ensembl file from NCBI and add entrez to gene index. '''
genes = {}
for gene in gene2ens:
if gene.startswith('9606\t'):
parts = gene.split('\t')
gene_id = parts[1]
ens_id = parts[2]
# prot_acc = parts[5]
if ens_id not in genes:
genes[ens_id] = {'dbxrefs': {'entrez': gene_id}}
def process_hits(resp_json):
hits = resp_json['hits']['hits']
docs = [Document(hit) for hit in hits]
chunk_size = 450
for i in range(0, len(docs), chunk_size):
docs_chunk = docs[i:i+chunk_size]
json_data = ''
for doc in docs_chunk:
ens_id = doc._meta['_id']
idx_type = doc.type()
doc_data = {"update": {"_id": ens_id, "_type": idx_type,
"_index": idx, "_retry_on_conflict": 3}}
json_data += json.dumps(doc_data) + '\n'
json_data += json.dumps({'doc': genes[ens_id]}) + '\n'
if json_data != '':
Loader().bulk_load(idx, idx_type, json_data)
query = ElasticQuery(Query.ids(list(genes.keys())))
ScanAndScroll.scan_and_scroll(idx, idx_type=idx_type, call_fun=process_hits, query=query)
示例3: _get_pub_docs_by_pmid
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def _get_pub_docs_by_pmid(pmids, sources=None):
""" Get the gene symbols for the corresponding array of ensembl IDs.
A dictionary is returned with the key being the ensembl ID and the
value the gene document. """
query = ElasticQuery(Query.ids(pmids), sources=sources)
elastic = Search(query, idx=ElasticSettings.idx("PUBLICATION"), size=len(pmids))
return {doc.doc_id(): doc for doc in elastic.search().docs}
示例4: get_gene_docs_by_ensembl_id
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_gene_docs_by_ensembl_id(cls, ens_ids, sources=None):
''' Get the gene symbols for the corresponding array of ensembl IDs.
A dictionary is returned with the key being the ensembl ID and the
value the gene document. '''
query = ElasticQuery(Query.ids(ens_ids), sources=sources)
elastic = Search(query, idx=ElasticSettings.idx('GENE', idx_type='GENE'), size=len(ens_ids))
return {doc.doc_id(): doc for doc in elastic.search().docs}
示例5: gene2ensembl_parse
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def gene2ensembl_parse(cls, gene2ens, idx, idx_type):
''' Parse gene2ensembl file from NCBI and add entrez to gene index. '''
genes = {}
for gene in gene2ens:
if gene.startswith('9606\t'):
parts = gene.split('\t')
gene_id = parts[1]
ens_id = parts[2]
# prot_acc = parts[5]
if ens_id not in genes:
genes[ens_id] = {'dbxrefs': {'entrez': gene_id}}
query = ElasticQuery(Query.ids(list(genes.keys())))
docs = Search(query, idx=idx, idx_type=idx_type, size=80000).search().docs
chunk_size = 450
for i in range(0, len(docs), chunk_size):
docs_chunk = docs[i:i+chunk_size]
json_data = ''
for doc in docs_chunk:
ens_id = doc._meta['_id']
idx_type = doc.type()
doc_data = {"update": {"_id": ens_id, "_type": idx_type,
"_index": idx, "_retry_on_conflict": 3}}
json_data += json.dumps(doc_data) + '\n'
json_data += json.dumps({'doc': genes[ens_id]}) + '\n'
if json_data != '':
Loader().bulk_load(idx, idx_type, json_data)
示例6: get_publications
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_publications(cls, pmids, sources=[]):
''' Get publications from the list of PMIDs. '''
if pmids is None or not pmids:
return None
from elastic.search import Search, ElasticQuery
pubs = Search(ElasticQuery(Query.ids(pmids), sources=sources),
idx=ElasticSettings.idx('PUBLICATION', 'PUBLICATION'), size=2).search().docs
return pubs
示例7: ensmart_gene_parse
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def ensmart_gene_parse(cls, ensmart_f, idx, idx_type):
''' For those gene docs missing a dbxrefs.entrez use Ensembl Mart to
fill in. '''
genes = {}
for ensmart in ensmart_f:
parts = ensmart.split('\t')
ens_id = parts[0]
gene_id = parts[1]
swissprot = parts[2].strip()
trembl = parts[3].strip()
if gene_id == '':
continue
if ens_id in genes:
if genes[ens_id]['dbxrefs']['entrez'] != gene_id:
genes[ens_id]['dbxrefs']['entrez'] = None
else:
if swissprot != '':
cls._add_to_dbxref(genes[ens_id], 'swissprot', swissprot)
if trembl != '':
cls._add_to_dbxref(genes[ens_id], 'trembl', trembl)
else:
genes[ens_id] = {'dbxrefs': {'entrez': gene_id}}
if swissprot != '':
genes[ens_id]['dbxrefs'].update({'swissprot': swissprot})
if trembl != '':
genes[ens_id]['dbxrefs'].update({'trembl': trembl})
''' search for the entrez ids '''
def process_hits(resp_json):
hits = resp_json['hits']['hits']
docs = [Document(hit) for hit in hits]
chunk_size = 450
for i in range(0, len(docs), chunk_size):
docs_chunk = docs[i:i+chunk_size]
json_data = ''
for doc in docs_chunk:
ens_id = doc._meta['_id']
if 'dbxrefs' in doc.__dict__:
dbxrefs = getattr(doc, 'dbxrefs')
else:
dbxrefs = {}
if ('entrez' in genes[ens_id]['dbxrefs'] and
'entrez' in dbxrefs and
dbxrefs['entrez'] != genes[ens_id]['dbxrefs']['entrez']):
logger.warn('Multiple entrez ids for ensembl id: '+ens_id)
continue
idx_type = doc.type()
doc_data = {"update": {"_id": ens_id, "_type": idx_type,
"_index": idx, "_retry_on_conflict": 3}}
json_data += json.dumps(doc_data) + '\n'
json_data += json.dumps({'doc': genes[ens_id]}) + '\n'
if json_data != '':
Loader().bulk_load(idx, idx_type, json_data)
query = ElasticQuery(Query.ids(list(genes.keys())))
ScanAndScroll.scan_and_scroll(idx, idx_type=idx_type, call_fun=process_hits, query=query)
示例8: is_region_for_disease
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def is_region_for_disease(cls, hit, section=None, config=None, result_container={}):
result_container_populated = result_container
feature_doc = hit['_source']
feature_doc['_id'] = hit['_id']
disease_loci = feature_doc['disease_loci']
region_id = feature_doc['region_id']
diseases = set()
for disease_locus_id in disease_loci:
query = ElasticQuery(Query.ids([disease_locus_id]), sources=['hits'])
elastic = Search(query, idx=ElasticSettings.idx('REGION', idx_type='DISEASE_LOCUS'))
disease_locus_hits = elastic.search().docs
for disease_locus_hit in disease_locus_hits:
hits = getattr(disease_locus_hit, 'hits')
for hit in hits:
query = ElasticQuery(Query.ids([hit]))
elastic = Search(query, idx=ElasticSettings.idx('REGION', idx_type='STUDY_HITS'))
hit_doc = elastic.search().docs[0]
disease = getattr(hit_doc, "disease")
status = getattr(hit_doc, "status")
if status != 'N':
return result_container
disease_loci = getattr(hit_doc, "disease_locus").lower()
if disease_loci == 'tbc':
return result_container
diseases.add(disease)
for disease in diseases:
result_container_populated = cls.populate_container(disease,
disease,
fnotes=None, features=[region_id],
diseases=[disease],
result_container=result_container_populated)
return result_container_populated
示例9: get_disease_loci
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_disease_loci(self):
''' Returns the disease loci for requested hit docs '''
regions_idx = ElasticSettings.idx('REGION', 'DISEASE_LOCUS')
disease_loci = getattr(self, "disease_loci")
if len(disease_loci) == 0:
logger.warning("no disease_locus attributes found/given")
return
resultObj = Search(search_query=ElasticQuery(Query.ids(disease_loci)),
idx=regions_idx).search()
return resultObj.docs
示例10: test_chrom
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def test_chrom(self):
''' Check correct number of chromosomes. '''
ids = ['X', 'Y']
for i in range(22):
ids.append(i+1)
idx = ElasticSettings.idx('BAND', idx_type='CHROM')
docs = Search(ElasticQuery(Query.ids(ids)), idx=idx, size=len(ids)).search().docs
self.assertEqual(len(ids), len(docs), 'Check for chromosomes')
for doc in docs:
self.assertGreater(getattr(doc, 'length'), 1000000, 'Chromosome length')
示例11: get_studies
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_studies(cls, study_ids=None, disease_code=None, sources=[], split_name=True):
studies_query = ElasticQuery(Query.match_all(), sources=sources)
if disease_code is not None:
studies_query = ElasticQuery(BoolQuery(must_arr=Query.term("diseases", disease_code)), sources=sources)
elif study_ids:
studies_query = ElasticQuery(Query.ids(study_ids), sources=sources)
studies = Search(studies_query, idx=ElasticSettings.idx('STUDY', 'STUDY'), size=200).search().docs
for doc in studies:
if split_name and getattr(doc, 'study_name') is not None:
setattr(doc, 'study_name', getattr(doc, 'study_name').split(':', 1)[0])
return Document.sorted_alphanum(studies, "study_id")
示例12: get_gene_docs_by_ensembl_id
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_gene_docs_by_ensembl_id(ens_ids, sources=None):
''' Get the gene symbols for the corresponding array of ensembl IDs.
A dictionary is returned with the key being the ensembl ID and the
value the gene document. '''
genes = {}
def get_genes(resp_json):
hits = resp_json['hits']['hits']
for hit in hits:
genes[hit['_id']] = GeneDocument(hit)
query = ElasticQuery(Query.ids(ens_ids), sources=sources)
ScanAndScroll.scan_and_scroll(ElasticSettings.idx('GENE'), call_fun=get_genes, query=query)
return genes
示例13: get_object
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_object(self):
q = ElasticQuery(Query.ids(self.kwargs[self.lookup_field]))
s = Search(search_query=q, idx=getattr(self, 'idx'))
try:
result = s.get_json_response()['hits']['hits'][0]
obj = ElasticObject(initial=result['_source'])
obj.uuid = result['_id']
obj.criteria_type = result['_type']
# May raise a permission denied
self.check_object_permissions(self.request, obj)
return obj
except (TypeError, ValueError, IndexError):
raise Http404
示例14: get_pub_docs_by_pmid
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def get_pub_docs_by_pmid(cls, pmids, sources=None):
''' Get the publication documents for a list of PMIDs.
A dictionary is returned with the key being the PMID and the
value the publication document. '''
pubs = {}
def get_pubs(resp_json):
hits = resp_json['hits']['hits']
for hit in hits:
pubs[hit['_id']] = PublicationDocument(hit)
from elastic.search import ElasticQuery, ScanAndScroll
query = ElasticQuery(Query.ids(pmids), sources=sources)
ScanAndScroll.scan_and_scroll(ElasticSettings.idx('PUBLICATION'), call_fun=get_pubs, query=query)
return pubs
示例15: study_page
# 需要导入模块: from elastic.query import Query [as 别名]
# 或者: from elastic.query.Query import ids [as 别名]
def study_page(request, study):
''' Renders a study page. '''
if study is None:
messages.error(request, 'No study id given.')
raise Http404()
query = ElasticQuery(Query.ids(study.split(',')))
elastic = Search(query, idx=ElasticSettings.idx('STUDY', 'STUDY'), size=5)
res = elastic.search(obj_document=StudyDocument)
if res.hits_total == 0:
messages.error(request, 'Study(s) '+study+' not found.')
elif res.hits_total < 9:
names = ', '.join([getattr(doc, 'study_name') for doc in res.docs])
context = {'features': res.docs, 'title': names}
return render(request, 'study/study.html', context, content_type='text/html')
raise Http404()