justaddcoffee/kg-emerging-viruses

View on GitHub
kg_covid_19/transform_utils/pharmgkb/pharmgkb.py

Summary

Maintainability
D
1 day
Test Coverage
F
54%

File pharmgkb.py has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Transform for PharmGKB drug to drug target data."""

import logging
import os
import re
Severity: Minor
Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 4 hrs to fix

    Function run has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def run(self, data_file: Optional[str] = None):
            """Run the transformation."""
            rel_zip_file_name = os.path.join(self.input_base_dir, "relationships.zip")
            relationship_file_name = "relationships.tsv"
            gene_mapping_zip_file = os.path.join(self.input_base_dir, "pharmgkb_genes.zip")
    Severity: Minor
    Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.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 make_preferred_drug_id has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def make_preferred_drug_id(
            self,
            pharmgkb_id: str,
            drug_id_map: dict,
            preferred_ids: dict,
    Severity: Minor
    Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.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 make_id_mapping_file has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def make_id_mapping_file(
            self,
            map_file: str,
            sep: str = "\t",
            pharmgkb_id_col: str = "PharmGKB Accession Id",
    Severity: Minor
    Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.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 make_id_mapping_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def make_id_mapping_file(
    Severity: Minor
    Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if entity_type == "Gene":
                                  self.make_pharmgkb_gene_node(
                                      fh=node,
                                      this_id=entity_id,
                                      name=entity_name,
      Severity: Major
      Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if not item:
                                    continue  # not xrefs, skip
                                item = item.strip('"')  # remove quotes around each item
        Severity: Major
        Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if self.key_parsed_ids not in dat:
                                      dat[self.key_parsed_ids] = dict()
                                  dat[self.key_parsed_ids][key] = value
          Severity: Major
          Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 45 mins to fix

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

                def make_pharmgkb_chemical_node(
            Severity: Minor
            Found in kg_covid_19/transform_utils/pharmgkb/pharmgkb.py - About 35 mins to fix

              There are no issues that match your filters.

              Category
              Status