+
+def open_folder(folder):
+ if sys.platform == "win32":
+ os.startfile(folder)
+ else:
+ opener ="open" if sys.platform == "darwin" else "xdg-open"
+ call([opener, folder])
+
+def normpath_win32(path) :
+ if not sys.platform == 'win32' :
+ return path
+ while '\\\\' in path :
+ path = path.replace('\\\\', '\\')
+ if path.startswith('\\') and not path.startswith('\\\\') :
+ path = '\\' + path
+ return path
+
+class TGen :
+ def __init__(self, path = None, encoding = 'utf8'):
+ self.path = path
+ self.tgen = {}
+ self.encoding = encoding
+
+ def __getitem__(self, key):
+ return self.tgen[key]
+
+ def read(self, path = None):
+ if path is None :
+ path = self.path
+ with codecs.open(path, 'r', self.encoding) as f :
+ tgen = f.read()
+ tgen = [line.split('\t') for line in tgen.splitlines()]
+ tgen = dict([[line[0], line[1:]] for line in tgen])
+ self.tgen = tgen
+ self.path = path
+
+ def write(self, path = None):
+ if path is None :
+ path = self.path
+ with open(path, 'w') as f :
+ f.write('\n'.join(['\t'.join([val] + self.tgen[val]) for val in self.tgen]).encode(self.encoding))
+
+ def writetable(self, pathout, tgens, totocc):
+ etoiles = totocc.keys()
+ etoiles.sort()
+ with open(pathout, 'w') as f :
+ line = '\t'.join([u'tgens'] + etoiles) + '\n'
+ f.write(line.encode(self.encoding))
+ for t in tgens :
+ line = '\t'.join([t] + [`tgens[t][et]` for et in etoiles]) + '\n'
+ f.write(line.encode(self.encoding))
+ i = 0
+ totname = 'total'
+ while totname + `i` in tgens :
+ i += 1
+ totname = totname + `i`
+ line = '\t'.join([totname] + [`totocc[et]` for et in etoiles]) + '\n'
+ f.write(line.encode(self.encoding))
+