@@ -38,25 +38,20 @@ def test_compcor(self):
3838 ['0.4206466244' , '-0.3361270124' ],
3939 ['-0.1246655485' , '-0.1235705610' ]]
4040
41- ccresult = self .run_cc (CompCor (realigned_file = self .realigned_file ,
42- mask_file = self .mask_file ),
41+ self .run_cc (CompCor (realigned_file = self .realigned_file , mask_file = self .mask_file ),
4342 expected_components )
4443
45- accresult = self .run_cc (ACompCor (realigned_file = self .realigned_file ,
46- mask_file = self .mask_file ,
47- components_file = 'acc_components_file' ),
48- expected_components )
49-
50- assert_equal (os .path .getsize (ccresult .outputs .components_file ),
51- os .path .getsize (accresult .outputs .components_file ))
44+ self .run_cc (ACompCor (realigned_file = self .realigned_file , mask_file = self .mask_file ,
45+ components_file = 'acc_components_file' ),
46+ expected_components , 'aCompCor' )
5247
5348 def test_tcompcor (self ):
5449 ccinterface = TCompCor (realigned_file = self .realigned_file , percentile_threshold = 0.75 )
5550 self .run_cc (ccinterface , [['-0.1114536190' , '-0.4632908609' ],
5651 ['0.4566907310' , '0.6983205193' ],
5752 ['-0.7132557407' , '0.1340170559' ],
5853 ['0.5022537643' , '-0.5098322262' ],
59- ['-0.1342351356' , '0.1407855119' ]])
54+ ['-0.1342351356' , '0.1407855119' ]], 'tCompCor' )
6055
6156 def test_tcompcor_no_percentile (self ):
6257 ccinterface = TCompCor (realigned_file = self .realigned_file )
@@ -96,7 +91,7 @@ def test_tcompcor_bad_input_dim(self):
9691 interface = TCompCor (realigned_file = data_file )
9792 self .assertRaisesRegexp (ValueError , '4-D' , interface .run )
9893
99- def run_cc (self , ccinterface , expected_components ):
94+ def run_cc (self , ccinterface , expected_components , expected_header = 'CompCor' ):
10095 # run
10196 ccresult = ccinterface .run ()
10297
@@ -108,12 +103,19 @@ def run_cc(self, ccinterface, expected_components):
108103 assert_equal (ccinterface .inputs .num_components , 6 )
109104
110105 with open (ccresult .outputs .components_file , 'r' ) as components_file :
106+ expected_n_components = min (ccinterface .inputs .num_components , self .fake_data .shape [3 ])
107+
111108 components_data = [line .split () for line in components_file ]
112- num_got_components = len (components_data )
113- assert_true (num_got_components == ccinterface .inputs .num_components
114- or num_got_components == self .fake_data .shape [3 ])
115- first_two = [row [:2 ] for row in components_data ]
116- assert_equal (first_two , expected_components )
109+
110+ header = components_data .pop (0 )[1 :] # the first item will be '#', we can throw it out
111+ assert_equal (header , [expected_header + str (i ) for i in range (expected_n_components )])
112+
113+ num_got_timepoints = len (components_data )
114+ assert_equal (num_got_timepoints , self .fake_data .shape [3 ])
115+ for index , timepoint in enumerate (components_data ):
116+ assert_true (len (timepoint ) == ccinterface .inputs .num_components
117+ or len (timepoint ) == self .fake_data .shape [3 ])
118+ assert_equal (timepoint [:2 ], expected_components [index ])
117119 return ccresult
118120
119121 def tearDown (self ):
0 commit comments