aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/datasets.py20
-rw-r--r--gn3/api/traits.py27
-rw-r--r--gn3/computations/datasets.py7
-rw-r--r--gn3/computations/traits.py8
-rw-r--r--tests/integration/test_traits.py8
-rw-r--r--tests/unit/computations/test_datasets.py4
-rw-r--r--tests/unit/computations/test_trait.py12
7 files changed, 56 insertions, 30 deletions
diff --git a/gn3/api/datasets.py b/gn3/api/datasets.py
index 70ee3a1..eb4097d 100644
--- a/gn3/api/datasets.py
+++ b/gn3/api/datasets.py
@@ -32,19 +32,19 @@ 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):
- """endpoints fetches sample for each trait in\
- a dataset"""
+ """test fetch_traits_data/dataset_name/dataset_type"""
# what actually brings speed issues in correlation
- 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,
- 116, 117, 118, 119, 120, 919, 147,
- 121, 40, 41, 124, 125, 128, 135, 129, 130, 131,
- 132, 134, 138, 139, 140, 141, 142, 144,
- 145, 148, 149, 920, 922, 2, 3, 1, 1100]
+ # should fetch this
+ 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,
+ 116, 117, 118, 119, 120, 919, 147,
+ 121, 40, 41, 124, 125, 128, 135, 129, 130, 131,
+ 132, 134, 138, 139, 140, 141, 142, 144,
+ 145, 148, 149, 920, 922, 2, 3, 1, 1100]
conn, _cursor = database_connector()
- results = get_traits_data(sample_ids=sample_ids, database_instance=conn,
+ results = get_traits_data(sample_ids=trait_sample_ids, database_instance=conn,
dataset_name=dataset_name, dataset_type=dataset_type)
conn.close()
diff --git a/gn3/api/traits.py b/gn3/api/traits.py
index a9ff906..758dcca 100644
--- a/gn3/api/traits.py
+++ b/gn3/api/traits.py
@@ -7,6 +7,8 @@ from flask import request
from gn3.computations.traits import fetch_trait
from gn3.computations.traits import get_trait_info_data
+from gn3.experimental_db import database_connector
+
trait = Blueprint("trait", __name__)
@@ -18,14 +20,23 @@ def home():
@trait.route("/<string:trait_name>/<string:dataset_name>")
def create_trait(trait_name, dataset_name):
- """endpoints for creating trait first should\
- call the endpoint for creating the trait only\
- also acts as endpoints for fetching trait data"""
-
- trait_dataset = mock.Mock() # xtodo should replace this with calling epoints
- trait_dataset.name = dataset_name
-
- trait_results = fetch_trait(dataset=trait_dataset, trait_name=trait_name)
+ """/test:trait_name/dataset_name/type :retrieve sample\
+ data for trait"""
+
+ # xtodo replace the object at most this endpoint
+ # requires dataset_type,dataset_name ,dataset_id
+ trait_dataset = {
+ "name": dataset_name,
+ "id": 12,
+ "type": "ProbeSet" # temp values
+ }
+ conn, _cursor = database_connector()
+
+ trait_results = fetch_trait(dataset=trait_dataset,
+ trait_name=trait_name,
+ database=conn)
+
+ conn.close()
return jsonify(trait_results)
diff --git a/gn3/computations/datasets.py b/gn3/computations/datasets.py
index b405e55..3664e4a 100644
--- a/gn3/computations/datasets.py
+++ b/gn3/computations/datasets.py
@@ -1,6 +1,5 @@
"""module contains the code all related to datasets"""
import json
-from unittest import mock
from math import ceil
from collections import defaultdict
@@ -16,7 +15,8 @@ from gn3.settings import GN2_BASE_URL
def retrieve_trait_sample_data(dataset,
trait_name: str,
- group_species_id=None,) -> List:
+ database,
+ group_species_id=None) -> List:
"""given the dataset id and trait_name fetch the\
sample_name,value from the dataset"""
@@ -35,7 +35,8 @@ def retrieve_trait_sample_data(dataset,
if dataset_query:
formatted_query = dataset_query % sample_query_values[dataset_type]
- results = fetch_from_db_sample_data(formatted_query, mock.Mock())
+
+ results = fetch_from_db_sample_data(formatted_query, database)
return results
diff --git a/gn3/computations/traits.py b/gn3/computations/traits.py
index bbb3073..38072ed 100644
--- a/gn3/computations/traits.py
+++ b/gn3/computations/traits.py
@@ -7,7 +7,7 @@ def compute_sum(rhs_val: int, lhs_val: int) -> int:
return rhs_val + lhs_val
-def fetch_trait(dataset, trait_name: str) -> dict:
+def fetch_trait(dataset, trait_name: str, database) -> dict:
"""this method creates a trait by\
fetching required data given the\
dataset and trait_name"""
@@ -17,20 +17,20 @@ def fetch_trait(dataset, trait_name: str) -> dict:
"trait_name": trait_name
}
- trait_data = get_trait_sample_data(dataset, trait_name)
+ trait_data = get_trait_sample_data(dataset, trait_name, database)
created_trait["trait_data"] = trait_data
return created_trait
-def get_trait_sample_data(trait_dataset, trait_name) -> dict:
+def get_trait_sample_data(trait_dataset, trait_name, database) -> dict:
"""first try to fetch the traits sample data from redis if that\
try to fetch from the traits dataset redis is only used for\
temp dataset type which is not used in this case """
sample_results = retrieve_trait_sample_data(
- trait_dataset.id, trait_dataset.type, trait_name)
+ trait_dataset, trait_name, database)
trait_data = {}
diff --git a/tests/integration/test_traits.py b/tests/integration/test_traits.py
index 2f3433a..7cf0a9f 100644
--- a/tests/integration/test_traits.py
+++ b/tests/integration/test_traits.py
@@ -26,7 +26,13 @@ class TraitIntegrationTest(TestCase):
trait_results = {
"dataset": None,
"trait_name": "1449593_at",
- "trait_data": {}
+ "trait_data": {
+ "BXD11": 8.464,
+ "BXD12": 8.414,
+ "BXD13": 8.753,
+ "BXD15": 8.5,
+ "BXD16": 8.832
+ }
}
mock_fetch_trait.return_value = trait_results
diff --git a/tests/unit/computations/test_datasets.py b/tests/unit/computations/test_datasets.py
index b696f70..44ff527 100644
--- a/tests/unit/computations/test_datasets.py
+++ b/tests/unit/computations/test_datasets.py
@@ -29,6 +29,8 @@ class TestDatasets(TestCase):
dataset_id = "HC_M2_0606_P&"
dataset_type = "Publish"
+ database = mock.Mock()
+
dataset = {
"id": dataset_id,
"type": dataset_type,
@@ -40,7 +42,7 @@ class TestDatasets(TestCase):
mock_fetch_sample_results.return_value = fetch_results
results = retrieve_trait_sample_data(
- dataset, trait_name)
+ dataset, trait_name, database)
self.assertEqual(mock_fetch_sample_results.call_count, 1)
self.assertEqual(results, fetch_results)
diff --git a/tests/unit/computations/test_trait.py b/tests/unit/computations/test_trait.py
index f662325..49c08d4 100644
--- a/tests/unit/computations/test_trait.py
+++ b/tests/unit/computations/test_trait.py
@@ -25,6 +25,8 @@ class TestTrait(TestCase):
"WQC": 11.1
}
+ database = mock.Mock()
+
get_sample_data.return_value = expected_sample_data
expected_trait = {
@@ -32,10 +34,12 @@ class TestTrait(TestCase):
"dataset": None,
"trait_data": expected_sample_data
}
- results = fetch_trait(dataset=None, trait_name="AXFDSF_AT")
+ results = fetch_trait(dataset=None,
+ trait_name="AXFDSF_AT",
+ database=database)
self.assertEqual(results, expected_trait)
- get_sample_data.assert_called_once_with(None, "AXFDSF_AT")
+ self.assertEqual(get_sample_data.call_count, 1)
@mock.patch("gn3.computations.traits.retrieve_trait_sample_data")
def test_get_trait_sample_data(self, mock_retrieve_sample_data):
@@ -52,8 +56,10 @@ class TestTrait(TestCase):
trait_name = "1426679_at"
+ database = mock.Mock()
+
results = get_trait_sample_data(
- trait_dataset, trait_name)
+ trait_dataset, trait_name, database)
expected_results = {
"129S1/SvImJ": 7.433,