How to use the xopen.xopen function in xopen

To help you get started, we’ve selected a few xopen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marcelm / cutadapt / src / cutadapt / parser.py View on Github external
def parse(self, spec: str, cmdline_type: str = 'back') -> Iterator[Adapter]:
        """
        Parse an adapter specification and yield appropriate Adapter classes.
        This works like the _parse_no_file() function above, but also supports the
        ``file:`` notation for reading adapters from an external FASTA
        file. Since a file can contain multiple adapters, this
        function is a generator.
        """
        if spec.startswith('file:'):
            # read adapter sequences from a file
            with xopen(spec[5:], mode="rb", threads=0) as f:
                fasta = FastaReader(f)
                for record in fasta:
                    name = record.name.split(None, 1)
                    name = name[0] if name else None
                    yield self._parse(record.sequence, cmdline_type, name=name)
        else:
            yield self._parse(spec, cmdline_type, name=None)
github marcelm / cutadapt / src / cutadapt / seqio.py View on Github external
def __init__(self, file):
		"""
		file is a path or a file-like object. In both cases, the file may
		be compressed (.gz, .bz2, .xz).
		"""
		if isinstance(file, str):
			file = xopen(file)
			self._close_on_exit = True
		self._file = file
github grocsvs / grocsvs / simple_demux_map / demux.py View on Github external
def get_out_fastqs(sample_names, outdir):
    samples_to_out_fastqs = {}

    for sample_name in sample_names:
        samples_to_out_fastqs[sample_name] = []
        for i in [1,2]:
            outpath = os.path.join(outdir, "{}_{}.fastq.gz".format(sample_name, i))
            outfile = xopen.xopen(outpath, "w")

            samples_to_out_fastqs[sample_name].append(outfile)

    return samples_to_out_fastqs
github grocsvs / grocsvs / simple_demux_map / demux.py View on Github external
def load_gem_barcodes(bcs_path):
    bcs_file = xopen.xopen(bcs_path)
    bcs = []
    for line in bcs_file:
        bcs.append(line.strip())
    bcs = set(bcs)
    return bcs
github grocsvs / grocsvs / simple_demux_map / demux.py View on Github external
def fastq_iter(inpath):
    fastq_file = xopen.xopen(inpath)

    while True:
        lines = [fastq_file.readline().strip() for i in range(4)]
        if len(lines[-1]) < 1:
            break
        yield lines
github IUNetSci / hoaxy-backend / hoaxy / commands / sns.py View on Github external
def load_tweets(cls, session, args):
        """Load tweets from file into database.
        """
        parser = Parser()
        ntweets = args['--number-of-tweets']
        strict_on_error = args['--strict-on-error']
        true_counter = 0
        counter = 0
        jds = []
        f = xopen(args[''])
        platform_id = get_platform_id(session, N_PLATFORM_TWITTER)
        bucket_size = args['--window-size']
        try:
            for line in f:
                counter += 1
                if line:
                    try:
                        jd = json.loads(line)
                        if 'in_reply_to_status_id' in jd and 'user' in jd and\
                                'text' in jd:
                            jds.append(json.loads(line))
                            true_counter += 1
                        else:
                            logger.error('Not a tweet at line %s, raw data %r',
                                         counter, jd)
                            if strict_on_error:
github marcelm / cutadapt / src / cutadapt / utils.py View on Github external
def xopen(self, path, mode):
        logger.debug("Opening file '%s', mode '%s' with xopen", path, mode)
        return xopen(path, mode, compresslevel=self.compression_level, threads=self.threads)

xopen

Open compressed files transparently

MIT
Latest version published 22 days ago

Package Health Score

79 / 100
Full package analysis

Popular xopen functions

Similar packages