diff --git a/mxdx/__init__.py b/mxdx/__init__.py index 251da66..46a8dc1 100644 --- a/mxdx/__init__.py +++ b/mxdx/__init__.py @@ -1,2 +1,4 @@ +"""mxdx: multiplexing and demultiplexing records since the early 90s.""" + from . import _version __version__ = _version.get_versions()['version'] diff --git a/mxdx/_io.py b/mxdx/_io.py index 6588159..753e145 100644 --- a/mxdx/_io.py +++ b/mxdx/_io.py @@ -321,7 +321,7 @@ def valid_interleave(cls): @staticmethod def io_from_stream(stream, n_lines=4): - """Sniff a datastream which cannot be seeked""" + """Sniff a datastream which cannot be seeked.""" lines = ''.join([stream.readline() for i in range(n_lines)]) buf = io.StringIO(lines) read_f, write_f = IO.sniff(buf) @@ -370,7 +370,7 @@ def sniff(cls, data): for fn_read, fn_write in io_pairs: buf.seek(0) - if next(fn_read(buf)) != None: + if next(fn_read(buf)) is not None: return (fn_read, fn_write) return None, None @@ -449,30 +449,31 @@ def _readfq(fp): # this is a generator function last = None # this is a buffer keeping the last unprocessed line while True: # mimic closure; is it a bad idea? if not last: # the first record or a record following a fastq - for l in fp: # search for the start of the next record - if l[0] in '>@': # fasta/q header line - last = l[:-1] # save this line + for line in fp: # search for the start of the next record + if line[0] in '>@': # fasta/q header line + last = line[:-1] # save this line break if not last: break name, seqs, last = last[1:].partition(" ")[0], [], None - for l in fp: # read the sequence - if l[0] in '@+>': - last = l[:-1] + for line in fp: # read the sequence + if line[0] in '@+>': + last = line[:-1] break - seqs.append(l[:-1]) + seqs.append(line[:-1]) if not last or last[0] != '+': # this is a fasta record yield name, ''.join(seqs), None # yield a fasta record count += 1 - if not last: break + if not last: + break else: # this is a fastq record seq, leng, seqs = ''.join(seqs), 0, [] - for l in fp: # read the quality - seqs.append(l[:-1]) - leng += len(l) - 1 + for line in fp: # read the quality + seqs.append(line[:-1]) + leng += len(line) - 1 if leng >= len(seq): # have read enough quality last = None - yield name, seq, ''.join(seqs); # yield a fastq record + yield name, seq, ''.join(seqs) # yield a fastq record count += 1 break if last: # reach EOF before reading enough quality @@ -503,7 +504,7 @@ def _readsam(data): if not refstart.isdigit(): raise ParseError() - except: + except: # noqa E722 yield None, None break else: diff --git a/mxdx/_mxdx.py b/mxdx/_mxdx.py index f31622a..cc4fc86 100644 --- a/mxdx/_mxdx.py +++ b/mxdx/_mxdx.py @@ -16,6 +16,7 @@ class Multiplex: """Multiplex records from a file batch.""" + def __init__(self, file_map, batch, paired_handling, output): self._file_map = file_map self._batch = batch @@ -48,7 +49,7 @@ def _read_sequential(self, r1_reader, r2_reader): yield rec def read(self): - """Read requested records, tag them, and emplace in a queue""" + """Read requested records, tag them, and emplace in a queue.""" mode = 'rt' read_f = self._read_f @@ -139,6 +140,7 @@ class BufferedQueue: To adjust for this, we're increasing the amount of data which an individual queue item can hold. """ + BUFSIZE = 1024 def __init__(self, ctx): @@ -215,7 +217,7 @@ def start(self): writer.join() def read(self): - """Read from the input stream and queue""" + """Read from the input stream and queue.""" # we can't pickle the streams so this has to be thread local if self._mux_input == '-': # see https://docs.python.org/3/library/multiprocessing.html#programming-guidelines @@ -267,7 +269,7 @@ def _write_rec(self, mx, rec): out_f.write(rec.write()) def write(self): - """Write to the respective outputs""" + """Write to the respective outputs.""" default = MuxFile("badtag.r1", "badtag.r2", 0, sys.maxsize, "badtag", False) diff --git a/mxdx/cli.py b/mxdx/cli.py index f571e9e..76c3fe1 100644 --- a/mxdx/cli.py +++ b/mxdx/cli.py @@ -1,3 +1,4 @@ +"""mxdx: multiplexing and demultiplexing.""" import click import sys import pathlib @@ -9,6 +10,7 @@ @click.group() def cli(): + """mxdx: multiplexing and demultiplexing.""" pass diff --git a/setup.py b/setup.py index 56484d7..598b4f1 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -"""mxdx: multiplexing and demultiplexing tools""" +"""mxdx: multiplexing and demultiplexing.""" import versioneer from setuptools import setup, find_packages