-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataload.py
135 lines (101 loc) · 5.81 KB
/
dataload.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import pandas as pd
from datasets import Dataset
def mytok(seq, kmer_len, s):
seq = seq.upper().replace("T", "U")
kmer_list = []
for j in range(0, (len(seq)-kmer_len)+1, s):
kmer_list.append(seq[j:j+kmer_len])
return kmer_list
########### loading dp dataset
def build_dp_dataset():
def load_dataset(data_path, split):
df = pd.read_csv(data_path)
df = df[df["split"] == split]
df = df.dropna(subset=["bp_zscore"])
# df['utr5_size'] = df['UTR5'].astype(str).map(len)
# df['cds_size'] = df['CDS'].astype(str).map(len)
# df['utr3_size'] = df['UTR3'].astype(str).map(len)
# df = df[df['utr5_size'] <= 512]
# df = df[df['cds_size'] <= 1020]
# df = df[df['utr3_size'] <= 1024]
utr5 = df["UTR5"].values.tolist()
utr3 = df["UTR3"].values.tolist()
cds = df["CDS"].values.tolist()
ys = df["bp_zscore"].values.tolist()
utr5 = [" ".join(mytok(seq, 1, 1)) for seq in utr5]
cds = [" ".join(mytok(seq, 3, 3)) for seq in cds]
utr3 = [" ".join(mytok(seq, 1, 1)) for seq in utr3]
seqs = list(zip(utr5, cds, utr3))
assert len(seqs) == len(ys)
return seqs, ys
train_seqs, train_ys = load_dataset("data/translation_rate.csv", "train")
valid_seqs, valid_ys = load_dataset("data/translation_rate.csv", "valid")
test_seqs, test_ys = load_dataset("data/translation_rate.csv", "test")
ds_train = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(train_seqs, train_ys)])
ds_valid = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(valid_seqs, valid_ys)])
ds_test = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(test_seqs, test_ys)])
return ds_train, ds_valid, ds_test
def build_class_dataset():
def load_dataset(data_path, split):
df = pd.read_csv(data_path)
df = df[df["split"] == split]
utr5 = df["5' UTR"].values.tolist()
utr3 = df["3' UTR"].values.tolist()
cds = df["CDS"].values.tolist()
ys = df["ClassificationID"].values.tolist()
utr5 = [" ".join(mytok(seq, 1, 1)) for seq in utr5]
cds = [" ".join(mytok(seq, 3, 3)) for seq in cds]
utr3 = [" ".join(mytok(seq, 1, 1)) for seq in utr3]
seqs = list(zip(utr5, cds, utr3))
assert len(seqs) == len(ys)
return seqs, ys
train_seqs, train_ys = load_dataset("data/protein_expression_5class.csv", "train")
valid_seqs, valid_ys = load_dataset("data/protein_expression_5class.csv", "valid")
test_seqs, test_ys = load_dataset("data/protein_expression_5class.csv", "test")
ds_train = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(train_seqs, train_ys)])
ds_valid = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(valid_seqs, valid_ys)])
ds_test = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(test_seqs, test_ys)])
return ds_train, ds_valid, ds_test
def build_liver_dataset():
def load_dataset(data_path, split):
df = pd.read_csv(data_path)
df = df[df["split"] == split]
utr5 = df["5' UTR"].values.tolist()
utr3 = df["3' UTR"].values.tolist()
cds = df["CDS"].values.tolist()
ys = df["Liver_norm"].values.tolist()
utr5 = [" ".join(mytok(seq, 1, 1)) for seq in utr5]
cds = [" ".join(mytok(seq, 3, 3)) for seq in cds]
utr3 = [" ".join(mytok(seq, 1, 1)) for seq in utr3]
seqs = list(zip(utr5, cds, utr3))
assert len(seqs) == len(ys)
return seqs, ys
train_seqs, train_ys = load_dataset("data/transcript_expression_liver.csv", "train")
valid_seqs, valid_ys = load_dataset("data/transcript_expression_liver.csv", "valid")
test_seqs, test_ys = load_dataset("data/transcript_expression_liver.csv", "test")
ds_train = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(train_seqs, train_ys)])
ds_valid = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(valid_seqs, valid_ys)])
ds_test = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(test_seqs, test_ys)])
return ds_train, ds_valid, ds_test
def build_saluki_dataset(cross):
def load_dataset(data_path):
df = pd.read_csv(data_path)
df = df.fillna('')
df = df.dropna(subset=["y"])
utr5 = df["UTR5"].values.tolist()
utr3 = df["UTR3"].values.tolist()
cds = df["CDS"].values.tolist()
ys = df["y"].values.tolist()
utr5 = [" ".join(mytok(seq, 1, 1)) for seq in utr5]
cds = [" ".join(mytok(seq, 3, 3)) for seq in cds]
utr3 = [" ".join(mytok(seq, 1, 1)) for seq in utr3]
seqs = list(zip(utr5, cds, utr3))
assert len(seqs) == len(ys)
return seqs, ys
train_seqs, train_ys = load_dataset("data/mrna_half-life.csv", "train")
valid_seqs, valid_ys = load_dataset("data/mrna_half-life.csv", "valid")
test_seqs, test_ys = load_dataset("data/mrna_half-life.csv", "test")
ds_train = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(train_seqs, train_ys)])
ds_valid = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(valid_seqs, valid_ys)])
ds_test = Dataset.from_list([{"5utr": seq[0], "cds": seq[1], "3utr": seq[2], "label": y} for seq, y in zip(test_seqs, test_ys)])
return ds_train, ds_valid, ds_test