Пример #1
0
 def build_id_query(self, vid, scopes=None):
     _default_scopes = '_id'
     scopes = scopes or _default_scopes
     if is_str(scopes):
         _query = {
             "match": {
                 scopes: {
                     "query": "{}".format(vid),
                     "operator": "and"
                 }
             }
         }
     elif is_seq(scopes):
         _query = {
             "multi_match": {
                 "query": "{}".format(vid),
                 "fields": scopes,
                 "operator": "and"
             }
         }
     else:
         raise ValueError('"scopes" cannot be "%s" type'.format(
             type(scopes)))
     _q = {"query": _query}
     self._query_options.pop(
         "query",
         None)  # avoid "query" be overwritten by self.query_options
     _q.update(self._query_options)
     return _q
Пример #2
0
 def build_id_query(self, vid, scopes=None):
     # _default_scopes = [
     #     '_id',
     #     'rsid', "dbnsfp.rsid", "dbsnp.rsid", "evs.rsid", "mutdb.rsid"  # for rsid
     #     "dbsnp.gene.symbol", 'evs.gene.symbol', 'clinvar.gene.symbol',
     #     'dbnsfp.genename', "cadd.gene.genename", "docm.genename",      # for gene symbols
     # ]
     _default_scopes = '_id'
     scopes = scopes or _default_scopes
     if is_str(scopes):
         _query = {
             "match": {
                 scopes: {
                     "query": "{}".format(vid),
                     "operator": "and"
                 }
             }
         }
     elif is_seq(scopes):
         _query = {
             "multi_match": {
                 "query": "{}".format(vid),
                 "fields": scopes,
                 "operator": "and"
             }
         }
     else:
         raise ValueError('"scopes" cannot be "%s" type'.format(type(scopes)))
     _q = {"query": _query}
     self._query_options.pop("query", None)    # avoid "query" be overwritten by self.query_options
     _q.update(self._query_options)
     return _q
Пример #3
0
 def build_id_query(self, vid, scopes=None):
     _default_scopes = '_id'
     scopes = scopes or _default_scopes
     if is_str(scopes):
         _query = {
             "match": {
                 scopes: {
                     "query": "{}".format(vid),
                     "operator": "and"
                 }
             }
         }
     elif is_seq(scopes):
         _query = {
             "multi_match": {
                 "query": "{}".format(vid),
                 "fields": scopes,
                 "operator": "and"
             }
         }
     else:
         raise ValueError('"scopes" cannot be "%s" type'.format(type(scopes)))
     _q = {"query": _query}
     self._query_options.pop("query", None)    # avoid "query" be overwritten by self.query_options
     _q.update(self._query_options)
     return _q
Пример #4
0
 def build_id_query(self, vid, scopes=None):
     # _default_scopes = [
     #     '_id',
     #     'rsid', "dbnsfp.rsid", "dbsnp.rsid", "evs.rsid", "mutdb.rsid"  # for rsid
     #     "dbsnp.gene.symbol", 'evs.gene.symbol', 'clinvar.gene.symbol',
     #     'dbnsfp.genename', "cadd.gene.genename", "docm.genename",      # for gene symbols
     # ]
     _default_scopes = '_id'
     scopes = scopes or _default_scopes
     if is_str(scopes):
         _query = {
             "match": {
                 scopes: {
                     "query": "{}".format(vid),
                     "operator": "and"
                 }
             }
         }
     elif is_seq(scopes):
         _query = {
             "multi_match": {
                 "query": "{}".format(vid),
                 "fields": scopes,
                 "operator": "and"
             }
         }
     else:
         raise ValueError('"scopes" cannot be "%s" type'.format(
             type(scopes)))
     _q = {"query": _query}
     self._query_options.pop(
         "query",
         None)  # avoid "query" be overwritten by self.query_options
     _q.update(self._query_options)
     return _q
Пример #5
0
 def _cleaned_scopes(self, scopes):
     '''return a cleaned scopes parameter.
         should be either a string or a list of scope fields.
     '''
     if scopes:
         if is_str(scopes):
             scopes = [x.strip() for x in scopes.split(',')]
         if is_seq(scopes):
             scopes = [x for x in scopes if x]
             if len(scopes) == 1:
                 scopes = scopes[0]
         else:
             scopes = None
     else:
         scopes = None
     return scopes
Пример #6
0
 def _cleaned_scopes(self, scopes):
     '''return a cleaned scopes parameter.
         should be either a string or a list of scope fields.
     '''
     if scopes:
         if is_str(scopes):
             scopes = [x.strip() for x in scopes.split(',')]
         if is_seq(scopes):
             scopes = [x for x in scopes if x]
             if len(scopes) == 1:
                 scopes = scopes[0]
         else:
             scopes = None
     else:
         scopes = None
     return scopes