genome/dgi-db

View on GitHub
lib/genome/updaters/get_drugbank.py

Summary

Maintainability
F
3 days
Test Coverage

Function parse has a Cognitive Complexity of 111 (exceeds 5 allowed). Consider refactoring.
Open

    def parse(self):
        print('Parsing Entrez...')
        symbol_to_info = dict()
        hgnc_id_to_info = dict()
        entrez_to_info = dict()
Severity: Minor
Found in lib/genome/updaters/get_drugbank.py - About 2 days 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 write has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def write(self):
        print('Writing to .tsv...')
        i = 0
        no_ensembl = no_entrez = total = 0
        header = ('count', 'drug_id', 'drug_name', 'drug_synonyms', 'drug_cas_number', 'drug_brands',
Severity: Minor
Found in lib/genome/updaters/get_drugbank.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

File get_drugbank.py has 257 lines of code (exceeds 250 allowed). Consider refactoring.
Open

__author__ = 'Kelsy C Cotto'

import zipfile
import os
import sys
Severity: Minor
Found in lib/genome/updaters/get_drugbank.py - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                            if isinstance(datum, tuple):
                                datum = ';'.join(str(x) for x in datum)
                            datum = str(datum).replace("\t", '')
    Severity: Major
    Found in lib/genome/updaters/get_drugbank.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if identifier.find('entry:resource',ns).text == 'HUGO Gene Nomenclature Committee (HGNC)':
                                  hgnc_gene_acc = identifier.find('entry:identifier', ns).text
                                  # Some identifiers are incorrectly labeled by DrugBank
                                  r = re.compile(r'^\d+$')
                                  if hgnc_gene_acc.startswith('GNC:'):
      Severity: Major
      Found in lib/genome/updaters/get_drugbank.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if not datum or datum == 'None':
                                    datum = 'N/A'
                                out.append(datum)
        Severity: Major
        Found in lib/genome/updaters/get_drugbank.py - About 45 mins to fix

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

              def download_file(self, url, local_filename):
                  # NOTE the stream=True parameter
                  r = requests.get(url, stream=True, allow_redirects=True, auth=HTTPBasicAuth(self.username, self.password))
                  with open(local_filename, 'wb') as f:
                      for chunk in r.iter_content(chunk_size=1024):
          Severity: Major
          Found in lib/genome/updaters/get_drugbank.py and 1 other location - About 4 hrs to fix
          lib/genome/updaters/get_entrez.py on lines 37..43

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

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

              def update(self):
                  if not self.is_current():
                      self.download_files()
                      self.parse()
                      self.write()
          Severity: Major
          Found in lib/genome/updaters/get_drugbank.py and 1 other location - About 1 hr to fix
          lib/genome/updaters/get_entrez.py on lines 123..127

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

          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