aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/correlation.py12
-rw-r--r--gn3/api/datasets.py8
-rw-r--r--gn3/api/traits.py7
-rw-r--r--gn3/computations/correlations.py15
-rw-r--r--tests/integration/test_correlation.py4
-rw-r--r--tests/integration/test_datasets.py6
-rw-r--r--tests/unit/computations/test_correlation.py73
-rw-r--r--tests/unit/computations/test_datasets.py55
-rw-r--r--tests/unit/computations/test_trait.py16
9 files changed, 105 insertions, 91 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 53ea6a7..e023cbe 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -15,9 +15,10 @@ correlation = Blueprint("correlation", __name__)
@correlation.route("/sample_r/<string:corr_method>", methods=["POST"])
def compute_sample_r(corr_method="pearson"):
- """correlation endpoint for computing sample r correlations\
+ """Correlation endpoint for computing sample r correlations\
api expects the trait data with has the trait and also the\
- target_dataset data"""
+ target_dataset data
+ """
correlation_input = request.get_json()
# xtodo move code below to compute_all_sampl correlation
@@ -35,9 +36,10 @@ def compute_sample_r(corr_method="pearson"):
@correlation.route("/lit_corr/<string:species>/<int:gene_id>", methods=["POST"])
def compute_lit_corr(species=None, gene_id=None):
- """api endpoint for doing lit correlation.results for lit correlation\
+ """Api endpoint for doing lit correlation.results for lit correlation\
are fetched from the database this is the only case where the db\
- might be needed for actual computing of the correlation results"""
+ might be needed for actual computing of the correlation results
+ """
database_instance = mock.Mock()
target_traits_gene_ids = request.get_json()
@@ -51,7 +53,7 @@ def compute_lit_corr(species=None, gene_id=None):
@correlation.route("/tissue_corr/<string:corr_method>", methods=["POST"])
def compute_tissue_corr(corr_method="pearson"):
- """api endpoint fr doing tissue correlation"""
+ """Api endpoint fr doing tissue correlation"""
tissue_input_data = request.get_json()
primary_tissue_dict = tissue_input_data["primary_tissue"]
target_tissues_dict_list = tissue_input_data["target_tissues"]
diff --git a/gn3/api/datasets.py b/gn3/api/datasets.py
index a6951fb..7f08de5 100644
--- a/gn3/api/datasets.py
+++ b/gn3/api/datasets.py
@@ -10,11 +10,10 @@ from gn3.experimental_db import database_connector
dataset = Blueprint("dataset", __name__)
-
@dataset.route("/create/<dataset_name>/")
@dataset.route("/create/<dataset_name>/<dataset_type>")
def create_dataset_api(dataset_name, dataset_type=None):
- """Test api/create/dataset/<dataset_name>/<dataset_type>"""
+ """Endpoint of creating dataset"""
new_dataset = create_dataset(
dataset_type=dataset_type, dataset_name=dataset_name)
@@ -27,9 +26,8 @@ def create_dataset_api(dataset_name, dataset_type=None):
@dataset.route("/fetch_traits_data/<dataset_name>/<dataset_type>")
def fetch_traits_data(dataset_name, dataset_type):
- """test fetch_traits_data/dataset_name/dataset_type"""
- # what actually brings speed issues in correlation
- # should fetch this
+ """Endpoint for fetching Trait data"""
+ # should fetch this(temp)
trait_sample_ids = [4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15,
17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31,
35, 36, 37, 39, 98, 99, 100, 103, 487, 105, 106, 110, 115,
diff --git a/gn3/api/traits.py b/gn3/api/traits.py
index cf445e1..0ac437d 100644
--- a/gn3/api/traits.py
+++ b/gn3/api/traits.py
@@ -12,11 +12,10 @@ from gn3.experimental_db import database_connector
trait = Blueprint("trait", __name__)
-
@trait.route("/<string:trait_name>/<string:dataset_name>")
def create_trait(trait_name, dataset_name):
- """/test:trait_name/dataset_name/type :retrieve sample\
- data for trait"""
+ """Endpoint for creating trait and fetching strain\
+ values"""
# xtodo replace the object at most this endpoint
# requires dataset_type,dataset_name ,dataset_id
@@ -38,7 +37,7 @@ def create_trait(trait_name, dataset_name):
@trait.route("/trait_info/<string:trait_name>", methods=["POST"])
def fetch_trait_info(trait_name):
- """api endpoint for fetching the trait info \
+ """Api endpoint for fetching the trait info \
expects the trait and trait dataset to have\
been created """
data = request.get_json()
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py
index dc2f8d3..7a6ff11 100644
--- a/gn3/computations/correlations.py
+++ b/gn3/computations/correlations.py
@@ -89,10 +89,9 @@ package :not packaged in guix
def filter_shared_sample_keys(this_samplelist,
target_samplelist) -> Tuple[List, List]:
- """Given primary and target samplelist for two base and target trait select
-filter the values using the shared keys
-
- """
+ """Given primary and target samplelist\
+ for two base and target trait select\
+ filter the values using the shared keys"""
this_vals = []
target_vals = []
for key, value in target_samplelist.items():
@@ -105,8 +104,9 @@ filter the values using the shared keys
def compute_all_sample_correlation(this_trait,
target_dataset,
corr_method="pearson") -> List:
- """Given a trait data samplelist and target__datasets compute all sample
-correlation"""
+ """Given a trait data samplelist and\
+ target__datasets compute all sample correlation
+ """
this_trait_samples = this_trait["trait_sample_data"]
@@ -269,7 +269,7 @@ def query_formatter(query_string: str, *query_values):
def map_to_mouse_gene_id(database, species: Optional[str],
gene_id: Optional[str]) -> Optional[str]:
- """given a species which is not mouse map the gene_id\
+ """Given a species which is not mouse map the gene_id\
to respective mouse gene id"""
# AK:xtodo move the code for checking nullity out of thing functions bug
# while method for string
@@ -296,7 +296,6 @@ def compute_all_lit_correlation(database_instance, trait_lists: List,
species: str, gene_id):
"""Function that acts as an abstraction for
lit_correlation_for_trait_list"""
- # xtodo to be refactored
lit_results = lit_correlation_for_trait_list(
database=database_instance,
diff --git a/tests/integration/test_correlation.py b/tests/integration/test_correlation.py
index 488a8a4..bc3f542 100644
--- a/tests/integration/test_correlation.py
+++ b/tests/integration/test_correlation.py
@@ -10,10 +10,6 @@ class CorrelationIntegrationTest(TestCase):
def setUp(self):
self.app = create_app().test_client()
- def test_fail(self):
- """initial method for class that fails"""
- self.assertEqual(2, 2)
-
@mock.patch("gn3.api.correlation.compute_all_sample_correlation")
def test_sample_r_correlation(self, mock_compute_samples):
"""Test /api/correlation/sample_r/{method}"""
diff --git a/tests/integration/test_datasets.py b/tests/integration/test_datasets.py
index 1d72234..34b7669 100644
--- a/tests/integration/test_datasets.py
+++ b/tests/integration/test_datasets.py
@@ -1,4 +1,4 @@
-"""this module contains integration tests for datasets"""
+"""This module contains integration tests for datasets"""
from unittest import TestCase
from unittest import mock
@@ -14,7 +14,7 @@ class DatasetIntegrationTests(TestCase):
@mock.patch("gn3.api.datasets.create_dataset")
def test_create_dataset(self, mock_dataset):
- """test for creating dataset object"""
+ """Test for creating dataset object"""
mock_dataset_creator = namedtuple(
'ProbeSet', ["dataset_name", "dataset_type"])
new_dataset = mock_dataset_creator("HC_M2_0606_P", "ProbeSet")
@@ -29,7 +29,7 @@ class DatasetIntegrationTests(TestCase):
@mock.patch("gn3.api.datasets.get_traits_data")
def test_fetch_traits_data(self, mock_get_trait_data):
- """test api/dataset/fetch_traits_data/d_name/d_type"""
+ """Test api/dataset/fetch_traits_data/d_name/d_type"""
mock_get_trait_data.return_value = {}
response = self.app.get(
diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py
index 84b9330..631dc18 100644
--- a/tests/unit/computations/test_correlation.py
+++ b/tests/unit/computations/test_correlation.py
@@ -1,4 +1,4 @@
-"""module contains the tests for correlation"""
+"""Module contains the tests for correlation"""
import unittest
from unittest import TestCase
from unittest import mock
@@ -80,10 +80,10 @@ class DataBase(QueryableMixin):
class TestCorrelation(TestCase):
- """class for testing correlation functions"""
+ """Class for testing correlation functions"""
def test_normalize_values(self):
- """function to test normalizing values """
+ """Function to test normalizing values """
results = normalize_values([2.3, None, None, 3.2, 4.1, 5],
[3.4, 7.2, 1.3, None, 6.2, 4.1])
@@ -92,7 +92,7 @@ class TestCorrelation(TestCase):
self.assertEqual(results, expected_results)
def test_bicor(self):
- """test for doing biweight mid correlation """
+ """Test for doing biweight mid correlation """
results = do_bicor(x_val=[1, 2, 3], y_val=[4, 5, 6])
@@ -102,8 +102,9 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.compute_corr_coeff_p_value")
@mock.patch("gn3.computations.correlations.normalize_values")
def test_compute_sample_r_correlation(self, norm_vals, compute_corr):
- """test for doing sample correlation gets the cor\
- and p value and rho value using pearson correlation"""
+ """Test for doing sample correlation gets the cor\
+ and p value and rho value using pearson correlation
+ """
primary_values = [2.3, 4.1, 5]
target_values = [3.4, 6.2, 4.1]
@@ -133,7 +134,7 @@ class TestCorrelation(TestCase):
spearman_results, tuple, "message")
def test_filter_shared_sample_keys(self):
- """function to tests shared key between two dicts"""
+ """Function to tests shared key between two dicts"""
this_samplelist = {
"C57BL/6J": "6.638",
@@ -162,7 +163,7 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.compute_sample_r_correlation")
@mock.patch("gn3.computations.correlations.filter_shared_sample_keys")
def test_compute_all_sample(self, filter_shared_samples, sample_r_corr):
- """given target dataset compute all sample r correlation"""
+ """Given target dataset compute all sample r correlation"""
filter_shared_samples.return_value = (["1.23", "6.565", "6.456"], [
"6.266", "6.565", "6.456"])
@@ -192,7 +193,6 @@ class TestCorrelation(TestCase):
sample_all_results = [{"1419792_at": {"corr_coeffient": -1.0,
"p_value": 0.9,
"num_overlap": 6}}]
- # ?corr_method: str, trait_vals, target_samples_vals
self.assertEqual(compute_all_sample_correlation(
this_trait=this_trait_data, target_dataset=traits_dataset), sample_all_results)
@@ -204,9 +204,10 @@ class TestCorrelation(TestCase):
@unittest.skip("not implemented")
def test_tissue_lit_corr_for_probe_type(self):
- """tests for doing tissue and lit correlation for trait list\
+ """Tests for doing tissue and lit correlation for trait list\
if both the dataset and target dataset are probeset runs\
- on after initial correlation has been done"""
+ on after initial correlation has been done
+ """
results = tissue_lit_corr_for_probe_type(
corr_type="tissue", top_corr_results={})
@@ -215,8 +216,9 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.compute_corr_coeff_p_value")
def test_tissue_correlation_for_trait_list(self, mock_compute_corr_coeff):
- """test given a primary tissue values for a trait and and a list of\
- target tissues for traits do the tissue correlation for them"""
+ """Test given a primary tissue values for a trait and and a list of\
+ target tissues for traits do the tissue correlation for them
+ """
primary_tissue_values = [1.1, 1.5, 2.3]
target_tissues_values = [1, 2, 3]
@@ -233,8 +235,9 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.fetch_lit_correlation_data")
@mock.patch("gn3.computations.correlations.map_to_mouse_gene_id")
def test_lit_correlation_for_trait_list(self, mock_mouse_gene_id, fetch_lit_data):
- """fetch results from db call for lit correlation given a trait list\
- after doing correlation"""
+ """Fetch results from db call for lit correlation given a trait list\
+ after doing correlation
+ """
target_trait_lists = [{"gene_id": 15},
{"gene_id": 17},
@@ -255,8 +258,9 @@ class TestCorrelation(TestCase):
self.assertEqual(lit_results, expected_results)
def test_fetch_lit_correlation_data(self):
- """test for fetching lit correlation data from\
- the database where the input and mouse geneid are none"""
+ """Test for fetching lit correlation data from\
+ the database where the input and mouse geneid are none
+ """
database_instance = DataBase()
results = fetch_lit_correlation_data(database=database_instance,
@@ -267,8 +271,9 @@ class TestCorrelation(TestCase):
self.assertEqual(results, ("1", 0))
def test_fetch_lit_correlation_data_db_query(self):
- """test for fetching lit corr coefficent givent the input\
- input trait mouse gene id and mouse gene id"""
+ """Test for fetching lit corr coefficent givent the input\
+ input trait mouse gene id and mouse gene id
+ """
database_instance = DataBase()
expected_results = ("1", 0.1)
@@ -281,8 +286,9 @@ class TestCorrelation(TestCase):
self.assertEqual(expected_results, lit_results)
def test_query_lit_correlation_for_db_empty(self):
- """test that corr coeffient returned is 0 given the\
- db value if corr coefficient is empty"""
+ """Test that corr coeffient returned is 0 given the\
+ db value if corr coefficient is empty
+ """
database_instance = mock.Mock()
database_instance.execute.return_value.fetchone.return_value = None
@@ -294,8 +300,9 @@ class TestCorrelation(TestCase):
self.assertEqual(lit_results, ("16", 0))
def test_query_formatter(self):
- """test for formatting a query given the query string and also the\
- values"""
+ """Test for formatting a query given the query string and also the\
+ values
+ """
query = """
SELECT VALUE
FROM LCorr
@@ -320,16 +327,18 @@ class TestCorrelation(TestCase):
self.assertEqual(formatted_query, expected_formatted_query)
def test_query_formatter_no_query_values(self):
- """test for formatting a query where there are no\
- string placeholder"""
+ """Test for formatting a query where there are no\
+ string placeholder
+ """
query = """SELECT * FROM USERS"""
formatted_query = query_formatter(query)
self.assertEqual(formatted_query, query)
def test_map_to_mouse_gene_id(self):
- """test for converting a gene id to mouse geneid\
- given a species which is not mouse"""
+ """Test for converting a gene id to mouse geneid\
+ given a species which is not mouse
+ """
database_instance = mock.Mock()
test_data = [("Human", 14), (None, 9), ("Mouse", 15), ("Rat", 14)]
@@ -349,9 +358,10 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.lit_correlation_for_trait_list")
def test_compute_all_lit_correlation(self, mock_lit_corr):
- """test for compute all lit correlation which acts\
+ """Test for compute all lit correlation which acts\
as an abstraction for lit_correlation_for_trait_list
- and is used in the api/correlation/lit"""
+ and is used in the api/correlation/lit
+ """
database = mock.Mock()
@@ -372,8 +382,9 @@ class TestCorrelation(TestCase):
@mock.patch("gn3.computations.correlations.tissue_correlation_for_trait_list")
def test_compute_all_tissue_correlation(self, mock_tissue_corr):
- """test for compute all tissue corelation which abstracts
- api calling the tissue_correlation for trait_list"""
+ """Test for compute all tissue corelation which abstracts
+ api calling the tissue_correlation for trait_list
+ """
primary_tissue_dict = {"trait_id": "1419792_at",
"tissue_values": [1, 2, 3, 4, 5]}
diff --git a/tests/unit/computations/test_datasets.py b/tests/unit/computations/test_datasets.py
index 44ff527..f9e9c2b 100644
--- a/tests/unit/computations/test_datasets.py
+++ b/tests/unit/computations/test_datasets.py
@@ -1,4 +1,4 @@
-"""module contains tests from datasets"""
+"""Module contains tests from datasets"""
import json
from unittest import TestCase
@@ -19,12 +19,13 @@ from gn3.computations.datasets import get_traits_data
class TestDatasets(TestCase):
- """class contains tests for datasets"""
+ """Class contains tests for datasets"""
@mock.patch("gn3.computations.datasets.fetch_from_db_sample_data")
def test_retrieve_trait_sample_data(self, mock_fetch_sample_results):
- """test retrieving sample data\
- for trait from the dataset"""
+ """Test retrieving sample data\
+ for trait from the dataset
+ """
trait_name = "1419792_at"
dataset_id = "HC_M2_0606_P&"
dataset_type = "Publish"
@@ -47,7 +48,7 @@ class TestDatasets(TestCase):
self.assertEqual(results, fetch_results)
def test_query_for_dataset_sample(self):
- """test for getting query for sample data"""
+ """Test for getting query for sample data"""
no_results = get_query_for_dataset_sample("does not exists")
@@ -57,8 +58,9 @@ class TestDatasets(TestCase):
self.assertIsInstance(query_exists, str)
def test_fetch_from_db_sample_data(self):
- """test for function that fetches sample\
- results from the database"""
+ """Test for function that fetches sample\
+ results from the database
+ """
database_results = [('BXD31', 8.001, None, None, 'BXD31'),
('BXD32', 7.884, None, None, 'BXD32'),
@@ -91,9 +93,10 @@ class TestDatasets(TestCase):
@mock.patch("gn3.computations.datasets.dataset_creator_store")
@mock.patch("gn3.computations.datasets.dataset_type_getter")
def test_create_dataset(self, mock_dataset_type, mock_store):
- """test function that creates/fetches required dataset\
+ """Test function that creates/fetches required dataset\
can either be published phenotype,genotype,Microarray or\
- user defined ->Temp"""
+ user defined ->Temp
+ """
probe_name = "HC_M2_0606_P"
probe_type = "ProbeSet"
@@ -109,28 +112,31 @@ class TestDatasets(TestCase):
self.assertEqual(dataset.dataset_type, probe_type)
def test_dataset_creator_store(self):
- """test for functions that actual
+ """Test for functions that actual
function to create differerent \
- datasets"""
+ datasets
+ """
results = dataset_creator_store("ProbeSet")
self.assertTrue(results)
def test_dataset_type_getter(self):
- """test for fetching type of dataset given\
- the dataset name"""
+ """Test for fetching type of dataset given\
+ the dataset name
+ """
redis_instance = mock.Mock()
- # found in redis
+ # fetched in redis
redis_instance.get.return_value = "ProbeSet"
results = dataset_type_getter("HC_M2_0_P", redis_instance)
self.assertEqual(results, "ProbeSet")
@mock.patch("gn3.computations.datasets.requests")
def test_fetch_dataset_type_from_gn2_api(self, mock_request):
- """test for function that test fetching\
+ """Test for function that test fetching\
all datasets from gn2 api in order to store\
- in redis"""
+ in redis
+ """
expected_json_results = {"datasets": {
"arabidopsis": {
@@ -164,8 +170,9 @@ class TestDatasets(TestCase):
self.assertEqual(expected_results, results)
def test_fetch_dataset_sample_id(self):
- """get from the database the sample\
- id if only in the samplelists"""
+ """Get from the database the sample\
+ id if only in the samplelists
+ """
expected_results = {"B6D2F1": 1, "BXD1": 4, "BXD11": 10,
"BXD12": 11, "BXD13": 12, "BXD15": 14, "BXD16": 15}
@@ -187,10 +194,9 @@ class TestDatasets(TestCase):
@mock.patch("gn3.computations.datasets.fetch_from_db_sample_data")
@mock.patch("gn3.computations.datasets.divide_into_chunks")
def test_get_traits_data(self, mock_divide_into_chunks, mock_fetch_samples):
- """test for for function to get data\
- of traits in dataset"""
- # xtodo more tests needed for this
-
+ """Test for for function to get data\
+ of traits in dataset
+ """
_expected_results = {'AT_DSAFDS': [
12, 14, 13, 23, 12, 14, 13, 23, 12, 14, 13, 23]}
database = mock.Mock()
@@ -203,8 +209,9 @@ class TestDatasets(TestCase):
self.assertEqual({}, dict(results))
def test_divide_into_chunks(self):
- """test for dividing a list into given number of\
- chunks for example"""
+ """Test for dividing a list into given number of\
+ chunks for example
+ """
results = divide_into_chunks([1, 2, 7, 3, 22, 8, 5, 22, 333], 3)
expected_results = [[1, 2, 7], [3, 22, 8], [5, 22, 333]]
diff --git a/tests/unit/computations/test_trait.py b/tests/unit/computations/test_trait.py
index cdd8078..feb97c6 100644
--- a/tests/unit/computations/test_trait.py
+++ b/tests/unit/computations/test_trait.py
@@ -1,4 +1,4 @@
-"""module contains tests for creating traits"""
+"""Module contains tests for creating traits"""
from unittest import TestCase
from unittest import mock
@@ -8,11 +8,11 @@ from gn3.computations.traits import get_trait_info_data
class TestTrait(TestCase):
- """class contains tests for creating traits"""
+ """Class contains tests for creating traits"""
@mock.patch("gn3.computations.traits.get_trait_sample_data")
def test_fetch_trait(self, get_sample_data):
- """test for creating/fetching trait"""
+ """Test for creating/fetching trait"""
expected_sample_data = {
"A/Y": 12.3,
@@ -37,8 +37,9 @@ class TestTrait(TestCase):
@mock.patch("gn3.computations.traits.retrieve_trait_sample_data")
def test_get_trait_sample_data(self, mock_retrieve_sample_data):
- """test for getting sample data from either\
- the trait's dataset or form redis"""
+ """Test for getting sample data from either\
+ the trait's dataset or form redis
+ """
trait_dataset = mock.Mock()
dataset_trait_sample_data = [
@@ -65,8 +66,9 @@ class TestTrait(TestCase):
self.assertEqual(results, expected_results)
def test_get_trait_info_data(self):
- """test for getting info data related\
- to trait"""
+ """Test for getting info data related\
+ to trait
+ """
results = get_trait_info_data(
trait_name="AXSF_AT", trait_dataset=mock.Mock(), database_instance=None)