KarrLab/datanator_query_python

View on GitHub
datanator_query_python/query/full_text_search.py

Summary

Maintainability
D
2 days
Test Coverage
F
56%

File full_text_search.py has 376 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from karr_lab_aws_manager.elasticsearch_kl import query_builder as es_query_builder
import numpy as np
import math
import json
import requests
Severity: Minor
Found in datanator_query_python/query/full_text_search.py - About 5 hrs to fix

    Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, profile_name=None, credential_path=None,
    Severity: Major
    Found in datanator_query_python/query/full_text_search.py - About 1 hr to fix

      Function bool_query has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def bool_query(self, query_message, index, must=None, should=None, must_not=None, _filter=None, 
      Severity: Major
      Found in datanator_query_python/query/full_text_search.py - About 1 hr to fix

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

            def get_num_source(self, q, q_index, index, fields=['name', 'synonyms'], 
        Severity: Major
        Found in datanator_query_python/query/full_text_search.py - About 50 mins to fix

          Function get_num_source has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_num_source(self, q, q_index, index, fields=['name', 'synonyms'], 
                                  count=10, from_=0, batch_size=100):
                  """Extract a count number of source (ecmdb, ymdb, metabolite_meta, etc) index
                  from ftx search result
                  
          Severity: Minor
          Found in datanator_query_python/query/full_text_search.py - About 45 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_single_index_count has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def get_single_index_count(self, q, index, num, 
          Severity: Minor
          Found in datanator_query_python/query/full_text_search.py - About 45 mins to fix

            Function get_index_in_page has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_index_in_page(self, r, index):
                    """Get indices in current hits page
                    
                    Args:
                        r (:obj:`dict`): ftx search result
            Severity: Minor
            Found in datanator_query_python/query/full_text_search.py - About 45 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_index_ko_count has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def get_index_ko_count(self, q, num, agg_field="frontend_gene_aggregate", index='protein', **kwargs):
            Severity: Minor
            Found in datanator_query_python/query/full_text_search.py - About 35 mins to fix

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

                  def get_genes_ko_count(self, q, num, agg_field="ko_number", **kwargs):
                      """Get protein index with different ko_number field for up to num hits,
                      provided at least one of the proteins under ko_number has abundance info.
                      
                      Args:
              Severity: Minor
              Found in datanator_query_python/query/full_text_search.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_single_index_count has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_single_index_count(self, q, index, num, 
                                             excludes=[], includes=[],
                                             **kwargs):
                      """Get single index up to num hits
                      
              Severity: Minor
              Found in datanator_query_python/query/full_text_search.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 bucket_abundance in r['aggregations']['top_kos']['buckets']:
                          ko_abundance.add(bucket_abundance['top_ko']['hits']['hits'][0]['_source'][agg_field])
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 304..305

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

              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 bucket_all in r_all['top_kos']['buckets']:
                          ko_all.add(bucket_all['top_ko']['hits']['hits'][0]['_source'][agg_field])
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 301..302

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

              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 bucket_all in r_all['top_kos']['buckets']:
                          ko_all.add(bucket_all['top_ko']['hits']['hits'][0]['_source'].get(agg_field))
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 414..415

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

              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 bucket_abundance in r['aggregations']['top_kos']['buckets']:
                          ko_abundance.add(bucket_abundance['top_ko']['hits']['hits'][0]['_source'].get(agg_field))
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 417..418

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

              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 ko_str != None:
                              # s['top_ko']['hits']['hits'][0]['_source']['abundances'] = True
                              s['top_ko']['hits']['hits'][0]['_source'][agg_field] = [ko_str[i:i+6] for i in range(0, len(ko_str), 6)]
                          else:
                              # s['top_ko']['hits']['hits'][0]['_source']['abundances'] = False
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 423..428

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

              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 ko_str is None:
                          #     # s['top_ko']['hits']['hits'][0]['_source']['abundances'] = True
                          #     s['top_ko']['hits']['hits'][0]['_source'][agg_field] = [ko_str[i:i+6] for i in range(0, len(ko_str), 6)]
                          # else:
                              # s['top_ko']['hits']['hits'][0]['_source']['abundances'] = False
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 1 other location - About 1 hr to fix
              datanator_query_python/query/full_text_search.py on lines 310..315

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

              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

                  def __init__(self, profile_name=None, credential_path=None,
                              config_path=None, elastic_path=None,
                              cache_dir=None, service_name='es', max_entries=float('inf'), verbose=False):
                      super().__init__(profile_name=profile_name, credential_path=credential_path,
              Severity: Major
              Found in datanator_query_python/query/full_text_search.py and 3 other locations - About 40 mins to fix
              datanator_query_python/aggregate/tabu.py on lines 12..12
              datanator_query_python/query/query_metabolite_concentrations.py on lines 11..11
              datanator_query_python/query/query_rna_halflife.py on lines 10..10

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

              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