|
a |
|
b/tests/test_multiomics.py |
|
|
1 |
"""Tests for `openomics` package.""" |
|
|
2 |
|
|
|
3 |
from openomics import MessengerRNA, MicroRNA, LncRNA, Protein, SomaticMutation |
|
|
4 |
from openomics import MultiOmics |
|
|
5 |
from .test_clinical import * |
|
|
6 |
|
|
|
7 |
cohort_folder_path = "tests/data/TCGA_LUAD/" |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
@pytest.fixture |
|
|
11 |
def generate_TCGA_LUAD_MessengerRNA(): |
|
|
12 |
data = MessengerRNA( |
|
|
13 |
data=os.path.join(cohort_folder_path, "LUAD__geneExp.txt"), |
|
|
14 |
transpose=True, |
|
|
15 |
usecols="GeneSymbol|TCGA", |
|
|
16 |
gene_index="GeneSymbol", |
|
|
17 |
gene_level="gene_name", |
|
|
18 |
) |
|
|
19 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
20 |
data.drop_samples(data.expressions.index[:100]) |
|
|
21 |
return data |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
@pytest.fixture |
|
|
25 |
def generate_TCGA_LUAD_MessengerRNA_dask(): |
|
|
26 |
data = MessengerRNA( |
|
|
27 |
data=os.path.join(cohort_folder_path, "LUAD__geneExp.txt"), |
|
|
28 |
transpose=True, |
|
|
29 |
usecols="GeneSymbol|TCGA", |
|
|
30 |
gene_index="GeneSymbol", |
|
|
31 |
gene_level="gene_name", |
|
|
32 |
npartitions=4, |
|
|
33 |
) |
|
|
34 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
35 |
data.init_annotations() |
|
|
36 |
return data |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
@pytest.fixture |
|
|
40 |
def generate_TCGA_LUAD_MicroRNA(): |
|
|
41 |
data = MicroRNA( |
|
|
42 |
data=os.path.join(cohort_folder_path, "LUAD__miRNAExp__RPM.txt"), |
|
|
43 |
transpose=True, |
|
|
44 |
usecols="GeneSymbol|TCGA", |
|
|
45 |
gene_index="GeneSymbol", |
|
|
46 |
gene_level="gene_name", |
|
|
47 |
) |
|
|
48 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
49 |
data.drop_samples(data.expressions.index[:100]) |
|
|
50 |
return data |
|
|
51 |
|
|
|
52 |
|
|
|
53 |
@pytest.fixture |
|
|
54 |
def generate_TCGA_LUAD_LncRNA(): |
|
|
55 |
data = LncRNA( |
|
|
56 |
data=os.path.join(cohort_folder_path, "TCGA-rnaexpr.tsv"), |
|
|
57 |
transpose=True, |
|
|
58 |
usecols="Gene_ID|TCGA", |
|
|
59 |
gene_index="Gene_ID", |
|
|
60 |
gene_level="gene_id", |
|
|
61 |
) |
|
|
62 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
63 |
data.drop_samples(data.expressions.index[:100]) |
|
|
64 |
return data |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
@pytest.fixture |
|
|
68 |
def generate_TCGA_LUAD_SomaticMutation(): |
|
|
69 |
data = SomaticMutation( |
|
|
70 |
data=os.path.join(cohort_folder_path, |
|
|
71 |
"LUAD__somaticMutation_geneLevel.txt"), |
|
|
72 |
transpose=True, |
|
|
73 |
usecols="GeneSymbol|TCGA", |
|
|
74 |
gene_index="gene_name", |
|
|
75 |
) |
|
|
76 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
77 |
data.drop_samples(data.expressions.index[:100]) |
|
|
78 |
return data |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
@pytest.fixture |
|
|
82 |
def generate_TCGA_LUAD_Protein(): |
|
|
83 |
data = Protein( |
|
|
84 |
data=os.path.join(cohort_folder_path, "protein_RPPA.txt"), |
|
|
85 |
transpose=True, |
|
|
86 |
usecols="GeneSymbol|TCGA", |
|
|
87 |
gene_index="GeneSymbol", |
|
|
88 |
gene_level="protein_name", |
|
|
89 |
) |
|
|
90 |
data.drop_genes(data.expressions.columns[50:]) |
|
|
91 |
data.drop_samples(data.expressions.index[:100]) |
|
|
92 |
return data |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
def test_import_MessengerRNA_Dask(generate_TCGA_LUAD_MessengerRNA_dask): |
|
|
96 |
""" |
|
|
97 |
Args: |
|
|
98 |
generate_TCGA_LUAD_MessengerRNA_dask: |
|
|
99 |
""" |
|
|
100 |
assert generate_TCGA_LUAD_MessengerRNA_dask.expressions is not None |
|
|
101 |
|
|
|
102 |
|
|
|
103 |
def test_import_expression_table_size(generate_TCGA_LUAD_MessengerRNA, generate_TCGA_clinical): |
|
|
104 |
""" |
|
|
105 |
Args: |
|
|
106 |
generate_TCGA_LUAD_MessengerRNA: |
|
|
107 |
""" |
|
|
108 |
cohort_name = "LUAD" |
|
|
109 |
luad_data = MultiOmics(cohort_name) |
|
|
110 |
luad_data.add_clinical_data(generate_TCGA_clinical) |
|
|
111 |
luad_data.add_omic(generate_TCGA_LUAD_MessengerRNA) |
|
|
112 |
luad_data.build_samples() |
|
|
113 |
print(luad_data.data.keys()) |
|
|
114 |
assert (luad_data.data[MessengerRNA.name()].shape == |
|
|
115 |
generate_TCGA_LUAD_MessengerRNA.expressions.shape) |
|
|
116 |
|
|
|
117 |
|
|
|
118 |
@pytest.fixture |
|
|
119 |
def generate_TCGA_LUAD( |
|
|
120 |
generate_TCGA_clinical, |
|
|
121 |
generate_TCGA_LUAD_MessengerRNA, |
|
|
122 |
generate_TCGA_LUAD_MicroRNA, |
|
|
123 |
generate_TCGA_LUAD_LncRNA, |
|
|
124 |
generate_TCGA_LUAD_Protein, |
|
|
125 |
): |
|
|
126 |
""" |
|
|
127 |
Args: |
|
|
128 |
generate_TCGA_LUAD_MessengerRNA: |
|
|
129 |
generate_TCGA_LUAD_MicroRNA: |
|
|
130 |
generate_TCGA_LUAD_LncRNA: |
|
|
131 |
generate_TCGA_LUAD_Protein: |
|
|
132 |
""" |
|
|
133 |
cohort_name = "LUAD" |
|
|
134 |
luad_data = MultiOmics(cohort_name) |
|
|
135 |
luad_data.add_clinical_data(generate_TCGA_clinical) |
|
|
136 |
luad_data.add_omic(generate_TCGA_LUAD_MessengerRNA) |
|
|
137 |
luad_data.add_omic(generate_TCGA_LUAD_MicroRNA) |
|
|
138 |
luad_data.add_omic(generate_TCGA_LUAD_LncRNA) |
|
|
139 |
luad_data.add_omic(generate_TCGA_LUAD_Protein) |
|
|
140 |
return luad_data |
|
|
141 |
|
|
|
142 |
|
|
|
143 |
def test_TCGA_LUAD_multiomics_transcriptomics(generate_TCGA_LUAD): |
|
|
144 |
""" |
|
|
145 |
Args: |
|
|
146 |
generate_TCGA_LUAD: |
|
|
147 |
""" |
|
|
148 |
assert all(elem in generate_TCGA_LUAD.get_omics_list() for elem in [ |
|
|
149 |
MessengerRNA.name(), |
|
|
150 |
MicroRNA.name(), |
|
|
151 |
LncRNA.name(), |
|
|
152 |
Protein.name(), |
|
|
153 |
]) |