NationalGenomicsInfrastructure/ngi_pipeline

View on GitHub
ngi_pipeline/engines/piper_ngi/utils.py

Summary

Maintainability
F
3 days
Test Coverage

File utils.py has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import collections
import datetime
import fnmatch
import glob
import os
Severity: Minor
Found in ngi_pipeline/engines/piper_ngi/utils.py - About 5 hrs to fix

    Function get_valid_seqruns_for_sample has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_valid_seqruns_for_sample(project_id, sample_id,
                                     include_failed_libpreps=False,
                                     include_done_seqruns=False,
                                     status_field="alignment_status"):
        """Find all the valid seqruns for a particular sample.
    Severity: Minor
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 2 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 remove_previous_genotype_analyses has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_previous_genotype_analyses(project_obj):
        """Remove genotype concordance analysis results for a sample, including
        .failed and .done files.
        Doesn't throw an error if it can't read a directory, but does if it can't
        delete a file it knows about.
    Severity: Minor
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 1 hr 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 get_finished_seqruns_for_sample has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_finished_seqruns_for_sample(project_id, sample_id,
                                        include_failed_libpreps=False):
        """Find all the finished seqruns for a particular sample.
    
        :param str project_id: The id of the project
    Severity: Minor
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 1 hr 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 remove_previous_sample_analyses has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_previous_sample_analyses(project_obj, sample_obj=None):
        """Remove analysis results for a sample, including .failed and .done files.
        Doesn't throw an error if it can't read a directory, but does if it can't
        delete a file it knows about.
    
    
    Severity: Minor
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 1 hr 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_for_preexisting_sample_runs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def check_for_preexisting_sample_runs(project_obj, sample_obj,
                                          restart_running_jobs, restart_finished_jobs,
                                          status_field="alignment_status"):
        """If any analysis is undergoing or has completed for this sample's
        seqruns, raise a RuntimeError.
    Severity: Minor
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 1 hr 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 _create_generic_output_file_path has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _create_generic_output_file_path(workflow_subtask, project_base_path, project_name, project_id,
    Severity: Major
    Found in ngi_pipeline/engines/piper_ngi/utils.py - About 50 mins to fix

      Function create_exit_code_file_path has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def create_exit_code_file_path(workflow_subtask, project_base_path, project_name, project_id,
      Severity: Major
      Found in ngi_pipeline/engines/piper_ngi/utils.py - About 50 mins to fix

        Function create_sbatch_header has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def create_sbatch_header(slurm_project_id, slurm_queue, num_cores, slurm_time,
        Severity: Major
        Found in ngi_pipeline/engines/piper_ngi/utils.py - About 50 mins to fix

          Function create_log_file_path has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def create_log_file_path(workflow_subtask, project_base_path, project_name,
          Severity: Major
          Found in ngi_pipeline/engines/piper_ngi/utils.py - About 50 mins to fix

            Function check_for_preexisting_sample_runs has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def check_for_preexisting_sample_runs(project_obj, sample_obj,
            Severity: Minor
            Found in ngi_pipeline/engines/piper_ngi/utils.py - About 35 mins to fix

              Function get_valid_seqruns_for_sample has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def get_valid_seqruns_for_sample(project_id, sample_id,
              Severity: Minor
              Found in ngi_pipeline/engines/piper_ngi/utils.py - About 35 mins to fix

                Function create_project_obj_from_analysis_log has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                def create_project_obj_from_analysis_log(project_name, project_id,
                Severity: Minor
                Found in ngi_pipeline/engines/piper_ngi/utils.py - About 35 mins to fix

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

                  def record_analysis_details(project, job_identifier):
                      """Write a yaml file enumerating exactly which fastq files we've started
                      analyzing.
                      """
                      output_file_path = os.path.join(project.base_path, "ANALYSIS",
                  Severity: Minor
                  Found in ngi_pipeline/engines/piper_ngi/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 _create_generic_output_file_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def _create_generic_output_file_path(workflow_subtask, project_base_path, project_name, project_id,
                                                       sample_id=None, libprep_id=None, seqrun_id=None):
                      base_path = os.path.join(project_base_path, "ANALYSIS", project_id, "piper_ngi","logs")
                      file_name = project_id
                      if sample_id:
                  Severity: Minor
                  Found in ngi_pipeline/engines/piper_ngi/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 rotate_previous_analysis has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def rotate_previous_analysis(project_obj):
                      """Rotates the files from the existing analysis starting at 03_merged_aligments"""
                      project_dir_path = os.path.join(project_obj.base_path, "ANALYSIS",
                                                      project_obj.project_id, "piper_ngi")
                      #analysis_move = glob.glob(os.path.join(project_dir_path, '0[3-9]_*'))
                  Severity: Minor
                  Found in ngi_pipeline/engines/piper_ngi/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 launch_piper_job has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def launch_piper_job(command_line, project, log_file_path=None):
                      """Launch the Piper command line.
                  
                      :param str command_line: The command line to execute
                      :param Project project: The Project object (needed to set the CWD)
                  Severity: Minor
                  Found in ngi_pipeline/engines/piper_ngi/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

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

                          for sample_file in sample_files:
                              LOG.debug("Deleting file {}".format(sample_file))
                              try:
                                  if os.path.isdir(sample_file):
                                      shutil.rmtree(sample_file)
                  Severity: Major
                  Found in ngi_pipeline/engines/piper_ngi/utils.py and 1 other location - About 4 hrs to fix
                  ngi_pipeline/engines/piper_ngi/utils.py on lines 140..148

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

                  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

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

                          for sample_file in sample_files:
                              LOG.info("Deleting file {}".format(sample_file))
                              try:
                                  if os.path.isdir(sample_file):
                                      shutil.rmtree(sample_file)
                  Severity: Major
                  Found in ngi_pipeline/engines/piper_ngi/utils.py and 1 other location - About 4 hrs to fix
                  ngi_pipeline/engines/piper_ngi/utils.py on lines 109..117

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

                  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

                  There are no issues that match your filters.

                  Category
                  Status