KarrLab/datanator_query_python

View on GitHub
datanator_query_python/query/query_sabiork_old.py

Summary

Maintainability
F
1 wk
Test Coverage
C
79%

File query_sabiork_old.py has 379 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from datanator_query_python.util import mongo_util, chem_util, file_util
from datanator_query_python.aggregate import lookups
from pymongo.collation import Collation, CollationStrength
from . import query_taxon_tree, query_sabio_compound
import json
Severity: Minor
Found in datanator_query_python/query/query_sabiork_old.py - About 5 hrs to fix

    Function get_kinlaw_by_rxn_ortho has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_kinlaw_by_rxn_ortho(self, substrates, products, dof=0,
                              projection={'kinlaw_id': 1, '_id': 0, "enzymes": 1},
                              bound='loose', skip=0, limit=0):
            ''' Find the kinlaw_id defined in sabio_rk using 
                rxn participants' inchikey
    Severity: Minor
    Found in datanator_query_python/query/query_sabiork_old.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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, cache_dirname=None, MongoDB=None, replicaSet=None, db='datanator',
    Severity: Major
    Found in datanator_query_python/query/query_sabiork_old.py - About 1 hr to fix

      Function get_info_by_entryid has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_info_by_entryid(self, entry_id, target_organism=None, size=10, last_id=0):
              """Find reactions by sabio entry id, return all information
              
              Args:
                  entry_id (:obj:`int`): entry_id
      Severity: Minor
      Found in datanator_query_python/query/query_sabiork_old.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_kinlaw_by_environment has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_kinlaw_by_environment(self, taxon=None, taxon_wildtype=None, ph_range=None, temp_range=None,
      Severity: Major
      Found in datanator_query_python/query/query_sabiork_old.py - About 50 mins to fix

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

            def get_kinlaw_by_rxn(self, substrates, products, dof=0,
        Severity: Major
        Found in datanator_query_python/query/query_sabiork_old.py - About 50 mins to fix

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

              def get_kinlaw_by_rxn_ortho(self, substrates, products, dof=0,
          Severity: Major
          Found in datanator_query_python/query/query_sabiork_old.py - About 50 mins to fix

            Function get_kinlaw_by_rxn_name has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def get_kinlaw_by_rxn_name(self, substrates, products,
            Severity: Minor
            Found in datanator_query_python/query/query_sabiork_old.py - About 45 mins to fix

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

                  def get_kinlaw_by_rxn(self, substrates, products, dof=0,
                                        projection={'kinlaw_id': 1, '_id': 0},
                                        bound='loose', skip=0, limit=0):
                      ''' Find the kinlaw_id defined in sabio_rk using 
                          rxn participants' inchikey
              Severity: Minor
              Found in datanator_query_python/query/query_sabiork_old.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 get_reaction_by_subunit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_reaction_by_subunit(self, _ids):
                      """Get reactions by enzyme subunit uniprot IDs
                      
                      Args:
                          _ids (:obj:`list` of :obj:`str`): List of uniprot IDs.
              Severity: Minor
              Found in datanator_query_python/query/query_sabiork_old.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 get_kinlaw_by_environment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_kinlaw_by_environment(self, taxon=None, taxon_wildtype=None, ph_range=None, temp_range=None,
                                        name_space=None, param_type=None, projection={'_id': 0}):
                      """get kinlaw info based on experimental conditions
                      
                      Args:
              Severity: Minor
              Found in datanator_query_python/query/query_sabiork_old.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 get_kinlawid_by_rxn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_kinlawid_by_rxn(self, substrates, products, dof=0):
                      ''' Find the kinlaw_id defined in sabio_rk using 
                          rxn participants' inchikey
              
                          Args:
              Severity: Minor
              Found in datanator_query_python/query/query_sabiork_old.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 4 locations. Consider refactoring.
              Open

                      if dof == 0:
                          substrates = substrates
                          products = products
                      elif dof == 1:
                          substrates = [re.compile('^' + x[:-2]) for x in substrates]
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 3 other locations - About 1 day to fix
              datanator_query_python/query/query_sabio_reaction_entries.py on lines 41..49
              datanator_query_python/query/query_sabiork_old.py on lines 110..118
              datanator_query_python/query/query_sabiork_old.py on lines 195..203

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

              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 4 locations. Consider refactoring.
              Open

                      if dof == 0:
                          substrates = substrates
                          products = products
                      elif dof == 1:
                          substrates = [re.compile('^' + x[:-2]) for x in substrates]
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 3 other locations - About 1 day to fix
              datanator_query_python/query/query_sabio_reaction_entries.py on lines 41..49
              datanator_query_python/query/query_sabiork_old.py on lines 110..118
              datanator_query_python/query/query_sabiork_old.py on lines 148..156

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

              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 4 locations. Consider refactoring.
              Open

                      if dof == 0:
                          substrates = substrates
                          products = products
                      elif dof == 1:
                          substrates = [re.compile('^' + x[:-2]) for x in substrates]
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 3 other locations - About 1 day to fix
              datanator_query_python/query/query_sabio_reaction_entries.py on lines 41..49
              datanator_query_python/query/query_sabiork_old.py on lines 148..156
              datanator_query_python/query/query_sabiork_old.py on lines 195..203

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

              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

                      if bound == 'loose':
                          constraint_0 = {substrate: {'$all': substrates}}
                          constraint_1 = {product: {'$all': products}}
                          constraint_2 = {"taxon_id": {"$ne": None}}
                      else:
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 1 other location - About 4 hrs to fix
              datanator_query_python/query/query_sabiork_old.py on lines 158..165

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

              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

                      if bound == 'loose':
                          constraint_0 = {substrate: {'$all': substrates}}
                          constraint_1 = {product: {'$all': products}}
                          constraint_2 = {"taxon_id": {"$ne": None}}
                      else:
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 1 other location - About 4 hrs to fix
              datanator_query_python/query/query_sabiork_old.py on lines 205..212

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

              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

                      if limit > 0:
                          pipeline = [{"$match": query}, {"$limit": limit}, {"$skip": skip}, lookup, {"$project": projection}]
                      else:
                          pipeline = [{"$match": query}, {"$skip": skip}, lookup, {"$project": projection}]
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 1 other location - About 2 hrs to fix
              datanator_query_python/query/query_sabiork_old.py on lines 168..171

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

              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

                      if limit > 0:
                          pipeline = [{"$match": query}, {"$limit": limit}, {"$skip": skip}, lookup, {"$project": projection}]
                      else:
                          pipeline = [{"$match": query}, {"$skip": skip}, lookup, {"$project": projection}]
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 1 other location - About 2 hrs to fix
              datanator_query_python/query/query_sabiork_old.py on lines 344..347

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

              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 5 locations. Consider refactoring.
              Open

                      super().__init__(cache_dirname=cache_dirname, MongoDB=MongoDB,
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 4 other locations - About 1 hr to fix
              datanator_query_python/query/query_metabolites.py on lines 21..21
              datanator_query_python/query/query_metabolites_meta.py on lines 15..15
              datanator_query_python/query/query_sabio_reaction_entries.py on lines 15..15
              datanator_query_python/query/query_taxon_tree.py on lines 18..18

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

              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 4 locations. Consider refactoring.
              Open

                      if temp_range:
                          all_constraints.append({'temperature': {'$gte': temp_range[0], '$lte': temp_range[1]}})
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 3 other locations - About 45 mins to fix
              datanator_query_python/query/query_sabiork.py on lines 247..248
              datanator_query_python/query/query_sabiork.py on lines 249..250
              datanator_query_python/query/query_sabiork_old.py on lines 60..61

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

              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 4 locations. Consider refactoring.
              Open

                      if ph_range:
                          all_constraints.append({'ph': {'$gte': ph_range[0], '$lte': ph_range[1]}})
              Severity: Major
              Found in datanator_query_python/query/query_sabiork_old.py and 3 other locations - About 45 mins to fix
              datanator_query_python/query/query_sabiork.py on lines 247..248
              datanator_query_python/query/query_sabiork.py on lines 249..250
              datanator_query_python/query/query_sabiork_old.py on lines 62..63

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

              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