Skip to content

Commit 4881d81

Browse files
authored
Merge pull request #990 from Sage-Bionetworks/develop
Schematic Release v22.10.3
2 parents 7bee333 + e95d856 commit 4881d81

File tree

6 files changed

+62
-18
lines changed

6 files changed

+62
-18
lines changed

api/routes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ def get_viz_tangled_tree_text(schema_url, figure_type, text_format):
421421
return text_df
422422

423423
def get_viz_tangled_tree_layers(schema_url, figure_type):
424-
424+
425+
# call config_handler()
426+
config_handler()
427+
425428
temp_path_to_jsonld = get_temp_jsonld(schema_url)
426429

427430
# Initialize Tangled Tree

run_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# Launch app
1616
app = create_app()
1717
CORS(app, resources={r"*": {"origins": "*"}})
18-
app.run(port=3001, debug=True)
18+
app.run(host=host, port=port, debug=True)

schematic/store/synapse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def wrapper(*args, **kwargs):
138138
return method(*args, **kwargs)
139139
except(SynapseHTTPError) as ex:
140140
str_message = str(ex).replace("\n","")
141-
if 'missing' in str_message:
141+
if 'trash' in str_message or 'does not exist' in str_message:
142142
logging.warning(str_message)
143143
return None
144144
else:
@@ -717,16 +717,16 @@ def get_synapse_table(self, synapse_id: str) -> Tuple[pd.DataFrame, CsvFileTable
717717

718718
return df, results
719719

720-
def _get_tables(self) -> List[Table]:
721-
project = self.syn.get(self.project_scope[0])
720+
def _get_tables(self, datasetId: str = None) -> List[Table]:
721+
project = self.syn.get(self.getDatasetProject(datasetId))
722722
return list(self.syn.getChildren(project, includeTypes=["table"]))
723723

724-
def get_table_info(self) -> List[str]:
724+
def get_table_info(self, datasetId: str = None) -> List[str]:
725725
"""Gets the names of the tables in the schema
726726
Returns:
727727
list[str]: A list of table names
728728
"""
729-
tables = self._get_tables()
729+
tables = self._get_tables(datasetId)
730730
if tables:
731731
return {table["name"]: table["id"] for table in tables}
732732
else:
@@ -735,7 +735,7 @@ def get_table_info(self) -> List[str]:
735735
@missing_entity_handler
736736
def upload_format_manifest_table(self, se, manifest, datasetId, table_name, restrict, useSchemaLabel):
737737
# Rename the manifest columns to display names to match fileview
738-
table_info = self.get_table_info()
738+
table_info = self.get_table_info(datasetId)
739739

740740
blacklist_chars = ['(', ')', '.', ' ']
741741
manifest_columns = manifest.columns.tolist()

schematic/visualization/attributes_explorer.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import numpy as np
55
import os
66
import pandas as pd
7-
import resource
87
from typing import Any, Dict, Optional, Text, List
98

109
from schematic.schemas import SchemaGenerator
1110
from schematic.utils.io_utils import load_json
12-
from schematic import CONFIG
1311

1412
logger = logging.getLogger(__name__)
1513

@@ -114,7 +112,16 @@ def parse_attributes(self, save_file=True):
114112
# Capitalize attribute if it begins with a lowercase letter, for aesthetics.
115113
if attribute[0].islower():
116114
attribute = attribute.capitalize()
117-
conditional_statement = f'{attribute} -is- "{value[0]}"'
115+
116+
# Remove "Type" (i.e. turn "Biospecimen Type" to "Biospcimen")
117+
if "Type" in attribute:
118+
attribute = attribute.split(" ")[0]
119+
120+
# Remove "Type" (i.e. turn "Tissue Type" to "Tissue")
121+
if "Type" in value[0]:
122+
value[0] = value[0].split(" ")[0]
123+
124+
conditional_statement = f'{attribute} is "{value[0]}"'
118125
if conditional_statement not in data_dict[key]['Conditional Requirements']:
119126
data_dict[key]['Cond_Req'] = True
120127
data_dict[key]['Conditional Requirements'].extend([conditional_statement])
@@ -123,9 +130,23 @@ def parse_attributes(self, save_file=True):
123130
f"There is an error getting conditional requirements related "
124131
"to the attribute: {key}. The error is likely caused by naming inconsistencies (e.g. uppercase, camelcase, ...)"
125132
)
133+
126134
for key, value in data_dict.items():
127135
if 'Conditional Requirements' in value.keys():
128-
data_dict[key]['Conditional Requirements'] = ' || '.join(data_dict[key]['Conditional Requirements'])
136+
137+
## reformat conditional requirement
138+
139+
# get all attributes
140+
attr_lst = [i.split(" is ")[-1] for i in data_dict[key]['Conditional Requirements']]
141+
142+
# join a list of attributes by using OR
143+
attr_str = " OR ".join(attr_lst)
144+
145+
# reformat the conditional requirement
146+
component_name = data_dict[key]['Conditional Requirements'][0].split(' is ')[0]
147+
conditional_statement_str = f" If {component_name} is {attr_str} then {key} is required"
148+
149+
data_dict[key]['Conditional Requirements'] = conditional_statement_str
129150
df = pd.DataFrame(data_dict)
130151
df = df.T
131152
cols = ['Attribute', 'Label', 'Description', 'Required', 'Cond_Req', 'Valid Values', 'Conditional Requirements', 'Validation Rules', 'Component']

schematic/visualization/tangled_tree.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
from os import path
88
import pandas as pd
9-
from pathlib import Path
109

1110
# allows specifying explicit variable types
1211
from typing import Any, Dict, Optional, Text, List
@@ -159,6 +158,19 @@ def get_topological_generations(self):
159158

160159
return topological_gen, nodes, edges, subg
161160

161+
def remove_unwanted_characters_from_conditional_statement(self, cond_req: str) -> str:
162+
'''Remove unwanted characters from conditional statement
163+
Example of conditional requirement: If File Format IS "BAM" OR "CRAM" OR "CSV/TSV" then Genome Build is required
164+
Example output: File Format IS "BAM" OR "CRAM" OR "CSV/TSV"
165+
'''
166+
if "then" in cond_req:
167+
# remove everything after "then"
168+
cond_req_new = cond_req.split('then')[0]
169+
170+
# remove "If" and empty space
171+
cond_req = cond_req_new.replace("If", "").lstrip().rstrip()
172+
return cond_req
173+
162174
def get_ca_alias(self, conditional_requirements: list) -> dict:
163175
'''Get the alias for each conditional attribute.
164176
@@ -173,13 +185,22 @@ def get_ca_alias(self, conditional_requirements: list) -> dict:
173185
value: attribute
174186
'''
175187
ca_alias = {}
188+
189+
# clean up conditional requirements
190+
conditional_requirements = [self.remove_unwanted_characters_from_conditional_statement(req) for req in conditional_requirements]
191+
176192
for i, req in enumerate(conditional_requirements):
177-
req = req.split(' || ')
178-
for r in req:
179-
attr, ali = r.split(' -is- ')
193+
if "OR" not in req:
194+
attr, ali = req.split(' is ')
180195
attr = "".join(attr.split())
181196
ali = self.strip_double_quotes(ali)
182197
ca_alias[ali] = attr
198+
else:
199+
attr, alias_str = req.split(' is ')
200+
alias_lst = alias_str.split(' OR ')
201+
for elem in alias_lst:
202+
elem = self.strip_double_quotes(elem)
203+
ca_alias[elem] = attr
183204
return ca_alias
184205

185206
def gather_component_dependency_info(self, cn, attributes_df):

tests/data/test_config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
definitions:
22
creds_path: "../../credentials.json"
33
token_pickle: "token.pickle"
4-
#synapse_config: "../../.synapseConfig"
4+
synapse_config: "../../.synapseConfig"
55
### Note: this key is required for people who use Synapse token authentication approach.
6-
### If you run into errors similar to KeyError: 'synpase_config', you might want to consider adding this key.
76

87
synapse:
98
master_fileview: "syn23643253"

0 commit comments

Comments
 (0)