Open B6/M8 file, filter entries by E-Value, and write said entries
17936
def main():
    """"""

    for entry in b6_evalue_filter(args.b6, args.e_value):
        args.output.write(entry.write())
284926
def mb_filter(fastq, cores):
    ''' 
    '''
    filter_mb = partial(umi_filter)
    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_mb, list(bigchunk)):
            for read in chunk:
                sys.stdout.write(read)
491445
def open_multi(cls, sock, chunk_types, isattys, chunk_eof_type=None, buf_size=None,
                 select_timeout=None):
    """"""
    cls._assert_aligned(chunk_types, isattys)

    # N.B. This is purely to permit safe handling of a dynamic number of contextmanagers.
    with ExitStack() as stack:
      read_fds, write_fds = list(zip(
        # Allocate one pipe pair per chunk type provided.
        *(stack.enter_context(_pipe(isatty)) for isatty in isattys)
      ))
      writer = NailgunStreamWriter(
        read_fds,
        sock,
        chunk_types,
        chunk_eof_type,
        buf_size=buf_size,
        select_timeout=select_timeout
      )
      with writer.running():
        yield write_fds, writer
544360
def process_tlog(filename):
    ''''''

    print("Processing %s" % filename)

    mlog = mavutil.mavlink_connection(filename, dialect=args.dialect, zero_time_base=True)

    # first walk the entire file, grabbing all messages into a hash of lists,
    #and the first message of each type into a hash
    msg_types = {}
    msg_lists = {}

    types = args.types
    if types is not None:
        types = types.split(',')

    # note that Octave doesn't like any extra '.', '*', '-', characters in the filename
    (head, tail) = os.path.split(filename)
    basename = '.'.join(tail.split('.')[:-1])
    mfilename = re.sub('[\.\-\+\*]','_', basename) + '.m'
    # Octave also doesn't like files that don't start with a letter
    if (re.match('^[a-zA-z]', mfilename) == None):
        mfilename = 'm_' + mfilename

    if head is not None:
        mfilename = os.path.join(head, mfilename)
    print("Creating %s" % mfilename)

    f = open(mfilename, "w")

    type_counters = {}

    while True:
        m = mlog.recv_match(condition=args.condition)
        if m is None:
            break

        if types is not None and m.get_type() not in types:
            continue
        if m.get_type() == 'BAD_DATA':
            continue

        fieldnames = m._fieldnames
        mtype = m.get_type()
        if mtype in ['FMT', 'PARM']:
            continue

        if mtype not in type_counters:
            type_counters[mtype] = 0
            f.write("%s.columns = {'timestamp'" % mtype)
            for field in fieldnames:
                val = getattr(m, field)
                if not isinstance(val, str):
                    if type(val) is not list:
                        f.write(",'%s'" % field)
                    else:
                        for i in range(0, len(val)):
                            f.write(",'%s%d'" % (field, i + 1))
            f.write("};\n")

        type_counters[mtype] += 1
        f.write("%s.data(%u,:) = [%f" % (mtype, type_counters[mtype], m._timestamp))
        for field in m._fieldnames:
            val = getattr(m, field)
            if not isinstance(val, str):
                if type(val) is not list:
                    f.write(",%.20g" % val)
                else:
                    for i in range(0, len(val)):
                        f.write(",%.20g" % val[i])
        f.write("];\n")
    f.close()
1186593
def filter_data(data, filter_name, filter_file, bits, filterbank_off=False,
                    swstat_channel_name=None):
    '''
    
    '''

    # if filterbank is off then return a time series of zeroes
    if filterbank_off:
        return numpy.zeros(len(data))

    # loop over the 10 filters in the filterbank
    for i in range(10):

        # read the filter
        filter = Filter(filter_file[filter_name][i])

        # if bit is on then filter the data
        bit = int(bits[-(i+1)])
        if bit:
            logging.info('filtering with filter module %d', i)

            # if there are second-order sections then filter with them
            if len(filter.sections):
                data = filter.apply(data)

            # else it is a filter with only gain so apply the gain
            else:
                coeffs = iir2z(filter_file[filter_name][i])
                if len(coeffs) > 1:
                    logging.info('Gain-only filter module return more than one number')
                    sys.exit()
                gain = coeffs[0]
                data = gain * data

    return  data
1000293
def main():
    
    with open(FILENAME, "r") as file_obj:
        contents = file_obj.read()
    desired = get_desired()
    if contents == EXPECTED:
        with open(FILENAME, "w") as file_obj:
            file_obj.write(desired)
    elif contents != desired:
        raise ValueError("Unexpected contents", contents, "Expected", EXPECTED)
678980
def write_str2file(pathname, astr):
    """"""
    fname = pathname
    fhandle = open(fname, 'wb')
    fhandle.write(astr)
    fhandle.close()
908917
private void handleArchiveByFile(Predicate<String> filter, File archive, List<String> discoveredFiles)
    {
        try
        {
            try (ZipFile zip = new ZipFile(archive))
            {
                Enumeration<? extends ZipEntry> entries = zip.entries();
                
                while (entries.hasMoreElements())
                {
                    ZipEntry entry = entries.nextElement();
                    String name = entry.getName();
                    if (filter.accept(name))
                        discoveredFiles.add(name);
                }
            }
        }
        catch (IOException e)
        {
            throw new RuntimeException("Error handling file " + archive, e);
        }
    }
499538
def _filter_to_info(in_file, data):
    
    header = ("""##INFO=<ID=DKFZBias,Number=.,Type=String,Description="Bias estimation based on unequal read support from DKFZBiasFilterVariant Depth">\n""")
    out_file = "%s-ann.vcf" % utils.splitext_plus(in_file)[0]
    if not utils.file_uptodate(out_file, in_file) and not utils.file_uptodate(out_file + ".gz", in_file):
        with file_transaction(data, out_file) as tx_out_file:
            with utils.open_gzipsafe(in_file) as in_handle:
                with open(tx_out_file, "w") as out_handle:
                    for line in in_handle:
                        if line.startswith("#CHROM"):
                            out_handle.write(header + line)
                        elif line.startswith("#"):
                            out_handle.write(line)
                        else:
                            out_handle.write(_rec_filter_to_info(line))
    return vcfutils.bgzip_and_index(out_file, data["config"])
1216366
def first_up(ofile, Rec, file_type):
    
    keylist = []
    pmag_out = open(ofile, 'a')
    outstring = "tab \t" + file_type + "\n"
    pmag_out.write(outstring)
    keystring = ""
    for key in list(Rec.keys()):
        keystring = keystring + '\t' + key
        keylist.append(key)
    keystring = keystring + '\n'
    pmag_out.write(keystring[1:])
    pmag_out.close()
    return keylist
349172
def wr_tsv(fout_tsv, tsv_data, **kws):
    """"""
    items_str = "items" if "items" not in kws else kws["items"]
    if tsv_data:
        ifstrm = sys.stdout if fout_tsv is None else open(fout_tsv, 'w')
        num_items = prt_tsv(ifstrm, tsv_data, **kws)
        if fout_tsv is not None:
            sys.stdout.write("  {N:>5} {ITEMS} WROTE: {FOUT}\n".format(
                N=num_items, ITEMS=items_str, FOUT=fout_tsv))
            ifstrm.close()
    else:
        sys.stdout.write("      0 {ITEMS}. NOT WRITING {FOUT}\n".format(
            ITEMS=items_str, FOUT=fout_tsv))
419257
def _write_to_file(self, filename, bytesvalue):
        """"""
        fh, tmp = tempfile.mkstemp()
        with os.fdopen(fh, self._flag) as f:
            f.write(self._dumps(bytesvalue))
        rename(tmp, filename)
        os.chmod(filename, self._mode)
1084010
def BDEVolumeOpen(bde_volume, path_spec, file_object, key_chain):
  
  password = key_chain.GetCredential(path_spec, 'password')
  if password:
    bde_volume.set_password(password)

  recovery_password = key_chain.GetCredential(path_spec, 'recovery_password')
  if recovery_password:
    bde_volume.set_recovery_password(recovery_password)

  startup_key = key_chain.GetCredential(path_spec, 'startup_key')
  if startup_key:
    bde_volume.read_startup_key(startup_key)

  bde_volume.open_file_object(file_object)
461925
def write_listing_to_textfile(textfile, tracklisting):
    """"""
    with codecs.open(textfile, 'wb', 'utf-8') as text:
        text.write(tracklisting)
1133158
def WriteBlobs(self, blob_id_data_map, cursor=None):
    """"""
    chunks = []
    for blob_id, blob in iteritems(blob_id_data_map):
      chunks.extend(_BlobToChunks(blob_id.AsBytes(), blob))
    for values in _PartitionChunks(chunks):
      _Insert(cursor, "blobs", values)
1303050
def filter_python_files(files):
    ""
    py_files = []
    for f in files:
        # If we end in .py, or if we don't have an extension and file says that
        # we are a python script, then add us to the list
        extension = os.path.splitext(f)[-1]

        if extension:
            if extension == '.py':
                py_files.append(f)
        elif 'python' in open(f, 'r').readline():
            py_files.append(f)
        elif 'python script' in bash('file {}'.format(f)).value().lower():
            py_files.append(f)

    return py_files
433739
def from_file (filename):
    
    entries = []
    with open(filename) as fd:
        lines = []
        for line in fd.readlines():
            line = line.rstrip()
            if not line:
                if lines:
                    entries.append(from_headers("\r\n".join(lines)))
                lines = []
            else:
                lines.append(line)
        if lines:
            entries.append(from_headers("\r\n".join(lines)))
        return entries