forked from slancast/fiber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreating_samples_metadata.py
65 lines (61 loc) · 1.44 KB
/
creating_samples_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import numpy as np
from shutil import copyfile
import shutil
cwd=os.getcwd()
counter = 0
array = [["sample","participant","fiber","week","run"]]
for root, dirs, files in os.walk(cwd):
for dir in dirs:
shutil.rmtree(dir)
for root, dirs, files in os.walk(cwd):
print(files)
try:
files.remove("samples.txt")
files.remove(".DS_Store")
except ValueError:
print("Error")
for file in files:
print(file)
z=file.split("_")
print(z)
if z[1] == "1" or z[1] == "2":
z[2] = z[1] + z[2]
del z[1]
if z[1] == "LC" or z[1] == "SC" or z[1] == "1LC" or z[1] == "2LC" or z[1] == "1SC" or z[1] == "2SC":
z[1] = z[1] + z[2]
del z[2]
if z[2] == "Washout":
z[2] = z[2] + z[3]
del z[3]
if z[2] == "WashoutWeek" or z[2] == "Washoutweek" or z[2] == "Washoutweek":
z[2] = z[2] + z[3]
del z[3]
if z[2] == "End":
del z[3]
if z[2] == "":
z[2] = "?"
print(z)
if z[3] == "rsem.genes.results.txt":
counter = counter + 1
a = [counter]
a.append(z[0])
a.append(z[1])
a.append(z[2])
b=z[0]+"_"+z[1]+"_"+z[2]
a.append(b)
if a[2].startswith("1") or a[2].startswith("2"):
a[2] = a[2][1:]
a.append(z[3])
array.append(a)
print(b)
try:
os.mkdir(cwd+"/"+b)
break
except OSError:
print(cwd+"/"+b+" already made")
break
copyfile(cwd+"/"+file, cwd+"/"+b+"/"+b+".genes.results")
array = np.array(array)
with open('samples.txt','wb') as f:
np.savetxt(f,array,fmt="%s",delimiter="\t")