config.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import os
  2. import json
  3. def cmdMatlab():
  4. pwd=os.path.dirname(os.path.abspath(__file__))
  5. pwdUp=os.path.dirname(pwd)
  6. mDir=os.path.join(pwdUp,'matlab')
  7. with open(os.path.join(os.path.expanduser('~'),'.labkey','setup.json'),'r') as f:
  8. siteSetup=json.load(f)
  9. mExec=siteSetup['paths']['matlab']
  10. cmds=[mExec]
  11. cmds.append('-sd')
  12. cmds.append(mDir)
  13. #cmds.append('-batch')
  14. return cmds
  15. def getPatientId(row,xconfig):
  16. return row[getPatientField(xconfig)]
  17. def getPatientField(xconfig):
  18. return xconfig['ParticipantField']
  19. def getVisitField(xconfig):
  20. return 'visitName'
  21. def getVisitId(row,xconfig):
  22. return row[getVisitField(xconfig)]
  23. def getIdFilter(row,xconfig):
  24. return {'variable':getPatientField(xconfig),\
  25. 'value':getPatientId(row,xconfig),
  26. 'oper':'eq'}
  27. def getVisitFilter(row,xconfig):
  28. return {'variable':getVisitField(xconfig),\
  29. 'value':getVisitId(row,xconfig),
  30. 'oper':'eq'}
  31. def getCode(row,xconfig):
  32. return '{}_{}'.format(getPatientId(row,xconfig),getVisitId(row,xconfig))
  33. def getTargetSeqNum(row,xconfig):
  34. if getVisitId(row,xconfig)=='OBR':
  35. return 2
  36. return 1
  37. def getPathList(row,xconfig):
  38. return [xconfig['baseDir'],getPatientId(row,xconfig),getVisitId(row,xconfig)]
  39. def getOutputDir(row,xconfig):
  40. return '/'.join(getPathList(row,xconfig))
  41. def getTempDir(xconfig):
  42. tempDir=xconfig['tempDir']
  43. pathList=tempDir.split('/')
  44. pathList.insert(0,os.path.expanduser('~'))
  45. return os.path.join(*pathList)
  46. def getLocalDir(row,xconfig):
  47. return os.path.join(getTempDir(xconfig),getCode(row,xconfig))
  48. def getNodeName(row,xconfig,mode,i=0):
  49. if mode=='CT':
  50. return getCode(row,xconfig)+'_CT'
  51. if mode=='NM':
  52. return '{}_Volume{}'.format(getCode(row,xconfig),i)
  53. return getCode(row,xconfig)+'_Dummy'
  54. def decode(code,xconfig):
  55. #invert code and return object equivalent to row with relevant
  56. #fields set that can be used in
  57. #getPatientId, getVisitId,getIdFilter,getVisitFilter
  58. #as an equivalent replacement for r
  59. values=code.split('_')
  60. fid=values[0]
  61. vid=values[1]
  62. return {getPatientField(xconfig):fid,getVisitField(xconfig):vid}
  63. def printRowCenterNames(r,setup):
  64. names=[]
  65. nr=setup['nr']
  66. nclass=setup['nclass']
  67. code=getCode(r,setup)
  68. #tempDir=config.getTempDir(setup)
  69. for nc in nclass:
  70. for j in range(nr):
  71. for i in range(nc):
  72. fCode='{}_{}_{}_center{}'.format(code,nc,j+1,i+1)
  73. names.append('{}_center.txt'.format(fCode))
  74. names.append('{}_centerWeight.nrrd'.format(fCode))
  75. return names
  76. def getFitParFinalName(code,nc,j,aType):
  77. fCode='{}_{}_{}'.format(code,nc,j+1)
  78. if aType!='global':
  79. fCode='{}_{}'.format(fCode,aType)
  80. return '{}_fitParFinal.txt'.format(fCode)
  81. def printFitParFinalRowNames(r,setup,aType):
  82. names=[]
  83. nr=setup['nr']
  84. nclass=setup['nclass']
  85. code=getCode(r,setup)
  86. #tempDir=config.getTempDir(setup)
  87. for nc in nclass:
  88. for j in range(nr):
  89. names.append(getFitParFinalName(code,nc,j,aType))
  90. #names.append('{}_centerWeight.nrrd'.format(fCode))
  91. return names