Skip to content

Commit

Permalink
more delinting
Browse files Browse the repository at this point in the history
  • Loading branch information
Didion, John (NIH/NHGRI) [F] committed Mar 23, 2017
1 parent d545faf commit 4761ab4
Show file tree
Hide file tree
Showing 9 changed files with 623 additions and 333 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# C0326: Disabled because it incorrectly flags whitespace around default values
# when function annotations are used; will add a custom checker that
# flags all other cases
disable=fixme,C0303,C0326,too-few-public-methods,too-many-instance-attributes,too-many-arguments,too-many-locals,too-many-branches,too-many-statements,too-many-function-args,too-many-lines,too-many-boolean-expressions,too-many-return-statements
disable=fixme,C0303,C0326,too-few-public-methods,too-many-instance-attributes,too-many-arguments,too-many-locals,too-many-branches,too-many-statements,too-many-function-args,too-many-lines,too-many-boolean-expressions,too-many-return-statements,too-many-ancestors
ignore=__pycache__,*.pyx,_version.py
16 changes: 13 additions & 3 deletions atropos/commands/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
import os
import sys
import textwrap
from atropos import AtroposError
from atropos.commands import (
Pipeline, SingleEndPipelineMixin, PairedEndPipelineMixin, create_reader)
from atropos.commands import load_known_adapters
from atropos.commands.stats import (
SingleEndReadStatistics, PairedEndReadStatistics)
from atropos.adapters import AdapterParser, BACK
# TODO: Only import used members
from atropos.trim.modifiers import *
from atropos.trim.filters import *
from atropos.trim.writers import *
from atropos.trim.modifiers import (
AdapterCutter, DoubleEncoder, InsertAdapterCutter, LengthTagModifier,
MergeOverlapping, MinCutter, NEndTrimmer, NextseqQualityTrimmer,
NonDirectionalBisulfiteTrimmer, OverwriteRead, PairedEndModifiers,
PrefixSuffixAdder, PrimerTrimmer, QualityTrimmer, RRBSTrimmer,
SingleEndModifiers, SuffixRemover, SwiftBisulfiteTrimmer,
UnconditionalCutter, ZeroCapper)
from atropos.trim.filters import (
FilterFactory, Filters, MergedReadFilter, NContentFilter, NoFilter,
TooLongReadFilter, TooShortReadFilter, TrimmedFilter, UntrimmedFilter)
from atropos.trim.writers import (
Formatters, InfoFormatter, RestFormatter, WildcardFormatter, Writers)
from atropos.io import STDOUT
from atropos.util import RandomMatchProbability, Const, run_interruptible

Expand Down
3 changes: 3 additions & 0 deletions atropos/io/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def __next__(self):
raise

def close(self):
"""Finish the progress bar and close the underlying iterator.
"""
if not self.done:
self.finish()
self.done = True
Expand All @@ -161,6 +163,7 @@ class MagCounter(progressbar.widgets.WidgetBase):
"""Custom widget that formats the value using a specified magnitude.
"""
def __init__(self, mag_format):
super().__init__()
self._format = mag_format

def __call__(self, progress, data):
Expand Down
26 changes: 24 additions & 2 deletions atropos/io/seqio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ def __init__(self, path, mode='r'):

@property
def name(self):
"""The underlying file name.
"""
return self._file.name

def close(self):
"""Close the underlying file.
"""
if self._close_on_exit and self._file is not None:
self._file.close()
self._file = None
Expand Down Expand Up @@ -144,6 +148,8 @@ def __iter__(self):
yield line

def close(self):
"""Close the underlying file.
"""
self._file.close()

class FastaReader(SequenceReader):
Expand Down Expand Up @@ -252,6 +258,8 @@ def __iter__(self):
fastaread.name, fastaread.sequence, qualities)

def close(self):
"""Close the underlying files.
"""
self.fastareader.close()
self.qualreader.close()

Expand Down Expand Up @@ -341,6 +349,8 @@ def __iter__(self):
yield (read1, read2)

def close(self):
"""Close the underlying files.
"""
self.reader1.close()
self.reader2.close()

Expand Down Expand Up @@ -380,6 +390,8 @@ def __iter__(self):
yield (read1, read2)

def close(self):
"""Close the underlying reader.
"""
self.reader.close()

def __enter__(self):
Expand Down Expand Up @@ -412,13 +424,20 @@ def __iter__(self):
import pysam
return self._iter(pysam.AlignmentFile(self._file))

def _iter(self, sam):
"""Create an iterator over records in the SAM/BAM file.
"""
raise NotImplementedError()

def __enter__(self):
return self

def __exit__(self, *args):
self.close()

def close(self):
"""Close the underling AlignmentFile.
"""
if self._close_on_exit and self._file is not None:
self._file.close()
self._file = None
Expand Down Expand Up @@ -654,6 +673,8 @@ def format(self, read):
return self.format_entry(read.name, read.sequence)

def format_entry(self, name, sequence):
"""Convert a sequence record to a string.
"""
if self.text_wrapper:
sequence = self.text_wrapper.fill(sequence)
return "".join((">", name, "\n", sequence, "\n"))
Expand All @@ -672,6 +693,8 @@ def format(self, read):
read.name, read.sequence, read.qualities, read.name2)

def format_entry(self, name, sequence, qualities, name2=""):
"""Convert a sequence record to a string.
"""
return "".join((
'@', name, '\n',
sequence, '\n+',
Expand Down Expand Up @@ -722,8 +745,7 @@ class InterleavedFormatter(SingleEndFormatter):
def format(self, result, read1, read2=None):
result[self.file1].extend((
self.seq_format.format(read1),
self.seq_format.format(read2)
))
self.seq_format.format(read2)))
self.written += 1
self.read1_bp += len(read1)
self.read2_bp += len(read2)
Expand Down
7 changes: 7 additions & 0 deletions atropos/scripts/atropos.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def __init__(self, *args, **kwargs):

def __call__(self, string):
return self._do_call(string, *self.args, **self.kwargs) or string

def _do_call(string, *args, **kwargs):
"""Convert and/or validate `string`.
"""
raise NotImplementedError()

class CompositeType(object):
"""A composite of multiple data types.
Expand Down Expand Up @@ -211,6 +216,8 @@ def between(min_val=None, max_val=None, type_=int):

class Command(object):
"""Base class for Atropos sub-commands.
Subclasses must define name, description, and usage members.
"""
def __init__(self, args):
self.orig_args = copy.copy(args)
Expand Down
Loading

0 comments on commit 4761ab4

Please sign in to comment.