returns a dict with query => blastline
766759
def hits(self):
        
        self.quality_sort()

        hits = dict((query, list(blines)) for (query, blines) in \
                        groupby(self, lambda x: x.query))

        self.ref_sort()

        return hits
641582
def get_fun(fun):
    '''
    
    '''
    log.debug('sqlite3 returner <get_fun> called fun: %s', fun)
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT s.id, s.full_ret, s.jid
            FROM salt_returns s
            JOIN ( SELECT MAX(jid) AS jid FROM salt_returns GROUP BY fun, id) max
            ON s.jid = max.jid
            WHERE s.fun = :fun
            '''
    cur.execute(sql,
                {'fun': fun})
    data = cur.fetchall()
    ret = {}
    if data:
        # Pop the jid off the list since it is not
        # needed and I am trying to get a perfect
        # pylint score :-)
        data.pop()
        for minion, ret in data:
            ret[minion] = salt.utils.json.loads(ret)
    _close_conn(conn)
    return ret
1136364
def query(options, collection_name, num_to_skip,
          num_to_return, query, field_selector, opts, check_keys=False):
    
    data = struct.pack("<I", options)
    data += bson._make_c_string(collection_name)
    data += struct.pack("<i", num_to_skip)
    data += struct.pack("<i", num_to_return)
    encoded = bson.BSON.encode(query, check_keys, opts)
    data += encoded
    max_bson_size = len(encoded)
    if field_selector is not None:
        encoded = bson.BSON.encode(field_selector, False, opts)
        data += encoded
        max_bson_size = max(len(encoded), max_bson_size)
    (request_id, query_message) = __pack_message(2004, data)
    return (request_id, query_message, max_bson_size)
181980
def to_query(self):
        
        return {
            "geo_shape": {
                self.name: {
                    "indexed_shape":  {
                        "index": self.index_name,
                        "type": self.doc_type,
                        "id": self.shape_id,
                        "path": self.path
                    }
                }
            }
        }
313082
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'matching_results' in _dict:
            args['matching_results'] = _dict.get('matching_results')
        if 'hits' in _dict:
            args['hits'] = [
                QueryResult._from_dict(x) for x in (_dict.get('hits'))
            ]
        return cls(**args)
62375
def query(self, query):
    ''''''
    query = query.copy()
    query.key = self._transform(query.key)
    return self.child_datastore.query(query)
773546
def blast_records_to_object(blast_records):
    

    # container for transformed objects
    blast_objects_list = []

    for blast_record in blast_records:

        br = BlastRecord(**{'query': blast_record.query,
                            'version': blast_record.version,
                            'expect': blast_record.expect,
                            'application': blast_record.application,
                            'reference': blast_record.reference})

        for alignment in blast_record.alignments:

            al = Alignment(**{
                'hit_def': alignment.hit_def,
                'title': alignment.title,
                'length': alignment.length,
            })

            for hsp in alignment.hsps:
                h = Hsp(**{
                    'align_length': hsp.align_length,
                    'bits': hsp.bits,
                    'expect': hsp.expect,
                    'frame': hsp.frame,
                    'gaps': hsp.gaps,
                    'identities': hsp.identities,
                    'match': hsp.match,
                    'num_alignments': hsp.num_alignments,
                    'positives': hsp.positives,
                    'query': hsp.query,
                    'query_end': hsp.query_end,
                    'query_start': hsp.query_start,
                    'sbjct': hsp.sbjct,
                    'sbjct_end': hsp.sbjct_end,
                    'sbjct_start': hsp.sbjct_start,
                    'score': hsp.score,
                    'strand': hsp.strand,
                    'str': str(hsp),
                })

                al.hsp_list.append(h)
            br.alignments.append(al)
        blast_objects_list.append(br)
    return blast_objects_list
348023
def _get_query(self, cursor):
        '''
        
        '''
        query = {'q':'*:*',
                'sort':'id desc',
                'rows':self._rows,
                'cursorMark':cursor}
        if self._date_field:
            query['sort'] = "{} asc, id desc".format(self._date_field)
        if self._per_shard:
            query['distrib'] = 'false'
        return query
758727
def basic_query(returns):
    """"""
    return compose(
        reusable,
        map_send(parse_request),
        map_yield(prepare_params, snug.prefix_adder(API_PREFIX)),
        map_return(loads(returns)),
        oneyield,
    )
430301
def dmql(query):
        """"""
        if isinstance(query, dict):
            raise ValueError("You supplied a dictionary to the dmql_query parameter, but a string is required."
                                " Did you mean to pass this to the search_filter parameter? ")

        # automatically surround the given query with parentheses if it doesn't have them already
        if len(query) > 0 and query != "*" and query[0] != '(' and query[-1] != ')':
            query = '({})'.format(query)
        return query
425604
def to_dict(self):
        """"""
        d = {}
        if self.query_params_match is not None:
            d['@query_params_match'] = self.query_params_match
        if self.query_person_match is not None:
            d['@query_person_match'] = self.query_person_match
        if self.valid_since is not None:
            d['@valid_since'] = datetime_to_str(self.valid_since)
        if self.source is not None:
            d['source'] = self.source.to_dict()
        d.update(self.fields_to_dict())
        return d
417458
def to_dict(self, trim=True):
        """"""
        if trim:
            return self._to_trimmed_dict()
        else:
            return dict(zip(DATASET_KEYS, self))
599568
def blast(self, blastfile=None, outfile=None):
        
        from jcvi.formats.blast import BlastSlow, BlastLineByConversion

        if not outfile:
            outfile = self.filename + ".blast"

        if blastfile is not None:
            blasts = BlastSlow(blastfile).to_dict()
        else:
            blasts = None

        fw = must_open(outfile, "w", checkexists=True)
        nlines = 0
        for a, b, id in self.iter_pairs():
            if (a, b) in blasts:
                bline = blasts[(a, b)]
            elif (b, a) in blasts:
                bline = blasts[(b, a)]
            else:
                line = "\t".join((a, b))
                bline = BlastLineByConversion(line, mode="110000000000")

            print(bline, file=fw)
            nlines += 1
        fw.close()

        logging.debug("A total of {0} BLAST lines written to `{1}`."\
                        .format(nlines, outfile))

        return outfile
1099805
def _to_query_json(self):
    
    json = {
      'compression': 'GZIP' if self._compressed else 'NONE',
      'ignoreUnknownValues': self._ignore_unknown_values,
      'maxBadRecords': self._max_bad_records,
      'sourceFormat': self._bq_source_format,
      'sourceUris': self._source,
    }
    if self._source_format == 'csv' and self._csv_options:
      json['csvOptions'] = {}
      json['csvOptions'].update(self._csv_options._to_query_json())
    if self._schema:
      json['schema'] = {'fields': self._schema._bq_schema}
    return json
243943
def get_fun(fun):
    '''
    
    '''
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''SELECT s.id,s.jid, s.full_ret
            FROM salt_returns s
            JOIN ( SELECT MAX(jid) AS jid FROM salt_returns GROUP BY fun, id) max
            ON s.jid = max.jid
            WHERE s.fun = ?
            '''

    cur.execute(sql, (fun,))
    data = cur.fetchall()

    ret = {}
    if data:
        for minion, _, retval in data:
            ret[minion] = salt.utils.json.loads(retval)
    _close_conn(conn)
    return ret
402236
def slug_from_dict(d, max_len=128, delim='-'):
    
    return slug_from_iter(list(d.values()), max_len=max_len, delim=delim)
649098
def _init_get_dict():
        """"""
        get_dict = {'main chain': PandasPdb._get_mainchain,
                    'hydrogen': PandasPdb._get_hydrogen,
                    'c-alpha': PandasPdb._get_calpha,
                    'carbon': PandasPdb._get_carbon,
                    'heavy': PandasPdb._get_heavy}
        return get_dict