Mercurial > repos > perssond > coreograph
comparison toolbox/ftools.py @ 0:99308601eaa6 draft
"planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
| author | perssond | 
|---|---|
| date | Wed, 19 May 2021 21:34:38 +0000 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:99308601eaa6 | 
|---|---|
| 1 from os.path import * | |
| 2 from os import listdir, makedirs, remove | |
| 3 import pickle | |
| 4 import shutil | |
| 5 | |
| 6 def fileparts(path): # path = file path | |
| 7 [p,f] = split(path) | |
| 8 [n,e] = splitext(f) | |
| 9 return [p,n,e] | |
| 10 | |
| 11 def listfiles(path,token): # path = folder path | |
| 12 l = [] | |
| 13 for f in listdir(path): | |
| 14 fullPath = join(path,f) | |
| 15 if isfile(fullPath) and token in f: | |
| 16 l.append(fullPath) | |
| 17 l.sort() | |
| 18 return l | |
| 19 | |
| 20 def listsubdirs(path): # path = folder path | |
| 21 l = [] | |
| 22 for f in listdir(path): | |
| 23 fullPath = join(path,f) | |
| 24 if isdir(fullPath): | |
| 25 l.append(fullPath) | |
| 26 l.sort() | |
| 27 return l | |
| 28 | |
| 29 def pathjoin(p,ne): # '/path/to/folder', 'name.extension' (or a subfolder) | |
| 30 return join(p,ne) | |
| 31 | |
| 32 def saveData(data,path): | |
| 33 print('saving data') | |
| 34 dataFile = open(path, 'wb') | |
| 35 pickle.dump(data, dataFile) | |
| 36 | |
| 37 def loadData(path): | |
| 38 print('loading data') | |
| 39 dataFile = open(path, 'rb') | |
| 40 return pickle.load(dataFile) | |
| 41 | |
| 42 def createFolderIfNonExistent(path): | |
| 43 if not exists(path): # from os.path | |
| 44 makedirs(path) | |
| 45 | |
| 46 def moveFile(fullPathSource,folderPathDestination): | |
| 47 [p,n,e] = fileparts(fullPathSource) | |
| 48 shutil.move(fullPathSource,pathjoin(folderPathDestination,n+e)) | |
| 49 | |
| 50 def copyFile(fullPathSource,folderPathDestination): | |
| 51 [p,n,e] = fileparts(fullPathSource) | |
| 52 shutil.copy(fullPathSource,pathjoin(folderPathDestination,n+e)) | |
| 53 | |
| 54 def removeFile(path): | |
| 55 remove(path) | 
