From 9e6443a15fe3dabcbf2d0b377f40678292e62bab Mon Sep 17 00:00:00 2001 From: unknown <david.hoksza@gmail.com> Date: Wed, 23 Oct 2019 15:13:52 +0200 Subject: [PATCH] ability to process non-multi sbmls; sanitization of names --- gui_config.ini | 2 +- talent/common.py | 3 +++ talent/sbml.py | 41 ++++++++++++++++++++-------------------- talent/utils/transfer.py | 5 +++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/gui_config.ini b/gui_config.ini index 4fde66e..a78bc57 100644 --- a/gui_config.ini +++ b/gui_config.ini @@ -3,6 +3,6 @@ openTgtFileDir=C:/projects/git/talent/tmp/pd_test1.sbml openTmpFileDir=C:/projects/git/talent/tmp/pd_test2.sbml openOutputPathButton=C:/projects/git/talent/out openOutputPath=C:/projects/git/talent/out -opnBcFile=C:/projects/git/talent/out/pd_test1-cc_0--from--pd_test2-cc0-tmp_order_0-tgt-ddup_False_tmp-ddup_False.pkl +opnBcFile=C:/projects/git/talent/out/pd_test1-cmp_Autophagy-cc_1--from--MTORAMPKsignaling-cc0-tmp_order_0-tgt-ddup_False_tmp-ddup_False.pkl cbTgtType=1 cbTmpType=1 diff --git a/talent/common.py b/talent/common.py index d682af8..2cb6acf 100644 --- a/talent/common.py +++ b/talent/common.py @@ -132,4 +132,7 @@ def str2bool(v): else: raise argparse.ArgumentTypeError('Boolean value expected.') +def sanitize_string(s: str): + return "".join(x for x in s if x.isalnum() or x in "_-") + diff --git a/talent/sbml.py b/talent/sbml.py index a31a534..f02ef27 100644 --- a/talent/sbml.py +++ b/talent/sbml.py @@ -410,25 +410,26 @@ class SbmlHelper: def __assign_features_to_species(self, features:Dict[str, MultiSpeciesType]) -> Dict: sid_features = {} - for species in self.model.getListOfSpecies(): - s_id = species.getId() - sid_features[s_id] = [] - multi = species.getPlugin('multi') - st = multi.getSpeciesType() - for sf in multi.getListOfSpeciesFeatures(): - occ = sf.getOccur() - sft = sf.getSpeciesFeatureType() - fsft = features[st].value[sft] - vals = [] - for val in sf.getListOfSpeciesFeatureValues(): - valval = val.getValue() - assert (st in features) - assert (sft in features[st].value) - assert (valval in fsft.value) - vals.append(fsft.value[valval]) - # for i in range(occ): - # sid_features[s_id].append(features[st][sftZZ][valval]) - sid_features[s_id].append(be.SpeciesFeature(cnt=occ, feature_type=sft, feature_name=fsft.name, values=vals)) + if self.multiPlugin: + for species in self.model.getListOfSpecies(): + s_id = species.getId() + sid_features[s_id] = [] + multi = species.getPlugin('multi') + st = multi.getSpeciesType() + for sf in multi.getListOfSpeciesFeatures(): + occ = sf.getOccur() + sft = sf.getSpeciesFeatureType() + fsft = features[st].value[sft] + vals = [] + for val in sf.getListOfSpeciesFeatureValues(): + valval = val.getValue() + assert (st in features) + assert (sft in features[st].value) + assert (valval in fsft.value) + vals.append(fsft.value[valval]) + # for i in range(occ): + # sid_features[s_id].append(features[st][sftZZ][valval]) + sid_features[s_id].append(be.SpeciesFeature(cnt=occ, feature_type=sft, feature_name=fsft.name, values=vals)) # TODO: possibly remove features which are shared across all species because those are irrelevant for discerning whether two glyps differ @@ -628,7 +629,7 @@ class SbmlHelper: compartmentName=compartments[s.getCompartment()] if s.getCompartment() else 'default', sboTerm= s.getSBOTerm(), layout=self.getSpeciesLayoutData(s_id), - features=sid_features[s_id] + features=sid_features[s_id] if s_id in sid_features else [] # 'bbox': bbox, # 'center': [bbox['x']+ bbox['width'] / 2, bbox['y']+ bbox['height'] / 2] )) diff --git a/talent/utils/transfer.py b/talent/utils/transfer.py index 21ad2b9..6995a37 100644 --- a/talent/utils/transfer.py +++ b/talent/utils/transfer.py @@ -293,8 +293,9 @@ def map_transfer_store(tgt, tmps, cache_path, output_path, ix_connected_componen # BeautificationOp(BEAUTY_OPERATION_TYPE.HANDLE_REACTION_SPECIES_OVERLAPS) # ]) # bc.run() - fname = "{}/{}-tmp_order_{}-tgt-ddup_{}_tmp-ddup_{}.pkl".format(output_path, get_tgt_tmp_name(tgt, tmp), i, - tgt.is_ddup(), tmp.is_ddup()) + fname = "{}/{}-tmp_order_{}-tgt-ddup_{}_tmp-ddup_{}.pkl".format(output_path, + common.sanitize_string(get_tgt_tmp_name(tgt, tmp)), + i, tgt.is_ddup(), tmp.is_ddup()) output_fnames.append(fname) # fname = "{}_cc-{}_k-{}.pkl".format(output_path, ix_connected_component, i) logging.info("Storing transferred layout into {}".format(fname)) -- GitLab