Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare app for production #6

Merged
merged 3 commits into from
Dec 3, 2021
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
4 changes: 2 additions & 2 deletions lib/kb_djornl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def run_rwr_cv(config, clients): # pylint: disable=too-many-locals
""" run RWR_CV and generate a report """
"""run RWR_CV and generate a report"""
params = config.get("params")
shared = config.get("shared")
dfu = clients["dfu"]
Expand Down Expand Up @@ -110,7 +110,7 @@ def run_rwr_cv(config, clients): # pylint: disable=too-many-locals
def run_rwr_loe(
config, clients
): # pylint: disable=too-many-locals, too-many-statements
""" run RWR_LOE and generate a report """
"""run RWR_LOE and generate a report"""
params = config.get("params")
shared = config.get("shared")
dfu = clients["dfu"]
Expand Down
20 changes: 10 additions & 10 deletions lib/kb_djornl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def create_tair10_featureset(
genes, config, dfu, gsu
): # pylint: disable=too-many-locals
""" Create an Arabidopsis thaliana featureset from a list of genes. """
"""Create an Arabidopsis thaliana featureset from a list of genes."""
params = config.get("params")
workspace_id = params["workspace_id"]
genome_ref = "Phytozome_Genomes/Athaliana_TAIR10"
Expand Down Expand Up @@ -56,7 +56,7 @@ def create_tair10_featureset(


def cytoscape_node(node, rank, seed=False):
""" convert nodedata into cytoscape format """
"""convert nodedata into cytoscape format"""
return dict(
defline=node["defline"],
geneSymbols=node["gene_symbols"],
Expand All @@ -71,7 +71,7 @@ def cytoscape_node(node, rank, seed=False):


def cytoscape_edge(edge):
""" convert edge data into cytoscape format """
"""convert edge data into cytoscape format"""
return dict(
id=edge["_id"],
edgeType=edge["edge_type"],
Expand Down Expand Up @@ -170,42 +170,42 @@ def fork_rwr_loe(reports_path, params, dfu): # pylint: disable=too-many-locals


def genes_to_rwr_tsv(genes):
""" convert a list of genes to a tsv string for use with RWR tools"""
"""convert a list of genes to a tsv string for use with RWR tools"""
return "".join([f"report\t{gene}\n" for gene in genes])


def get_wsurl():
""" Get the workspace url for this environment. """
"""Get the workspace url for this environment."""
config_file = os.environ.get("KB_DEPLOYMENT_CONFIG")
config_p = configparser.ConfigParser()
config_p.read(config_file)
return config_p["kb_djornl"]["workspace-url"]


def get_genes_from_tair10_featureset(featureset_ref, dfu):
""" Read genes from a A. thaliana featureset. """
"""Read genes from a A. thaliana featureset."""
featureset_response = dfu.get_objects({"object_refs": [featureset_ref]})
featureset = featureset_response["data"][0]["data"]
return featureset["element_ordering"]


def load_manifest():
""" Load the manifest yaml file """
"""Load the manifest yaml file"""
manifest_path = os.path.join(DATA_ROOT, "prerelease/manifest.yaml")
with open(manifest_path) as manifest_file:
manifest = yaml.safe_load(manifest_file)
return manifest


def normalized_node_id(node_id):
""" normalize node id """
"""normalize node id"""
if "/" in node_id:
return node_id.split("/")[1]
return node_id


def object_info_as_dict(object_info):
""" Convert a KBase object_info list into a dictionary. """
"""Convert a KBase object_info list into a dictionary."""
[
_id,
_name,
Expand Down Expand Up @@ -288,7 +288,7 @@ def put_graph_metadata(metadata, config): # pylint: disable=too-many-locals


def query_sqlite(genes): # pylint: disable=too-many-locals
""" Query the data loaded into sqlite3 based on seed genes """
"""Query the data loaded into sqlite3 based on seed genes"""
networks_path = os.path.join(DATA_ROOT, "networks.db")
con = sqlite3.connect(networks_path)
manifest = load_manifest()
Expand Down
2 changes: 1 addition & 1 deletion scripts/postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def download_assets(assets, endpoint, cookies):
"""Download assets from endpoint using cookies. """
"""Download assets from endpoint using cookies."""
destination_path = "test_local/workdir/tmp/reports"
for asset in assets:
asset_url = endpoint._replace(path=asset).geturl()
Expand Down
5 changes: 4 additions & 1 deletion scripts/refdata-load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ set -e
KB_ENV=$(grep -e kbase_endpoint /kb/module/work/config.properties \
| cut -f3 -d'/' | cut -f1 -d. \
)
if [[ "$KB_ENV" == 'ci' ]]; then
echo Detected environment $KB_ENV
if [[ "$KB_ENV" == 'kbase' ]]; then
RWRTOOLS_BLOB_URL='https://kbase.us/services/shock-api/node/e27516d4-e54d-4931-91f7-7d36c25fe3cc?download_raw'
elif [[ "$KB_ENV" == 'ci' ]]; then
RWRTOOLS_BLOB_URL='https://ci.kbase.us/services/shock-api/node/0481bd3b-14b4-40f9-a585-aee531235edc?download_raw';
elif [[ "$KB_ENV" == 'appdev' ]]; then
RWRTOOLS_BLOB_URL='https://appdev.kbase.us/services/shock-api/node/29d12bac-53b9-451f-8fc6-48124f1c2f8f?download_raw';
Expand Down
2 changes: 1 addition & 1 deletion scripts/rwrtools-env-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x
set -e

source /miniconda/etc/profile.d/conda.sh
conda env create -vv -f ./data/rwrtools.yml
conda env create -v -f ./data/rwrtools.yml
conda activate rwrtools
R --no-restore --no-save << HEREDOC
if (!requireNamespace("BiocManager", quietly = TRUE))
Expand Down
18 changes: 9 additions & 9 deletions test/kb_djornl_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@


def echo(*args, **kwargs):
""" echo arguments """
"""echo arguments"""
print(args)
print(kwargs)
return defaultdict(dict)


class EchoMock: # pylint: disable=too-few-public-methods
""" echo mocker """
"""echo mocker"""

def __getattribute__(self, name):
assert name
return echo


class MockDFU:
""" mock dfu """
"""mock dfu"""

def save_objects(self, params):
""" mock dfu save_objects """
"""mock dfu save_objects"""
assert self, params
return [[None] * 11]

def ws_name_to_id(self, name):
""" mock workspace name to id """
"""mock workspace name to id"""
assert self
return len(name)

def get_objects(self, params):
""" mock get_objects """
"""mock get_objects"""
assert self
ref = params["object_refs"][0]
mock_filenames = dict(
Expand All @@ -67,7 +67,7 @@ def get_objects(self, params):


class kb_djornlTest(unittest.TestCase): # pylint: disable=invalid-name
""" kb_djornl unit test class """
"""kb_djornl unit test class"""

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -129,12 +129,12 @@ def tearDownClass(cls):
print("Test workspace was deleted")

def setUp(self):
""" remove report dir before each test"""
"""remove report dir before each test"""
# the scratch dir is named shared in kb_djornlImpl
shutil.rmtree(self.reports_path, ignore_errors=True)

def _get_multiplex_params(self, multiplex):
""" Make parameters for RWR_CV and RWR_LOE mutliplex tests """
"""Make parameters for RWR_CV and RWR_LOE mutliplex tests"""
return {
"workspace_id": self.workspace_id,
"workspace_name": self.wsName,
Expand Down