Skip to content

Commit

Permalink
revisited special character section in read and write SBML files (#464)
Browse files Browse the repository at this point in the history
* Special character specific to libsbml and moose

* Update pymoose.yml

clean and update
  • Loading branch information
hrani committed Sep 14, 2023
1 parent 7b699e3 commit 2845875
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pymoose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- name: Install dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo -E apt clean
sudo -E apt update
sudo -E apt install -y cmake libgsl-dev g++ gcc git
sudo -E apt install python3-tk python-tk
sudo -E apt install -y libhdf5-dev doxygen
Expand Down
23 changes: 15 additions & 8 deletions python/moose/SBML/readSBML.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
Last-Updated: Tue Apr 5 17:10:00 2022(+0530)
By:HarshaRani
**********************************************************************/
2023
Aug3: SBMLread will not accept & and < special character in the name
Moose will not accept '/' (bcos path kinetics/pool etc),#,&,[,],?,/,<
explicitly I was converting space to _space_ which is removed
2022:
Apr 05: - edge case NN_mapk15.g, extra Neutral path '/kinetics' exist which
was not created in xml file which was causing ex12.0* example break
Expand Down Expand Up @@ -523,7 +527,7 @@ def getCmptAnnotation(obj):

def getObjAnnotation(obj, modelAnnotationInfo):
name = obj.getId()
name = name.replace(" ", "_space_")
#name = name.replace(" ", "_space_")
# modelAnnotaInfo= {}
annotateMap = {}
if (obj.getAnnotation() is not None):
Expand Down Expand Up @@ -568,7 +572,7 @@ def getObjAnnotation(obj, modelAnnotationInfo):
def getEnzAnnotation(obj, modelAnnotaInfo, rev,
globparameterIdValue, specInfoMap,funcDef):
name = obj.getId()
name = name.replace(" ", "_space_")
#name = name.replace(" ", "_space_")
# modelAnnotaInfo= {}
annotateMap = {}
if (obj.getAnnotation() is not None):
Expand Down Expand Up @@ -708,7 +712,7 @@ def createReaction(model, specInfoMap, modelAnnotaInfo, globparameterIdValue,fun
# group = groups[0]
if (reac.isSetName()):
rName = reac.getName()
rName = rName.replace(" ", "_space_")
#rName = rName.replace(" ", "_space_")
if not(rName):
rName = rId
rev = reac.getReversible()
Expand Down Expand Up @@ -1264,7 +1268,7 @@ def createSpecies(basePath, model, comptSbmlidMooseIdMap,
# group = groups[0]
if spe.isSetName():
sName = spe.getName()
sName = sName.replace(" ", "_space_")
#sName = sName.replace(" ", "_space_")

if spe.isSetCompartment():
comptId = spe.getCompartment()
Expand Down Expand Up @@ -1471,7 +1475,7 @@ def createCompartment(basePath, model, comptSbmlidMooseIdMap):

if (compt.isSetName()):
name = compt.getName()
name = name.replace(" ", "_space")
#name = name.replace(" ", "_space")

if (compt.isSetOutside()):
outside = compt.getOutside()
Expand Down Expand Up @@ -1613,9 +1617,12 @@ def idBeginWith(name):


def convertSpecialChar(str1):
d = {"&": "_and", "<": "_lessthan_", ">": "_greaterthan_", "BEL": "&#176", "-": "_minus_", "'": "_prime_",
"+": "_plus_", "*": "_star_", "/": "_slash_", "(": "_bo_", ")": "_bc_",
"[": "_sbo_", "]": "_sbc_", " ": "_"
# d = {"&": "_and", "<": "_lessthan_", ">": "_greaterthan_", "BEL": "&#176", "-": "_minus_", "'": "_prime_",
# "+": "_plus_", "*": "_star_", "/": "_slash_", "(": "_bo_", ")": "_bc_",
# "[": "_sbo_", "]": "_sbc_", " ": "_"
# }
d = {"BEL": "&#176" , "'": "_prime_", "/": "_slash_" ,"[": "_sbo_", "]": "_sbc_",
"#" :"_hash_" , "\"":"_quote_" , "?":"_question_" ,"\\":"_slash","&":"_and_","<":"_greater_"
}
for i, j in list(d.items()):
str1 = str1.replace(i, j)
Expand Down
16 changes: 12 additions & 4 deletions python/moose/SBML/writeSBML.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
By: HarshaRani
**********************************************************************/
/****************************
2023
Aug 3 : revisited specialChar, like /,\,[,],#,?,prime,quotes, are not allowed in name both in moose and sbml
All special charater are not allowed to write in sbml id those are retained and added
2022
Apr 5 : Added basepath in compartment Annotation
2021
Expand Down Expand Up @@ -1074,22 +1077,28 @@ def findGroup_compt(melement):
return melement

def convertSpecialCharshot(str1):
#Checks name str for special char and convert as SBML ID doesnot allow special char
d = { "BEL" : "&#176",
"'" : "_prime_",
"\\" : "_slash_",
"/" : "_slash_",
"[" : "_sbo_",
"]" : "_sbc_",
": " : "_" ,
" " : "_" }
"#" : "_hash_" ,
"\"" : "_quote_" ,
"?":"_question_",
"&":"_and_",
"<":"_greater_"
}
for i, j in d.items():
str1 = str1.replace(i, j)
return str1

def convertSpecialChar(str1):
# Checks Id str for special char and convert as SBML ID doesnot allow special char
d = {"&": "_and", "<": "_lessthan_", ">": "_greaterthan_", "BEL": "&#176", "-": "_minus_", "'": "_prime_",
"+": "_plus_", "*": "_star_", "/": "_slash_", "(": "_bo_", ")": "_bc_",
"[": "_sbo_", "]": "_sbc_", ".": "_dot_", " ": "_"
"[": "_sbo_", "]": "_sbc_", ".": "_dot_", " ": "_", "#" : "_hash_", "?": "_question_"
}
for i, j in d.items():
str1 = str1.replace(i, j)
Expand All @@ -1106,7 +1115,6 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
sName = convertSpecialChar(spe.name)
comptVec = findCompartment(spe)
speciannoexist = False

if not comptVec.isA("ChemCompt"):
return -2
else:
Expand Down
23 changes: 12 additions & 11 deletions python/moose/chemMerge/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,22 @@ def deleteSolver(modelRoot):
st_ksolve = st.ksolve
moose.delete(st)
if moose.exists((st_ksolve).path):
moose.delete(st_ksolve)
moose.delete(moose.element(st_ksolve))

def poolMerge(comptS,comptD,poolNotcopiedyet):
#Here from source file all the groups are check if exist, if doesn't exist then create those groups
#Then for that group pools are copied
SCmptGrp = moose.wildcardFind(comptS.path+'/#[TYPE=Neutral]')
SCmptGrp = SCmptGrp +(moose.element(comptS.path),)
SCmptGrp.append(moose.element(comptS.path))

DCmptGrp = moose.wildcardFind(comptD.path+'/#[TYPE=Neutral]')
DCmptGrp = DCmptGrp +(moose.element(comptD.path),)
DCmptGrp.append(moose.element(comptD.path))

objS = moose.element(comptS.path).parent.name
objD = moose.element(comptD.path).parent.name

for spath in SCmptGrp:
grp_cmpt = ((spath.path).replace(objS,objD)).replace('[0]','')
grp_cmpt = ((spath.path).replace(objS,objD,1)).replace('[0]','')
if moose.exists(grp_cmpt):
#If path exist, but its not the Neutral obj then creating a neutral obj with _grp
#It has happened that pool, reac, enz name might exist with the same name, which when tried to create a group
Expand All @@ -408,10 +408,10 @@ def poolMerge(comptS,comptD,poolNotcopiedyet):
#Neutral obj from src if doesn't exist in destination,then create src's Neutral obj in des
src = spath
srcpath = (spath.parent).path
des = srcpath.replace(objS,objD)
moose.Neutral(moose.element(des).path+'/'+spath.name)

dpath = moose.element(spath.path.replace(objS,objD))
des = srcpath.replace(objS,objD,1)
despath = moose.element(des).path
tt = moose.Neutral(moose.element(des).path+'/'+spath.name)
dpath = moose.element(spath.path.replace(objS,objD,1))
spoollist = moose.wildcardFind(spath.path+'/#[ISA=PoolBase]')
dpoollist = moose.wildcardFind(dpath.path+'/#[ISA=PoolBase]')
#check made, for a given Neutral or group if pool doesn't exist then copied
Expand Down Expand Up @@ -578,12 +578,13 @@ def reacMerge(comptS,comptD,key,poolListina):
# And assuming that pools are copied earlier EXPECT POOL CPLX
# To be assured the it takes correct compartment name incase reaction sub's
# belongs to different compt
key = findCompartment(rs).name
#key = findCompartment(rs).name
key = moose.element(rs.parent).name
if rSsubname and rSprdname:
allexists = checkexist(rSsubname,objS,objD)
allexistp = checkexist(rSprdname,objS,objD)
if allexists and allexistp:
rdpath = rs.parent.path.replace(objS,objD)
rdpath = rs.parent.path.replace(objS,objD,1)
reac = moose.copy(rs,moose.element(rdpath))
connectObj(reac,rSsubname,"sub",comptD,war_msg)
connectObj(reac,rSprdname,"prd",comptD,war_msg)
Expand Down Expand Up @@ -703,7 +704,7 @@ def checkexist(spList,objB,objA):
allexist = False
for rsp in spList:
found = False
rspPath = rsp.path.replace(objB,objA)
rspPath = rsp.path.replace(objB,objA,0)
if moose.exists(rspPath):
found = True
allexistL.append(found)
Expand Down

0 comments on commit 2845875

Please sign in to comment.