@@ -42,11 +42,11 @@ def setup_class(self, tmpdir):
4242
4343 def test_compcor (self ):
4444 expected_components = [
45- [" -0.1989607212" , " -0.5753813646" ],
46- [" 0.5692369697" , " 0.5674945949" ],
47- [" -0.6662573243" , " 0.4675843432" ],
48- [" 0.4206466244" , " -0.3361270124" ],
49- [" -0.1246655485" , " -0.1235705610" ],
45+ [- 0.1989607212 , - 0.5753813646 ],
46+ [0.5692369697 , 0.5674945949 ],
47+ [- 0.6662573243 , 0.4675843432 ],
48+ [0.4206466244 , - 0.3361270124 ],
49+ [- 0.1246655485 , - 0.1235705610 ],
5050 ]
5151
5252 self .run_cc (
@@ -73,11 +73,11 @@ def test_compcor(self):
7373
7474 def test_compcor_variance_threshold_and_metadata (self ):
7575 expected_components = [
76- [" -0.2027150345" , " -0.4954813834" ],
77- [" 0.2565929051" , " 0.7866217875" ],
78- [" -0.3550986008" , " -0.0089784905" ],
79- [" 0.7512786244" , " -0.3599828482" ],
80- [" -0.4500578942" , " 0.0778209345" ],
76+ [- 0.2027150345 , - 0.4954813834 ],
77+ [0.2565929051 , 0.7866217875 ],
78+ [- 0.3550986008 , - 0.0089784905 ],
79+ [0.7512786244 , - 0.3599828482 ],
80+ [- 0.4500578942 , 0.0778209345 ],
8181 ]
8282 expected_metadata = {
8383 "component" : "CompCor00" ,
@@ -111,11 +111,11 @@ def test_tcompcor(self):
111111 self .run_cc (
112112 ccinterface ,
113113 [
114- [" -0.1114536190" , " -0.4632908609" ],
115- [" 0.4566907310" , " 0.6983205193" ],
116- [" -0.7132557407" , " 0.1340170559" ],
117- [" 0.5022537643" , " -0.5098322262" ],
118- [" -0.1342351356" , " 0.1407855119" ],
114+ [- 0.1114536190 , - 0.4632908609 ],
115+ [0.4566907310 , 0.6983205193 ],
116+ [- 0.7132557407 , 0.1340170559 ],
117+ [0.5022537643 , - 0.5098322262 ],
118+ [- 0.1342351356 , 0.1407855119 ],
119119 ],
120120 "tCompCor" ,
121121 )
@@ -138,11 +138,11 @@ def test_compcor_no_regress_poly(self):
138138 pre_filter = False ,
139139 ),
140140 [
141- [" 0.4451946442" , " -0.7683311482" ],
142- [" -0.4285129505" , " -0.0926034137" ],
143- [" 0.5721540256" , " 0.5608764842" ],
144- [" -0.5367548139" , " 0.0059943226" ],
145- [" -0.0520809054" , " 0.2940637551" ],
141+ [0.4451946442 , - 0.7683311482 ],
142+ [- 0.4285129505 , - 0.0926034137 ],
143+ [0.5721540256 , 0.5608764842 ],
144+ [- 0.5367548139 , 0.0059943226 ],
145+ [- 0.0520809054 , 0.2940637551 ],
146146 ],
147147 )
148148
@@ -225,27 +225,20 @@ def run_cc(
225225 assert os .path .getsize (expected_file ) > 0
226226
227227 with open (ccresult .outputs .components_file , "r" ) as components_file :
228- if expected_n_components is None :
229- expected_n_components = min (
230- ccinterface .inputs .num_components , self .fake_data .shape [3 ]
231- )
228+ header = components_file .readline ().rstrip ().split ("\t " )
229+ components_data = np .loadtxt (components_file , delimiter = "\t " )
230+
231+ if expected_n_components is None :
232+ expected_n_components = min (
233+ ccinterface .inputs .num_components , self .fake_data .shape [3 ]
234+ )
235+
236+ assert header == [
237+ f"{ expected_header } { i :02d} " for i in range (expected_n_components )
238+ ]
232239
233- components_data = [line .rstrip ().split ("\t " ) for line in components_file ]
234-
235- # the first item will be '#', we can throw it out
236- header = components_data .pop (0 )
237- expected_header = [
238- expected_header + "{:02d}" .format (i )
239- for i in range (expected_n_components )
240- ]
241- for i , heading in enumerate (header ):
242- assert expected_header [i ] in heading
243-
244- num_got_timepoints = len (components_data )
245- assert num_got_timepoints == self .fake_data .shape [3 ]
246- for index , timepoint in enumerate (components_data ):
247- assert len (timepoint ) == expected_n_components
248- assert timepoint [:2 ] == expected_components [index ]
240+ assert components_data .shape == (self .fake_data .shape [3 ], expected_n_components )
241+ assert np .allclose (components_data [:, :2 ], expected_components )
249242
250243 if ccinterface .inputs .save_metadata :
251244 expected_metadata_file = ccinterface ._list_outputs ()["metadata_file" ]
0 commit comments