Retrieve k/v pairs given a prefix and filter using {inc,exc}_list
975948
def peer_retrieve_by_prefix(prefix, relation_name='cluster', delimiter='_',
                            inc_list=None, exc_list=None):
    
    inc_list = inc_list if inc_list else []
    exc_list = exc_list if exc_list else []
    peerdb_settings = peer_retrieve('-', relation_name=relation_name)
    matched = {}
    if peerdb_settings is None:
        return matched
    for k, v in peerdb_settings.items():
        full_prefix = prefix + delimiter
        if k.startswith(full_prefix):
            new_key = k.replace(full_prefix, '')
            if new_key in exc_list:
                continue
            if new_key in inc_list or len(inc_list) == 0:
                matched[new_key] = v
    return matched
482276
def get_filters_values(self):
        
        return [(flt, value) for flt, value in zip(self.filters, self.values)]
759328
def sb_filter(fastq, bc, cores, nedit):
    ''' 
    '''
    barcodes = set(sb.strip() for sb in bc)
    if nedit == 0:
        filter_sb = partial(exact_sample_filter2, barcodes=barcodes)
    else:
        barcodehash = MutationHash(barcodes, nedit)
        filter_sb = partial(correcting_sample_filter2, barcodehash=barcodehash)
    p = multiprocessing.Pool(cores)

    chunks = tz.partition_all(10000, read_fastq(fastq))
    bigchunks = tz.partition_all(cores, chunks)
    for bigchunk in bigchunks:
        for chunk in p.map(filter_sb, list(bigchunk)):
            for read in chunk:
                sys.stdout.write(read)
765629
def match_as_dict(self, film_sl_vectors, substrate_sl_vectors, film_vectors, substrate_vectors, match_area):
        
        d = {}
        d["film_sl_vecs"] = np.asarray(film_sl_vectors)
        d["sub_sl_vecs"] = np.asarray(substrate_sl_vectors)
        d["match_area"] = match_area
        d["film_vecs"] = np.asarray(film_vectors)
        d["sub_vecs"] = np.asarray(substrate_vectors)

        return d
257545
function split(nodes, filters) {
    var result = {};
    var nNodes = nodes.length, nFilters = filters.length;
    var iNode = 0;
    for (var iFilter = 0; iFilter < nFilters; iFilter++) {
        var filter = filters[iFilter];
        var next = [];
        while (iNode < nNodes && nodes[iNode].type === filter.type) {
            next.push(nodes[iNode]);
            iNode++;
        }
        result[filter.name] = next;
    }
    return result;
}
1358116
def _get_var_array(self, k, use_raw=False, layer='X'):
        """"""
        in_raw_obs_names = k in self.raw.obs_names if self.raw is not None else False

        if use_raw and self.raw is None:
            raise ValueError('.raw doesn\'t exist')

        if k in self.var.keys():
            x = self._var[k]
        elif in_raw_obs_names and use_raw and layer == 'X':
            x = self.raw[k].X
        elif k in self.obs_names and not use_raw and (layer == 'X' or layer in self.layers.keys()):
            x = self[k].X if layer=='X' else self[k].layers[layer]
        elif use_raw and layer != 'X':
            raise ValueError('No layers in .raw')
        elif layer != 'X' and layer not in self.layers.keys():
            raise ValueError('Did not find {} in layers.keys.'
                             .format(layer))
        else:
            raise ValueError('Did not find {} in var.keys or obs_names.'
                             .format(k))
        return x
497355
def list2bytecode(l, opc, varnames, consts):
    
    bc = []
    for i, opcodes in enumerate(l):
        opname = opcodes[0]
        operands = opcodes[1:]
        if opname not in opc.opname:
            raise TypeError(
                "error at item %d [%s, %s], opcode not valid" %
                (i, opname, operands))
        opcode = opc.opmap[opname]
        bc.append(opcode)
        print(opname, operands)
        gen = (j for j in operands if operands)
        for j in gen:
            k = (consts if opcode in opc.CONST_OPS else varnames).index(j)
            if k == -1:
                raise TypeError(
                    "operand %s [%s, %s], not found in names" %
                    (i, opname, operands))
            else:
                bc += num2code(k)
                pass
            pass
        pass
    if opc.python_version < 3.0:
        return reduce(lambda a, b: a + chr(b), bc, '')
    else:
        if PYTHON3:
            return bytes(bc)
        else:
            return bytes(bytearray(bc))
294656
def get_stripped_prefix(source, prefix):
    
    cut = len(prefix)
    return {
        k[cut:]: v for k, v in source.items()
        if k.startswith(prefix)
    }
259987
def query(self, name, reshape=RESHAPE_DEFAULT, filt=None, idval=None, idxlower=True):
        '''
        
        '''
        gdx_handle = self.gdx_handle
        ret, symNr = gdxcc.gdxFindSymbol(gdx_handle, name)
        assert ret, "Symbol '%s' not found in GDX '%s'" % (name, self.internal_filename)
        sinfo = self.get_sid_info(symNr)
        dim = sinfo['dim']
        symType = sinfo['stype']
        ret, nrRecs = gdxcc.gdxDataReadStrStart(gdx_handle, symNr)
        assert ret, get_last_error('gdxDataReadStrStart', gdx_handle)
        if idval is None:
            if symType == gdxcc.GMS_DT_EQU:
                idval = gdxcc.GMS_VAL_MARGINAL
            else:
                idval = gdxcc.GMS_VAL_LEVEL
        ifilt = None
        vtable = [None]*(nrRecs)
        rcounter = 0
        rowtype = None
        if filt != None:
            if isinstance(filt,list):
                filt = '^({0})$'.format('|'.join([re.escape(x) for x in filt]))
            if isinstance(filt, str):
                filt_func = re.compile(filt, re.IGNORECASE).match
            else:
                filt_func = filt
        for i in range(nrRecs):
            vrow = [None]*(dim+1)
            ret, elements, values, afdim = gdxcc.gdxDataReadStr(gdx_handle)
            assert ret, get_last_error('gdxDataReadStr', gdx_handle)
            if (filt != None):
                match_filt = False
                for e in elements:
                    m = filt_func(e)
                    if m != None:
                        match_filt = True
                        break
                if not match_filt:
                    continue
            d = -1
            for d in range(dim):
                try:
                    vrow[d] = int(elements[d])
                except:
                    vrow[d] = elements[d].lower() if idxlower else elements[d]
            vrow[d+1] = values[idval]
            vtable[rcounter] = vrow
            rcounter += 1
        gdxcc.gdxDataReadDone(gdx_handle)
        cols = ['s%d' % x for x in range(dim)]+['val',]
        df = pd.DataFrame(vtable[:rcounter],columns=cols)
        logger.debug("%d / %d records read from <%s>" % (rcounter, nrRecs, self.internal_filename))
        if symType == gdxcc.GMS_DT_SET:
            reshape = RESHAPE_SERIES
        df = dfreshape(df, reshape)
        if symType == gdxcc.GMS_DT_SET:
            df = df.index
        self.data = df
        return df
1324757
def load_filter(name, full=False, path='filters'):
    """

    # First we'll get the filter using its internal routine.
    filt = DigitalFilter(name.split('.')[0])
    filt.fromfile(path)

    # If full, we get the inversion output
    if full:
        # Try to get the inversion result. If files are not found, most likely
        # because they were not stored, we only return the filter
        try:
            # Get file name
            path = os.path.abspath(path)
            if len(name.split('.')) == 2:
                suffix = '.gz'
            else:
                suffix = ''
            fullfile = os.path.join(path, name.split('.')[0] +
                                    '_full.txt' + suffix)

            # Read data
            out = np.loadtxt(fullfile)

        except IOError:
            return filt

        # Collect inversion-result tuple
        nspace = int(out[0][0])
        nshift = int(out[1][0])

        space_shift_matrix = np.zeros((2, nspace, nshift))
        space_shift_matrix[0, :, :] = out[5:nspace+5, :]
        space_shift_matrix[1, :, :] = out[nspace+5:2*nspace+5, :]

        out = (np.array([out[2][0], out[3][0]]), out[4][0], space_shift_matrix,
               out[2*nspace+5:3*nspace+5, :], int(out[3*nspace+5, 0]))

        return filt, out
    else:
        return filt
905717
def operators(self, ignore=0):
        
        return [k for k, v in self._operatorMap.items() if not v.flags & ignore]
115162
def keyfilter(predicate, d, factory=dict):
    
    rv = factory()
    for k, v in iteritems(d):
        if predicate(k):
            rv[k] = v
    return rv
612204
def _parse_PREFIX(value):
        ""
        channel_modes, channel_chars = value.split(')')
        channel_modes = channel_modes[1:]
        return collections.OrderedDict(zip(channel_chars, channel_modes))
531504
def get_infix_items(tokens, callback=infix_error):
    
    internal_assert(len(tokens) >= 3, "invalid infix tokens", tokens)
    (arg1, func, arg2), tokens = tokens[:3], tokens[3:]
    args = list(arg1) + list(arg2)
    while tokens:
        args = [callback([args, func, []])]
        (func, newarg), tokens = tokens[:2], tokens[2:]
        args += list(newarg)
    return func, args
840209
def retrieve_keys(bucket, key, prefix='', postfix='', delim='/',
                      directories=False, recursive=False):
        
        if key and prefix:
            assert key.endswith(delim)

        key += prefix
        # check whether key is a directory
        if not key.endswith(delim) and key:
            # check for matching prefix
            if BotoClient.check_prefix(bucket, key + delim, delim=delim):
                # found a directory
                key += delim

        listdelim = delim if not recursive else None
        results = bucket.list(prefix=key, delimiter=listdelim)
        if postfix:
            func = lambda k_: BotoClient.filter_predicate(k_, postfix, inclusive=True)
            return filter(func, results)
        elif not directories:
            func = lambda k_: BotoClient.filter_predicate(k_, delim, inclusive=False)
            return filter(func, results)
        else:
            return results
1030982
function (sKey) {
			var aFiltered = FilterProcessor.apply([sKey], oCombinedFilter, function(vRef, sPath) {
				var oContext = that.oModel.getContext('/' + vRef);
				return that.oModel.getProperty(sPath, oContext);
			});
			return aFiltered.length > 0;
		}
1099421
function readDir(p, filter, files, prefix) {
    prefix = prefix || '';
    files = files || [];
    filter = filter || function (x) {
        return x[0] !== '.';
    };

    let dir = path.join(p, prefix);
    if (!fs.existsSync(dir)) {
        return files;
    }
    if (fs.statSync(dir).isDirectory()) {
        fs.readdirSync(dir).filter(filter).forEach(function (name) {
            readDir(p, filter, files, path.join(prefix, name));
        });
    } else {
        files.push(prefix);
    }
    return files;
}