@@ -83,6 +83,7 @@ def test_filtering_a_little(run_component, input_path,
83
83
"--min_cells_per_gene" , "10" ,
84
84
"--min_fraction_mito" , "0" ,
85
85
"--max_fraction_mito" , "0.2" ,
86
+ "--var_gene_names" , "gene_symbol" ,
86
87
"--do_subset" ])
87
88
assert Path ("output-2.h5mu" ).is_file ()
88
89
mu_out = mu .read_h5mu ("output-2.h5mu" )
@@ -104,11 +105,76 @@ def test_filter_cells_without_counts(run_component, input_h5mu, tmp_path):
104
105
run_component ([
105
106
"--input" , temp_h5mu_path ,
106
107
"--output" , "output-3.h5mu" ,
107
- "--min_cells_per_gene" , "3"
108
+ "--min_cells_per_gene" , "0" ,
108
109
])
109
110
assert Path ("output-3.h5mu" ).is_file ()
110
111
mu_out = mu .read_h5mu ("output-3.h5mu" )
111
112
assert mu_out .mod ['rna' ].obs .at [obs_to_remove , 'filter_with_counts' ] == False
112
113
114
+ def test_filter_mitochondrial (run_component , input_path ,
115
+ input_n_rna_obs , input_n_prot_obs ,
116
+ input_n_rna_vars , input_n_prot_vars ):
117
+ run_component ([
118
+ "--input" , input_path ,
119
+ "--output" , "output-4.h5mu" ,
120
+ "--var_gene_names" , "gene_symbol" ,
121
+ "--max_fraction_mito" , "0.2" ,
122
+ "--do_subset"
123
+ ])
124
+ assert Path ("output-4.h5mu" ).is_file ()
125
+ mu_out = mu .read_h5mu ("output-4.h5mu" )
126
+ new_obs = mu_out .mod ['rna' ].n_obs
127
+ new_vars = mu_out .mod ['rna' ].n_vars
128
+ assert new_obs < input_n_rna_obs
129
+ assert new_vars == input_n_rna_vars
130
+ assert mu_out .mod ['prot' ].n_obs == input_n_prot_obs
131
+ assert mu_out .mod ['prot' ].n_vars == input_n_prot_vars
132
+ assert list (mu_out .mod ['rna' ].var ['feature_types' ].cat .categories ) == ["Gene Expression" ]
133
+ assert list (mu_out .mod ['prot' ].var ['feature_types' ].cat .categories ) == ["Antibody Capture" ]
134
+
135
+ def test_filter_mitochondrial_regex (run_component , input_path ,
136
+ input_n_rna_obs , input_n_prot_obs ,
137
+ input_n_rna_vars , input_n_prot_vars ):
138
+ run_component ([
139
+ "--input" , input_path ,
140
+ "--output" , "output-5.h5mu" ,
141
+ "--var_gene_names" , "gene_symbol" ,
142
+ "--max_fraction_mito" , "0.2" ,
143
+ "--mitochondrial_gene_regex" , "^[M][T]-" ,
144
+ "--do_subset"
145
+ ])
146
+ assert Path ("output-5.h5mu" ).is_file ()
147
+ mu_out = mu .read_h5mu ("output-5.h5mu" )
148
+ new_obs = mu_out .mod ['rna' ].n_obs
149
+ new_vars = mu_out .mod ['rna' ].n_vars
150
+ assert new_obs < input_n_rna_obs
151
+ assert new_vars == input_n_rna_vars
152
+ assert mu_out .mod ['prot' ].n_obs == input_n_prot_obs
153
+ assert mu_out .mod ['prot' ].n_vars == input_n_prot_vars
154
+ assert list (mu_out .mod ['rna' ].var ['feature_types' ].cat .categories ) == ["Gene Expression" ]
155
+ assert list (mu_out .mod ['prot' ].var ['feature_types' ].cat .categories ) == ["Antibody Capture" ]
156
+
157
+ def test_filter_mitochondrial_column_not_set (run_component , input_path ,
158
+ input_n_rna_obs , input_n_prot_obs ,
159
+ input_n_rna_vars , input_n_prot_vars ):
160
+ run_component ([
161
+ "--input" , input_path ,
162
+ "--output" , "output-6.h5mu" ,
163
+ "--max_fraction_mito" , "0.2" ,
164
+ "--mitochondrial_gene_regex" , "^[mM][tT]-" ,
165
+ "--do_subset"
166
+ ])
167
+ assert Path ("output-6.h5mu" ).is_file ()
168
+ mu_out = mu .read_h5mu ("output-6.h5mu" )
169
+ new_obs = mu_out .mod ['rna' ].n_obs
170
+ new_vars = mu_out .mod ['rna' ].n_vars
171
+ assert new_obs == input_n_rna_obs # Stays the same because filtering on the wrong column
172
+ assert new_vars == input_n_rna_vars
173
+ assert mu_out .mod ['prot' ].n_obs == input_n_prot_obs
174
+ assert mu_out .mod ['prot' ].n_vars == input_n_prot_vars
175
+ assert list (mu_out .mod ['rna' ].var ['feature_types' ].cat .categories ) == ["Gene Expression" ]
176
+ assert list (mu_out .mod ['prot' ].var ['feature_types' ].cat .categories ) == ["Antibody Capture" ]
177
+
178
+
113
179
if __name__ == "__main__" :
114
180
exit (pytest .main ([__file__ ], plugins = ["viashpy" ]))
0 commit comments