Mercurial > repos > perssond > coreograph
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolbox/ftools.py Wed May 19 21:34:38 2021 +0000 @@ -0,0 +1,55 @@ +from os.path import * +from os import listdir, makedirs, remove +import pickle +import shutil + +def fileparts(path): # path = file path + [p,f] = split(path) + [n,e] = splitext(f) + return [p,n,e] + +def listfiles(path,token): # path = folder path + l = [] + for f in listdir(path): + fullPath = join(path,f) + if isfile(fullPath) and token in f: + l.append(fullPath) + l.sort() + return l + +def listsubdirs(path): # path = folder path + l = [] + for f in listdir(path): + fullPath = join(path,f) + if isdir(fullPath): + l.append(fullPath) + l.sort() + return l + +def pathjoin(p,ne): # '/path/to/folder', 'name.extension' (or a subfolder) + return join(p,ne) + +def saveData(data,path): + print('saving data') + dataFile = open(path, 'wb') + pickle.dump(data, dataFile) + +def loadData(path): + print('loading data') + dataFile = open(path, 'rb') + return pickle.load(dataFile) + +def createFolderIfNonExistent(path): + if not exists(path): # from os.path + makedirs(path) + +def moveFile(fullPathSource,folderPathDestination): + [p,n,e] = fileparts(fullPathSource) + shutil.move(fullPathSource,pathjoin(folderPathDestination,n+e)) + +def copyFile(fullPathSource,folderPathDestination): + [p,n,e] = fileparts(fullPathSource) + shutil.copy(fullPathSource,pathjoin(folderPathDestination,n+e)) + +def removeFile(path): + remove(path) \ No newline at end of file