betteridiot/bamnostic

View on GitHub
bamnostic/utils.py

Summary

Maintainability
D
2 days
Test Coverage

Function cigar_alignment has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

def cigar_alignment(seq=None, cigar=None, start_pos = 0, qualities=None, base_qual_thresh=0, query=False):
    """Use the CIGAR to filter out all unaligned data bases

    Any clipping results in the removal of those bases. If an insertion is seen in
    the CIGAR, those bases are removed from the sequence. If a deletion is seen in
Severity: Minor
Found in bamnostic/utils.py - About 7 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function parse_region has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

def parse_region(contig=None, start=None, stop=None, region=None,
                 tid=None, reference=None, end=None, until_eof=False):
    r""" Parses region information from all user set parameters.

    The main goal of this function is to handle the many different ways a user
Severity: Minor
Found in bamnostic/utils.py - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _handle_split_region has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def _handle_split_region(split_roi, until_eof=False):
    """ Checks format against `until_eof` and creates the Roi object

    Args:
        split_roi (:py:obj:`list` or :py::obj:`tuple`): the contig, start, and stop information.
Severity: Minor
Found in bamnostic/utils.py - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

                    if seg_qual[index] >= base_qual_thresh:
                        yield base, start_pos
                else:
Severity: Major
Found in bamnostic/utils.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if qualities is not None:
                            if seg_qual[index] >= base_qual_thresh:
                                yield base, start_pos
                        else:
                            yield base, start_pos
    Severity: Major
    Found in bamnostic/utils.py - About 45 mins to fix

      Function md_changes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def md_changes(seq, md_tag):
          """Recreates the reference sequence of a given alignment to the extent that the
          MD tag can represent.
      
          Note:
      Severity: Minor
      Found in bamnostic/utils.py - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def update(self, others):
              """ Same as a regular `dict.update`, however, since pypy's `dict.update`
              doesn't go through `dict.__setitem__`, this is used to ensure it does
      
              Args:
      Severity: Minor
      Found in bamnostic/utils.py - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function cigar_changes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def cigar_changes(seq, cigar):
          """Recreates the reference sequence to the extent that the CIGAR string can
              represent.
      
          Args:
      Severity: Minor
      Found in bamnostic/utils.py - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function cull has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def cull(self):
              """ Main utility function for pruning the LruDict
      
              If the length of the LruDict is more than `max_cache`, it removes the LRU item
              """
      Severity: Minor
      Found in bamnostic/utils.py - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, *args, **kwargs):
              """ Initialize the dictionary based on collections.OrderedDict. This
              is built of the basic `OrderedDict`. The major difference in instantiation
              is the usage of the `max_cache` argument. This sets the dictionary size
              to be used.
      Severity: Minor
      Found in bamnostic/utils.py - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Wontfix

                      for index, base in enumerate(seg_seq):
                          if qualities is not None:
                              if seg_qual[index] >= base_qual_thresh:
                                  yield base, start_pos
                          else:
      Severity: Major
      Found in bamnostic/utils.py and 1 other location - About 1 hr to fix
      bamnostic/utils.py on lines 829..833

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 43.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Wontfix

                      if qualities is not None:
                          if seg_qual[index] >= base_qual_thresh:
                              yield base, start_pos
                      else:
                          yield base, start_pos
      Severity: Major
      Found in bamnostic/utils.py and 1 other location - About 1 hr to fix
      bamnostic/utils.py on lines 813..818

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 43.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Missing whitespace after ','
      Open

                  for k,v in others.items():
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Each comma, semicolon or colon should be followed by whitespace.

      Okay: [a, b]
      Okay: (3,)
      Okay: a[1:4]
      Okay: a[:4]
      Okay: a[1:]
      Okay: a[1:4:2]
      E231: ['a','b']
      E231: foo(bar,baz)
      E231: [{'a':'b'}]

      Missing whitespace after ','
      Open

                      self.__setitem__(k,v)
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Each comma, semicolon or colon should be followed by whitespace.

      Okay: [a, b]
      Okay: (3,)
      Okay: a[1:4]
      Okay: a[:4]
      Okay: a[1:]
      Okay: a[1:4:2]
      E231: ['a','b']
      E231: foo(bar,baz)
      E231: [{'a':'b'}]

      Expected 2 blank lines after class or function definition, found 1
      Open

      _CIGAR_OPS = {'M': ('BAM_CMATCH', 0),
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Separate top-level function and class definitions with two blank lines.

      Method definitions inside a class are separated by a single blank
      line.
      
      Extra blank lines may be used (sparingly) to separate groups of
      related functions.  Blank lines may be omitted between a bunch of
      related one-liners (e.g. a set of dummy implementations).
      
      Use blank lines in functions, sparingly, to indicate logical
      sections.
      
      Okay: def a():\n    pass\n\n\ndef b():\n    pass
      Okay: def a():\n    pass\n\n\nasync def b():\n    pass
      Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
      Okay: default = 1\nfoo = 1
      Okay: classify = 1\nfoo = 1
      
      E301: class Foo:\n    b = 0\n    def bar():\n        pass
      E302: def a():\n    pass\n\ndef b(n):\n    pass
      E302: def a():\n    pass\n\nasync def b(n):\n    pass
      E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
      E303: def a():\n\n\n\n    pass
      E304: @decorator\n\ndef a():\n    pass
      E305: def a():\n    pass\na()
      E306: def a():\n    def b():\n        pass\n    def c():\n        pass

      Unexpected spaces around keyword / parameter equals
      Open

      def cigar_alignment(seq=None, cigar=None, start_pos = 0, qualities=None, base_qual_thresh=0, query=False):
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Don't use spaces around the '=' sign in function arguments.

      Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value, except when
      using a type annotation.
      
      Okay: def complex(real, imag=0.0):
      Okay: return magic(r=real, i=imag)
      Okay: boolean(a == b)
      Okay: boolean(a != b)
      Okay: boolean(a <= b)
      Okay: boolean(a >= b)
      Okay: def foo(arg: int = 42):
      Okay: async def foo(arg: int = 42):
      
      E251: def complex(real, imag = 0.0):
      E251: return magic(r = real, i = imag)
      E252: def complex(real, image: float=0.0):

      Missing whitespace after ','
      Open

                      self.__setitem__(k,v)
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Each comma, semicolon or colon should be followed by whitespace.

      Okay: [a, b]
      Okay: (3,)
      Okay: a[1:4]
      Okay: a[:4]
      Okay: a[1:]
      Okay: a[1:4:2]
      E231: ['a','b']
      E231: foo(bar,baz)
      E231: [{'a':'b'}]

      Unexpected spaces around keyword / parameter equals
      Open

      def cigar_alignment(seq=None, cigar=None, start_pos = 0, qualities=None, base_qual_thresh=0, query=False):
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Don't use spaces around the '=' sign in function arguments.

      Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value, except when
      using a type annotation.
      
      Okay: def complex(real, imag=0.0):
      Okay: return magic(r=real, i=imag)
      Okay: boolean(a == b)
      Okay: boolean(a != b)
      Okay: boolean(a <= b)
      Okay: boolean(a >= b)
      Okay: def foo(arg: int = 42):
      Okay: async def foo(arg: int = 42):
      
      E251: def complex(real, imag = 0.0):
      E251: return magic(r = real, i = imag)
      E252: def complex(real, image: float=0.0):

      Expected 2 blank lines after class or function definition, found 1
      Open

      warnings.formatwarning = format_warnings
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Separate top-level function and class definitions with two blank lines.

      Method definitions inside a class are separated by a single blank
      line.
      
      Extra blank lines may be used (sparingly) to separate groups of
      related functions.  Blank lines may be omitted between a bunch of
      related one-liners (e.g. a set of dummy implementations).
      
      Use blank lines in functions, sparingly, to indicate logical
      sections.
      
      Okay: def a():\n    pass\n\n\ndef b():\n    pass
      Okay: def a():\n    pass\n\n\nasync def b():\n    pass
      Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
      Okay: default = 1\nfoo = 1
      Okay: classify = 1\nfoo = 1
      
      E301: class Foo:\n    b = 0\n    def bar():\n        pass
      E302: def a():\n    pass\n\ndef b(n):\n    pass
      E302: def a():\n    pass\n\nasync def b(n):\n    pass
      E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
      E303: def a():\n\n\n\n    pass
      E304: @decorator\n\ndef a():\n    pass
      E305: def a():\n    pass\na()
      E306: def a():\n    def b():\n        pass\n    def c():\n        pass

      Do not use bare 'except'
      Open

          except:
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      When catching exceptions, mention specific exceptions when possible.

      Okay: except Exception:
      Okay: except BaseException:
      E722: except:

      Missing whitespace after ','
      Open

                  for k,v in others:
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Each comma, semicolon or colon should be followed by whitespace.

      Okay: [a, b]
      Okay: (3,)
      Okay: a[1:4]
      Okay: a[:4]
      Okay: a[1:]
      Okay: a[1:4:2]
      E231: ['a','b']
      E231: foo(bar,baz)
      E231: [{'a':'b'}]

      At least two spaces before inline comment
      Open

                  self.mode = False # FIFO
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Separate inline comments by at least two spaces.

      An inline comment is a comment on the same line as a statement.
      Inline comments should be separated by at least two spaces from the
      statement. They should start with a # and a single space.
      
      Each line of a block comment starts with a # and a single space
      (unless it is indented text inside the comment).
      
      Okay: x = x + 1  # Increment x
      Okay: x = x + 1    # Increment x
      Okay: # Block comment
      E261: x = x + 1 # Increment x
      E262: x = x + 1  #Increment x
      E262: x = x + 1  #  Increment x
      E265: #Block comment
      E266: ### Block comment

      Missing whitespace after ','
      Open

              elif _PY_VERSION[:2] <= (3,2):
      Severity: Minor
      Found in bamnostic/utils.py by pep8

      Each comma, semicolon or colon should be followed by whitespace.

      Okay: [a, b]
      Okay: (3,)
      Okay: a[1:4]
      Okay: a[:4]
      Okay: a[1:]
      Okay: a[1:4:2]
      E231: ['a','b']
      E231: foo(bar,baz)
      E231: [{'a':'b'}]

      There are no issues that match your filters.

      Category
      Status