betteridiot/bamnostic

View on GitHub

Showing 165 of 167 total issues

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

        self.ref_indices = {ref: self.get_ref(ref, idx=True) for ref in range(self.n_refs)}
Severity: Minor
Found in bamnostic/bai.py and 1 other location - About 35 mins to fix
bamnostic/csi.py on lines 210..210

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 33.

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

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

    def get_ref(self, ref_id=None, idx=False):
        """Iteratively unpacks all the bins, linear intervals, and chunks for a given reference

        A reference is comprised of 2 things: 1) a series of bins that reference chunks of aligned
        reads that are grouped within that bin. 2) a series of virtual offsets of the first read of a
Severity: Minor
Found in bamnostic/csi.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

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

                if bin_id == self._UNMAP_BIN:
                    assert n_chunks == 2, 'Bin 3740 is supposed to have 2 chunks. This has {}'.format(n_chunks)
                    unmapped = Unmapped(*unpack_unmapped(self._io.read(32)))
                    self.unmapped[ref_id] = unmapped
                else:
Severity: Minor
Found in bamnostic/bai.py and 1 other location - About 30 mins to fix
bamnostic/csi.py on lines 275..281

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 32.

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

Avoid too many return statements within this function.
Open

                return data
Severity: Major
Found in bamnostic/bgzf.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                        return
    Severity: Major
    Found in bamnostic/bam.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                          return
      Severity: Major
      Found in bamnostic/bam.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return
        Severity: Major
        Found in bamnostic/bam.py - About 30 mins to fix

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

                          if bin_id == self._UNMAP_BIN:
                              assert n_chunks == 2, 'Bin 3740 is supposed to have 2 chunks. This has {}'.format(n_chunks)
                              unmapped = bai.Unmapped(*unpack_unmapped(self._io.read(32)))
                              self.unmapped[ref_id] = unmapped
                          else:
          Severity: Minor
          Found in bamnostic/csi.py and 1 other location - About 30 mins to fix
          bamnostic/bai.py on lines 303..309

          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 32.

          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

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

              def _qual_builder(self):
                  """Pulls out the quality information for the given read
          
                  Attributes:
                      query_qualities (:py:obj:`array.array`): Array of Phred quality scores for each base
          Severity: Minor
          Found in bamnostic/core.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 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 _check_sq has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _check_sq(self):
                  """ Inspect BAM file for @SQ entries within the header
          
                  The implementation of this check is for BAM files specifically. I inspects
                  the SAM header (if present) for the `@SQ` entires. However, if the SAM header
          Severity: Minor
          Found in bamnostic/bam.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

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

              def to_bam(bam_file):
                  """Writes the alignment record to a BAM file
          
                  Args:
                      bam_file (string or :py:obj:`bamnostic.bam.BamWriter`): BAM file path or open bam file in a write mode
          Severity: Minor
          Found in bamnostic/core.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, filename):
                  """Initialization method
          
                  Generates an "index" of the index. This gives us the byte positions of each chromosome
                  within the index file. Now, when a user queries over a specific chromosome, it pulls
          Severity: Minor
          Found in bamnostic/csi.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

          Trailing whitespace
          Open

                  super_args = {'filepath_or_object': locals()['filepath_or_object'], 
          Severity: Minor
          Found in bamnostic/bam.py by pep8

          Trailing whitespace is superfluous.

          The warning returned varies on whether the line itself is blank,
          for easier filtering for those who want to indent their blank lines.
          
          Okay: spam(1)\n#
          W291: spam(1) \n#
          W293: class Foo(object):\n    \n    bang = 12

          Continuation line under-indented for visual indent
          Open

                          copy_header = None, header = b'', reference_names = None, reference_lengths = None):
          Severity: Minor
          Found in bamnostic/bam.py by pep8

          Continuation lines indentation.

          Continuation lines should align wrapped elements either vertically
          using Python's implicit line joining inside parentheses, brackets
          and braces, or using a hanging indent.
          
          When using a hanging indent these considerations should be applied:
          - there should be no arguments on the first line, and
          - further indentation should be used to clearly distinguish itself
            as a continuation line.
          
          Okay: a = (\n)
          E123: a = (\n    )
          
          Okay: a = (\n    42)
          E121: a = (\n   42)
          E122: a = (\n42)
          E123: a = (\n    42\n    )
          E124: a = (24,\n     42\n)
          E125: if (\n    b):\n    pass
          E126: a = (\n        42)
          E127: a = (24,\n      42)
          E128: a = (24,\n    42)
          E129: if (a or\n    b):\n    pass
          E131: a = (\n    42\n 24)

          Unexpected spaces around keyword / parameter equals
          Open

                          copy_header = None, header = b'', reference_names = None, reference_lengths = None):
          Severity: Minor
          Found in bamnostic/bam.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):

          Unexpected spaces around keyword / parameter equals
          Open

                          super(BamWriter, self).__init__(filepath_or_object, mode=mode, compresslevel = compresslevel)
          Severity: Minor
          Found in bamnostic/bam.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):

          Continuation line under-indented for visual indent
          Open

                              'mode': locals()['mode'], 'max_cache': locals()['max_cache'],
          Severity: Minor
          Found in bamnostic/bam.py by pep8

          Continuation lines indentation.

          Continuation lines should align wrapped elements either vertically
          using Python's implicit line joining inside parentheses, brackets
          and braces, or using a hanging indent.
          
          When using a hanging indent these considerations should be applied:
          - there should be no arguments on the first line, and
          - further indentation should be used to clearly distinguish itself
            as a continuation line.
          
          Okay: a = (\n)
          E123: a = (\n    )
          
          Okay: a = (\n    42)
          E121: a = (\n   42)
          E122: a = (\n42)
          E123: a = (\n    42\n    )
          E124: a = (24,\n     42\n)
          E125: if (\n    b):\n    pass
          E126: a = (\n        42)
          E127: a = (24,\n      42)
          E128: a = (24,\n    42)
          E129: if (a or\n    b):\n    pass
          E131: a = (\n    42\n 24)

          Unexpected spaces around keyword / parameter equals
          Open

                  self.write_header(copy_header = copy_header, header = header, 
          Severity: Minor
          Found in bamnostic/bam.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):
          Severity
          Category
          Status
          Source
          Language