Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions api/resources/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"""

from flask_restx import Namespace, Resource, fields
from flask import request, jsonify
from flask import request
from markupsafe import escape
from api.utils.bar_utils import BARUtils
from api.utils.mfinder_utils import MfinderUtils
from marshmallow import Schema, ValidationError, fields as marshmallow_fields
from api import db
from api.models.rice_interactions import Interactions as RiceInteractions
Expand Down Expand Up @@ -157,26 +156,3 @@ def post(self):
return BARUtils.success_exit(res)
else:
return BARUtils.error_exit("No data for the given species/genes"), 400


@itrns.route("/mfinder")
class MFinder(Resource):
@itrns.expect(post_int_data)
def post(self):
"""This endpoint was originally written by Vincent Lau to return mFinder
results to AGENT in his express node.JS app. However Tianhui Zhao refactored
to the BAR_API
"""
data = request.get_json()
# Validate json
try:
data = MFinderDataSchema().load(data)
except ValidationError as err:
return BARUtils.error_exit(err.messages), 400

filtered_valid_arr = MfinderUtils.input_validation(data["data"])
if isinstance(filtered_valid_arr, str):
return BARUtils.error_exit(filtered_valid_arr), 400
settings = MfinderUtils.settings_validation(data.get("options", {}))
ret_json = MfinderUtils.create_files_and_mfinder(filtered_valid_arr, settings)
return jsonify(MfinderUtils.beautify_results(ret_json))
200 changes: 0 additions & 200 deletions api/utils/mfinder_utils.py

This file was deleted.

55 changes: 0 additions & 55 deletions tests/resources/test_interactions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from api import app
from unittest import TestCase
import json
from json import load


class TestIntegrations(TestCase):
Expand Down Expand Up @@ -132,57 +131,3 @@ def test_post_itrns(self):
"error": "No data for the given species/genes",
}
self.assertEqual(data, expected)

def test_mfinder(self):
"""
This function test mfinder via POST.
"""
# Valid request
with open("tests/data/mfinder_input.json") as json_file_1:
input_data = load(json_file_1)
response = self.app_client.post(
"/interactions/mfinder",
json=input_data,
)
data = json.loads(response.get_data(as_text=True))
with open("tests/data/mfinder_output.json") as json_file_2:
expected = load(json_file_2)
self.assertEqual(data, expected)

# Invalid data structure
response = self.app_client.post("/interactions/mfinder", json={"data": {}})
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": {"data": ["Not a valid list."]}}
self.assertEqual(data, expected)

response = self.app_client.post("/interactions/mfinder", json={"data": []})
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": "arr length 0!"}
self.assertEqual(data, expected)

response = self.app_client.post(
"/interactions/mfinder", json={"data": [["AT5G67420", "AT1G12110"], ["AT5G67420"]]}
)
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": "inner arr length is not of length 2!"}
self.assertEqual(data, expected)

response = self.app_client.post("/interactions/mfinder", json={"data": [["AT5G67420", "AT1G12110"], 1]})
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": {"data": {"1": ["Not a valid list."]}}}
self.assertEqual(data, expected)

response = self.app_client.post(
"/interactions/mfinder", json={"data": [["AT5G67420", "AT1G12110"], ["AT5G67420", 1]]}
)
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": {"data": {"1": {"1": ["Not a valid string."]}}}}
self.assertEqual(data, expected)

# Invalid gene ID
response = self.app_client.post(
"/interactions/mfinder", json={"data": [["AT1G01010", "AT5G01010"], ["001G01030", "AT2G03240"]]}
)
data = json.loads(response.get_data(as_text=True))
expected = {"wasSuccessful": False, "error": "Invalid gene ID contained!"}
self.assertEqual(data, expected)
Loading