Browse Source

Minor updates to scripts, config file is also used in vangogh mode

Andrej 1 year ago
parent
commit
345e0bdcec

File diff suppressed because it is too large
+ 8 - 2
pythonScripts/analyze.ipynb


+ 23 - 15
pythonScripts/clusterAnalysis.ipynb

@@ -33,6 +33,19 @@
     "import labkeyInterface\n",
     "import labkeyFileBrowser\n",
     "import labkeyDatabaseBrowser\n",
+    "\n",
+    "def connect(server,f):\n",
+    "    net=labkeyInterface.labkeyInterface()\n",
+    "    fconfig=os.path.join(os.path.expanduser('~'),'.labkey','{}.json'.format(server))\n",
+    "    net.init(fconfig)\n",
+    "    net.getCSRF()\n",
+    "    return f(net)\n",
+    "\n",
+    "def connectDB(server):\n",
+    "    return connect(server,labkeyDatabaseBrowser.labkeyDB)\n",
+    "\n",
+    "def connectFB(server):\n",
+    "    return connect(server,labkeyFileBrowser.labkeyFileBrowser)\n",
     "\n"
    ]
   },
@@ -47,12 +60,8 @@
     "with open(fsetup,'r') as f:\n",
     "    setup=json.load(f)\n",
     "\n",
-    "net=labkeyInterface.labkeyInterface()\n",
-    "fconfig=os.path.join(os.path.expanduser('~'),'.labkey',setup['network'])\n",
-    "net.init(fconfig)\n",
-    "#net.getCSRF()\n",
-    "db=labkeyDatabaseBrowser.labkeyDB(net)\n",
-    "fb=labkeyFileBrowser.labkeyFileBrowser(net)\n",
+    "db=connectDB('merlin')\n",
+    "fb=connectFB('merlin')\n",
     "    \n",
     "\n",
     "    \n"
@@ -66,12 +75,18 @@
    "source": [
     "#doAnalysis\n",
     "\n",
+    "#fill the Imaging1 fields, for multiple visits, change sequence number\n",
+    "\n",
+    "\n",
     "#0.) convert to NRRD \n",
     "# ~/software/src/SlicerLabkeyExtenstion/slicerScripts/runSlicer.sh convertToNRRD.py ../template/cardiacSPECT.json)\n",
     "\n",
+    "#this is not performed at vangogh, use Analysis on merlin, convertNRRD.py with cardiacSPECT.json\n",
+    "\n",
     "#1.) downloadFiles\n",
     "\n",
     "#getData.downloadPatientFiles(db,fb,setup)\n",
+    "#this should also be done at vangogh... Figuring out how\n",
     "\n",
     "#2.) generate (c-cluster) centers\n",
     "\n",
@@ -111,18 +126,11 @@
     "\n",
     "#8.) Plot regions through chart wizard on labkey, see also Summary R Report for error-plots on multi-class analysis\n"
    ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {},
-   "outputs": [],
-   "source": []
   }
  ],
  "metadata": {
   "kernelspec": {
-   "display_name": "Python 3",
+   "display_name": "Python 3 (ipykernel)",
    "language": "python",
    "name": "python3"
   },
@@ -136,7 +144,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.8.10"
+   "version": "3.10.6"
   }
  },
  "nbformat": 4,

File diff suppressed because it is too large
+ 2 - 1
pythonScripts/segmentation.ipynb


+ 91 - 1
pythonScripts/segmentation.py

@@ -4,7 +4,7 @@ import SimpleITK
 import os
 import getData
 
-def guessPixelPosition(sx=-1,sy=-1,sz=-1):
+def guessPixelPosition15(sx=-1,sy=-1,sz=-1):
     #guess position of segments
     if sx<0:
         sx=12
@@ -17,6 +17,41 @@ def guessPixelPosition(sx=-1,sy=-1,sz=-1):
 
     slc=[sx,sy,sz]
     p1=[sx,sy,sz]
+    pts={
+      '0':[sx-5,sy,sz],\
+      '1':[sx-2,sy,sz-rz],\
+      '2':[sx-2,sy,sz+rz-1],\
+      '3':[sx-1,sy-rz,sz],\
+      '4':[sx-1,sy+rz-1,sz],\
+      '5':[sx,sy-rz+oz,sz],\
+      '6':[sx,sy-0.3*rz+oz,sz-rz],\
+      '7':[sx,sy-0.3*rz+oz,sz+rz],\
+      '8':[sx,sy,sz],\
+      '9':[sx,sy+0.3*rz+oz,sz-rz],\
+      '10':[sx,sy+0.3*rz+oz,sz+rz],\
+      '11':[sx,sy+rz+oz,sz],\
+      '12':[sx+3,sy-rz,sz],\
+      '13':[sx+3,sy,sz-rz],\
+      '14':[sx+3,sy,sz+rz],\
+      '15':[sx+3,sy+rz,sz]}
+    slices={'0':['8','0','1','13','2','14'],\
+      '1':['8','0','3','4','12','15'],\
+      '2':['8','11','9','6','5','7','10']}
+   
+    print(slices['0'])
+
+    fp={x:[pts[q] for q in slices[x]] for x in slices}
+    
+    sliceIds={x:[] for x in pts}
+    for p in pts:
+       for s in slices:
+          if p in slices[s]:
+             sliceIds[p].append(s)
+    
+    sliceCode={x:';'.join(sliceIds[x]) for x in sliceIds}
+    print(fp)
+    print(sliceCode)
+    return fp
 
     #tip
     fp={'0':[\
@@ -43,7 +78,62 @@ def guessPixelPosition(sx=-1,sy=-1,sz=-1):
             [sx,sy+0.3*rz+oz,sz+rz]]}
     return fp
 
+def guessPixelPosition4(sx=-1,sy=-1,sz=-1):
+    #guess position of segments
+    if sx<0:
+        sx=32
+    if sy<0:
+        sy=31
+    if sz<0:
+        sz=31
+    rz=4
+
+    pts={
+      '0':[sx,sy,sz],\
+      '1':[sx,sy,sz-rz],\
+      '2':[sx,sy,sz+rz],\
+      '3':[sx,sy-rz,sz],\
+      '4':[sx,sy+rz,sz]}
+    slices={
+      '0':['0','1','2'],\
+      '1':['0','3','4'],\
+      '2':['0','1','2','3','4']}
+   
+    print(slices['0'])
+
+    fp={x:[pts[q] for q in slices[x]] for x in slices}
     
+    sliceIds={x:[] for x in pts}
+    for p in pts:
+       for s in slices:
+          if p in slices[s]:
+             sliceIds[p].append(s)
+    
+    sliceCode={x:';'.join(sliceIds[x]) for x in sliceIds}
+    print(fp)
+    print(sliceCode)
+    return [{'regionId':x,'x':pts[x][0],'y':pts[x][1],'z':pts[x][2],'sliceId':sliceCode[x]} for x in pts]
+
+def updateSegmentation(db,setup,r,pixels):
+   copyFields=['PatientId','visitName']
+   for x in pixels:
+      for c in copyFields:
+         x[c]=r[c]
+      x['SequenceNum']=r['SequenceNum']+0.01*int(x['regionId'])
+      filterVar=['PatientId','SequenceNum']
+      qFilter=[{'variable':y,'value':'{}'.format(x[y]),'oper':'eq'} for y in filterVar]
+      ds=db.selectRows(setup['project'],'study','Segmentation',qFilter)
+      entry={}
+      mode='insert'
+      if len(ds['rows'])>0:
+         entry=ds['rows'][0]
+         mode='update'
+      for q in x:
+         entry[q]=x[q]
+      db.modifyRows(mode,setup['project'],'study','Segmentation',[entry])
+   print('Done')
+     
+
 def getPatientNIM(r,setup):
     locDir=config.getLocalDir(r,setup)
     fileName=config.getNodeName(r,setup,'NM',19)+'.nrrd'

+ 8 - 4
template/cardiacSPECT.json

@@ -4,7 +4,6 @@
 		"schemaName":"study",
 		"queryName":"Imaging"
 	},
-   "network":"merlin.json",
 	"project":"dinamic_spect/Patients",
    "schemaName":"study",
 	"queryName":"Imaging1",
@@ -12,10 +11,15 @@
    "summaryQueryName":"Summary",
 	"dicomDir":"dicom",
 	"remote":1,
-	"localDir":"/home/studen/temp/dynamicSPECT",
-	"tempDir":"/home/studen/temp/dynamicSPECT",
+	"localDir":"temp/dynamicSPECT",
+	"tempDir":"temp/dynamicSPECT",
 	"PatientId":"3ZFMIR",
    "baseDir":"processedImages",
    "ParticipantField":"PatientId",
-   "recalculate":1
+   "recalculate":0,
+   "network":"merlin.json",
+   "nclass":[10,20,30],
+   "nr":20,
+   "patientFilter":[{"variable":"PatientId","value":"MM","oper":"eq"},{"variable":"visitName","value":"MIR","oper":"eq"}],
+   "calculateCenters":0
 }

Some files were not shown because too many files changed in this diff