|  | @@ -3,6 +3,7 @@ import sys
 | 
	
		
			
				|  |  |  import config
 | 
	
		
			
				|  |  |  import analysis
 | 
	
		
			
				|  |  |  import json
 | 
	
		
			
				|  |  | +import SimpleITK
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def connectDB(server):
 | 
	
		
			
				|  |  |     sPath=os.path.join(os.path.expanduser('~'),'.labkey','setup.json')
 | 
	
	
		
			
				|  | @@ -65,23 +66,20 @@ def downloadNode(fb,fileName,rPath,lPath):
 | 
	
		
			
				|  |  |          return
 | 
	
		
			
				|  |  |      print('Loading {}'.format(fileName))
 | 
	
		
			
				|  |  |      fb.readFileToFile(rPath1,lPath1)
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  def downloadFiles(fb,r,setup):
 | 
	
		
			
				|  |  | -    rPath=fb.formatPathURL(setup['project'],config.getOutputDir(r,setup))
 | 
	
		
			
				|  |  | -    lPath=config.getLocalDir(r,setup)
 | 
	
		
			
				|  |  | -    if not os.path.isdir(lPath):
 | 
	
		
			
				|  |  | -        os.makedirs(lPath)
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      #CT
 | 
	
		
			
				|  |  |      fileName=config.getNodeName(r,setup,'CT')+'.nrrd'
 | 
	
		
			
				|  |  | -    downloadNode(fb,fileName,rPath,lPath)
 | 
	
		
			
				|  |  | +    copyFromServer(fb,r,setup,[fileName])
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      for i in range(20):
 | 
	
		
			
				|  |  |          fileName=config.getNodeName(r,setup,'NM',i)+'.nrrd'
 | 
	
		
			
				|  |  | -        downloadNode(fb,fileName,rPath,lPath)
 | 
	
		
			
				|  |  | +        copyFromServer(fb,r,setup,[fileName])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      fileName=config.getNodeName(r,setup,'Dummy')+'.mcsv'
 | 
	
		
			
				|  |  | -    downloadNode(fb,fileName,rPath,lPath)
 | 
	
		
			
				|  |  | +    copyFromServer(fb,r,setup,[fileName])
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |  def downloadPatientFiles(db,fb,setup,qfilter=[]):
 | 
	
		
			
				|  |  |      rows=getPatients(db,setup,qfilter)
 | 
	
	
		
			
				|  | @@ -123,11 +121,34 @@ def copyFromServer(fb,r,setup,names):
 | 
	
		
			
				|  |  |     project=setup['project']
 | 
	
		
			
				|  |  |     remoteDir=fb.buildPathURL(project,config.getPathList(r,setup))
 | 
	
		
			
				|  |  |     for n in names:
 | 
	
		
			
				|  |  | -      localPath=os.path.join(tempDir,code,n)
 | 
	
		
			
				|  |  | +      localDir=os.path.join(tempDir,code)
 | 
	
		
			
				|  |  | +      if not os.path.isdir(localDir):
 | 
	
		
			
				|  |  | +         os.makedirs(localDir)
 | 
	
		
			
				|  |  | +      localPath=os.path.join(localDir,n)
 | 
	
		
			
				|  |  |        if os.path.isfile(localPath) and not forceReload:
 | 
	
		
			
				|  |  |           continue
 | 
	
		
			
				|  |  |        remotePath='{}/{}'.format(remoteDir,n)
 | 
	
		
			
				|  |  | -      fb.readFileToFile(localPath,remotePath)
 | 
	
		
			
				|  |  | +      fb.readFileToFile(remotePath,localPath)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def getLocalPath(r,setup,name):
 | 
	
		
			
				|  |  | +   tempDir=config.getTempDir(setup)
 | 
	
		
			
				|  |  | +   code=config.getCode(r,setup)
 | 
	
		
			
				|  |  | +   return os.path.join(tempDir,code,name)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def getURL(r,setup,name):
 | 
	
		
			
				|  |  | +   remoteDir=fb.buildPathURL(project,config.getPathList(r,setup))
 | 
	
		
			
				|  |  | +   return '/'.join(remoteDir,name)
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | +def getPatientNIM(fb,r,setup):
 | 
	
		
			
				|  |  | +    fileName=config.getNodeName(r,setup,'NM',19)+'.nrrd'
 | 
	
		
			
				|  |  | +    f=getLocalPath(r,setup,fileName)
 | 
	
		
			
				|  |  | +    if not os.path.isfile(f):
 | 
	
		
			
				|  |  | +#download from server
 | 
	
		
			
				|  |  | +       copyFromServer(fb,r,setup,[fileName])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    im=SimpleITK.ReadImage(f)
 | 
	
		
			
				|  |  | +    nim=SimpleITK.GetArrayFromImage(im)
 | 
	
		
			
				|  |  | +    return nim
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      
 |