Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
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
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
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
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:
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)