Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed May 29, 2024
1 parent 37057d8 commit 1ebfa62
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions mxdx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""mxdx: multiplexing and demultiplexing records since the early 90s."""

from . import _version
__version__ = _version.get_versions()['version']
31 changes: 16 additions & 15 deletions mxdx/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -503,7 +504,7 @@ def _readsam(data):

if not refstart.isdigit():
raise ParseError()
except:
except: # noqa E722
yield None, None
break
else:
Expand Down
8 changes: 5 additions & 3 deletions mxdx/_mxdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions mxdx/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""mxdx: multiplexing and demultiplexing."""
import click
import sys
import pathlib
Expand All @@ -9,6 +10,7 @@

@click.group()
def cli():
"""mxdx: multiplexing and demultiplexing."""
pass


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""mxdx: multiplexing and demultiplexing tools"""
"""mxdx: multiplexing and demultiplexing."""
import versioneer
from setuptools import setup, find_packages

Expand Down

0 comments on commit 1ebfa62

Please sign in to comment.