-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Split aCompCor into aCompCor, cCompCor, wCompCor #2523
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
daf8e63
ENH: Add RenameACompCor interface
effigies 318f9f1
ENH: Insert aCompCor renamer into confounds workflow
effigies be6a5be
TEST: Add regression test with some truncated aCompCor components
effigies 4d479a9
ENH: Add interface for filtering out metadata of dropped components
effigies 9fe66ec
TEST: Check FilterDropped
effigies 291315d
ENH: Filter dropped tCompCor and aCompCor components
effigies f1f2333
DOC: Add docstrings for new interfaces [skip tests]
effigies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,88 @@ def _run_interface(self, runtime): | |
return runtime | ||
|
||
|
||
class _FilterDroppedInputSpec(BaseInterfaceInputSpec): | ||
in_file = File(exists=True, desc='input CompCor metadata') | ||
|
||
|
||
class _FilterDroppedOutputSpec(TraitedSpec): | ||
out_file = File(desc='filtered CompCor metadata') | ||
|
||
|
||
class FilterDropped(SimpleInterface): | ||
input_spec = _FilterDroppedInputSpec | ||
output_spec = _FilterDroppedOutputSpec | ||
|
||
def _run_interface(self, runtime): | ||
self._results["out_file"] = fname_presuffix( | ||
self.inputs.in_file, | ||
suffix='_filtered', | ||
use_ext=True, | ||
newpath=runtime.cwd) | ||
|
||
metadata = pd.read_csv(self.inputs.in_file, sep='\t') | ||
metadata[metadata.retained].to_csv(self._results["out_file"], sep='\t', index=False) | ||
|
||
return runtime | ||
|
||
|
||
class _RenameACompCorInputSpec(BaseInterfaceInputSpec): | ||
components_file = File(exists=True, desc='input aCompCor components') | ||
metadata_file = File(exists=True, desc='input aCompCor metadata') | ||
|
||
|
||
class _RenameACompCorOutputSpec(TraitedSpec): | ||
components_file = File(desc='output aCompCor components') | ||
metadata_file = File(desc='output aCompCor metadata') | ||
|
||
|
||
class RenameACompCor(SimpleInterface): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here? |
||
input_spec = _RenameACompCorInputSpec | ||
output_spec = _RenameACompCorOutputSpec | ||
|
||
def _run_interface(self, runtime): | ||
self._results["components_file"] = fname_presuffix( | ||
self.inputs.components_file, | ||
suffix='_renamed', | ||
use_ext=True, | ||
newpath=runtime.cwd) | ||
self._results["metadata_file"] = fname_presuffix( | ||
self.inputs.metadata_file, | ||
suffix='_renamed', | ||
use_ext=True, | ||
newpath=runtime.cwd) | ||
|
||
components = pd.read_csv(self.inputs.components_file, sep='\t') | ||
metadata = pd.read_csv(self.inputs.metadata_file, sep='\t') | ||
all_comp_cor = metadata[metadata["retained"]] | ||
|
||
c_comp_cor = all_comp_cor[all_comp_cor["mask"] == "CSF"] | ||
w_comp_cor = all_comp_cor[all_comp_cor["mask"] == "WM"] | ||
a_comp_cor = all_comp_cor[all_comp_cor["mask"] == "combined"] | ||
|
||
c_orig = c_comp_cor["component"] | ||
c_new = [f"c_comp_cor_{i:02d}" for i in range(len(c_orig))] | ||
|
||
w_orig = w_comp_cor["component"] | ||
w_new = [f"w_comp_cor_{i:02d}" for i in range(len(w_orig))] | ||
|
||
a_orig = a_comp_cor["component"] | ||
a_new = [f"a_comp_cor_{i:02d}" for i in range(len(a_orig))] | ||
|
||
(components.rename(columns=dict(zip(c_orig, c_new))) | ||
.rename(columns=dict(zip(w_orig, w_new))) | ||
.rename(columns=dict(zip(a_orig, a_new))) | ||
).to_csv(self._results["components_file"], sep='\t', index=False) | ||
|
||
metadata.loc[c_comp_cor.index, "component"] = c_new | ||
metadata.loc[w_comp_cor.index, "component"] = w_new | ||
metadata.loc[a_comp_cor.index, "component"] = a_new | ||
|
||
metadata.to_csv(self._results["metadata_file"], sep='\t', index=False) | ||
|
||
return runtime | ||
|
||
|
||
class GatherConfoundsInputSpec(BaseInterfaceInputSpec): | ||
signals = File(exists=True, desc='input signals') | ||
dvars = File(exists=True, desc='file containing DVARS') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def data_dir(): | ||
return Path(__file__).parent / "data" |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
fmriprep/interfaces/tests/data/component_metadata_filtered.tsv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
component mask singular_value variance_explained cumulative_variance_explained retained | ||
a_comp_cor_00 CSF 303.3879065215 0.0822378515 0.0822378515 True | ||
a_comp_cor_01 CSF 265.3127089823 0.0628914102 0.1451292617 True | ||
a_comp_cor_02 CSF 246.9403411402 0.0544827867 0.1996120484 True | ||
a_comp_cor_03 CSF 230.7904478523 0.0475894718 0.2472015202 True | ||
a_comp_cor_04 CSF 204.1002458456 0.0372187926 0.2844203128 True | ||
a_comp_cor_05 CSF 191.4965421158 0.0327640136 0.3171843264 True | ||
a_comp_cor_06 CSF 164.3946836008 0.0241463095 0.3413306359 True | ||
a_comp_cor_07 CSF 163.0617292465 0.023756328 0.3650869639 True | ||
a_comp_cor_08 CSF 155.6055929068 0.0216334423 0.3867204062 True | ||
a_comp_cor_09 CSF 142.6779990644 0.0181881801 0.4049085863 True | ||
a_comp_cor_10 CSF 132.7833535167 0.0157529716 0.4206615579 True | ||
a_comp_cor_11 CSF 125.5448815801 0.0140822888 0.4347438468 True | ||
a_comp_cor_12 CSF 114.4560888929 0.0117045044 0.4464483511 True | ||
a_comp_cor_13 CSF 109.7800169819 0.0107676719 0.457216023 True | ||
a_comp_cor_14 CSF 98.9016427614 0.0087394124 0.4659554354 True | ||
a_comp_cor_15 CSF 95.592760075 0.0081644179 0.4741198534 True | ||
a_comp_cor_16 CSF 93.2993710837 0.0077773682 0.4818972215 True | ||
a_comp_cor_17 CSF 89.7572859278 0.0071980465 0.489095268 True | ||
a_comp_cor_18 CSF 85.4637024159 0.0065258732 0.4956211413 True | ||
a_comp_cor_19 CSF 83.3739078155 0.0062106283 0.5018317696 True | ||
a_comp_cor_20 WM 195.3633011611 0.0249509989 0.0249509989 True | ||
a_comp_cor_21 WM 152.0507341632 0.0151139858 0.0400649847 True | ||
a_comp_cor_22 WM 143.1829225994 0.0134024567 0.0534674414 True | ||
a_comp_cor_23 WM 119.7135045391 0.0093688925 0.0628363339 True | ||
a_comp_cor_24 WM 110.7818275484 0.0080230411 0.070859375 True | ||
a_comp_cor_25 WM 100.5105167828 0.0066042724 0.0774636474 True | ||
a_comp_cor_26 WM 94.344414343 0.0058188124 0.0832824598 True | ||
a_comp_cor_27 WM 92.150833289 0.0055513742 0.0888338339 True | ||
a_comp_cor_28 WM 90.5254087866 0.0053572629 0.0941910968 True | ||
a_comp_cor_29 WM 88.523526571 0.0051229413 0.0993140381 True | ||
a_comp_cor_30 WM 86.0931701872 0.0048455086 0.1041595467 True | ||
a_comp_cor_31 WM 84.7990437222 0.004700931 0.1088604777 True | ||
a_comp_cor_32 WM 83.3114198348 0.0045374415 0.1133979192 True | ||
a_comp_cor_33 WM 81.0694160734 0.0042965123 0.1176944314 True | ||
a_comp_cor_34 WM 80.4668446429 0.0042328795 0.121927311 True | ||
a_comp_cor_35 WM 79.4022991891 0.0041216217 0.1260489326 True | ||
a_comp_cor_36 WM 78.1613446177 0.0039937972 0.1300427299 True | ||
a_comp_cor_37 WM 77.3254517928 0.003908831 0.1339515609 True | ||
a_comp_cor_38 WM 77.0534117377 0.003881376 0.1378329369 True | ||
a_comp_cor_39 WM 76.2953999669 0.0038053856 0.1416383225 True | ||
a_comp_cor_169 combined 198.9777037853 0.0252962205 0.0252962205 True | ||
a_comp_cor_170 combined 154.343866075 0.0152203822 0.0405166027 True | ||
a_comp_cor_171 combined 144.8823205662 0.0134115075 0.0539281102 True | ||
a_comp_cor_172 combined 120.8445698188 0.0093304178 0.063258528 True | ||
a_comp_cor_173 combined 112.8109339075 0.0081310981 0.071389626 True | ||
a_comp_cor_174 combined 103.1053103638 0.0067921752 0.0781818012 True | ||
a_comp_cor_175 combined 101.536218232 0.0065870169 0.0847688181 True | ||
a_comp_cor_176 combined 94.2588177592 0.0056766326 0.0904454507 True | ||
a_comp_cor_177 combined 92.4469798367 0.0054604982 0.0959059488 True | ||
a_comp_cor_178 combined 91.5242270524 0.005352035 0.1012579839 True | ||
a_comp_cor_179 combined 89.1481999125 0.0050777576 0.1063357415 True | ||
a_comp_cor_180 combined 86.0081616799 0.0047263528 0.1110620943 True | ||
a_comp_cor_181 combined 84.3147231404 0.0045420681 0.1156041625 True | ||
a_comp_cor_182 combined 83.821614868 0.0044890956 0.1200932581 True | ||
a_comp_cor_183 combined 81.5457945837 0.0042486401 0.1243418982 True | ||
a_comp_cor_184 combined 80.7942317719 0.0041706863 0.1285125845 True | ||
a_comp_cor_185 combined 78.7768936096 0.0039650121 0.1324775965 True | ||
a_comp_cor_186 combined 77.8233137548 0.0038696015 0.1363471981 True | ||
a_comp_cor_187 combined 77.7936337977 0.0038666506 0.1402138486 True | ||
a_comp_cor_188 combined 77.0694477923 0.0037949958 0.1440088445 True |
121 changes: 121 additions & 0 deletions
121
fmriprep/interfaces/tests/data/component_metadata_renamed.tsv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
component mask singular_value variance_explained cumulative_variance_explained retained | ||
c_comp_cor_00 CSF 303.3879065215 0.0822378515 0.0822378515 True | ||
c_comp_cor_01 CSF 265.3127089823 0.0628914102 0.1451292617 True | ||
c_comp_cor_02 CSF 246.9403411402 0.0544827867 0.1996120484 True | ||
c_comp_cor_03 CSF 230.7904478523 0.0475894718 0.2472015202 True | ||
c_comp_cor_04 CSF 204.1002458456 0.0372187926 0.2844203128 True | ||
c_comp_cor_05 CSF 191.4965421158 0.0327640136 0.3171843264 True | ||
c_comp_cor_06 CSF 164.3946836008 0.0241463095 0.3413306359 True | ||
c_comp_cor_07 CSF 163.0617292465 0.023756328 0.3650869639 True | ||
c_comp_cor_08 CSF 155.6055929068 0.0216334423 0.3867204062 True | ||
c_comp_cor_09 CSF 142.6779990644 0.0181881801 0.4049085863 True | ||
c_comp_cor_10 CSF 132.7833535167 0.0157529716 0.4206615579 True | ||
c_comp_cor_11 CSF 125.5448815801 0.0140822888 0.4347438468 True | ||
c_comp_cor_12 CSF 114.4560888929 0.0117045044 0.4464483511 True | ||
c_comp_cor_13 CSF 109.7800169819 0.0107676719 0.457216023 True | ||
c_comp_cor_14 CSF 98.9016427614 0.0087394124 0.4659554354 True | ||
c_comp_cor_15 CSF 95.592760075 0.0081644179 0.4741198534 True | ||
c_comp_cor_16 CSF 93.2993710837 0.0077773682 0.4818972215 True | ||
c_comp_cor_17 CSF 89.7572859278 0.0071980465 0.489095268 True | ||
c_comp_cor_18 CSF 85.4637024159 0.0065258732 0.4956211413 True | ||
c_comp_cor_19 CSF 83.3739078155 0.0062106283 0.5018317696 True | ||
dropped0 CSF 81.1499858901 0.0058837217 0.5077154913 False | ||
dropped1 CSF 79.5953753795 0.0056604492 0.5133759405 False | ||
dropped2 CSF 77.2577614056 0.0053328512 0.5187087917 False | ||
dropped3 CSF 75.5079204435 0.0050940153 0.523802807 False | ||
dropped4 CSF 73.5288160796 0.0048304809 0.5286332879 False | ||
dropped5 CSF 71.9710349644 0.004627972 0.5332612599 False | ||
dropped6 CSF 71.5010523346 0.0045677265 0.5378289864 False | ||
dropped7 CSF 70.2484154012 0.0044090832 0.5422380695 False | ||
dropped8 CSF 68.485370616 0.0041905483 0.5464286178 False | ||
dropped9 CSF 68.1403689881 0.004148434 0.5505770518 False | ||
dropped10 CSF 66.7913214051 0.0039857981 0.5545628499 False | ||
dropped11 CSF 65.7544720308 0.0038630098 0.5584258597 False | ||
dropped12 CSF 64.9251957319 0.003766186 0.5621920457 False | ||
dropped13 CSF 63.8149558968 0.0036384815 0.5658305272 False | ||
dropped14 CSF 62.3065499093 0.0034685075 0.5692990347 False | ||
dropped15 CSF 60.5440181278 0.0032750483 0.5725740829 False | ||
dropped16 CSF 60.148632541 0.0032324122 0.5758064952 False | ||
dropped17 CSF 58.8915186625 0.0030987086 0.5789052037 False | ||
dropped18 CSF 57.6950186454 0.0029740746 0.5818792784 False | ||
dropped19 CSF 57.2791049695 0.00293135 0.5848106283 False | ||
w_comp_cor_00 WM 195.3633011611 0.0249509989 0.0249509989 True | ||
w_comp_cor_01 WM 152.0507341632 0.0151139858 0.0400649847 True | ||
w_comp_cor_02 WM 143.1829225994 0.0134024567 0.0534674414 True | ||
w_comp_cor_03 WM 119.7135045391 0.0093688925 0.0628363339 True | ||
w_comp_cor_04 WM 110.7818275484 0.0080230411 0.070859375 True | ||
w_comp_cor_05 WM 100.5105167828 0.0066042724 0.0774636474 True | ||
w_comp_cor_06 WM 94.344414343 0.0058188124 0.0832824598 True | ||
w_comp_cor_07 WM 92.150833289 0.0055513742 0.0888338339 True | ||
w_comp_cor_08 WM 90.5254087866 0.0053572629 0.0941910968 True | ||
w_comp_cor_09 WM 88.523526571 0.0051229413 0.0993140381 True | ||
w_comp_cor_10 WM 86.0931701872 0.0048455086 0.1041595467 True | ||
w_comp_cor_11 WM 84.7990437222 0.004700931 0.1088604777 True | ||
w_comp_cor_12 WM 83.3114198348 0.0045374415 0.1133979192 True | ||
w_comp_cor_13 WM 81.0694160734 0.0042965123 0.1176944314 True | ||
w_comp_cor_14 WM 80.4668446429 0.0042328795 0.121927311 True | ||
w_comp_cor_15 WM 79.4022991891 0.0041216217 0.1260489326 True | ||
w_comp_cor_16 WM 78.1613446177 0.0039937972 0.1300427299 True | ||
w_comp_cor_17 WM 77.3254517928 0.003908831 0.1339515609 True | ||
w_comp_cor_18 WM 77.0534117377 0.003881376 0.1378329369 True | ||
w_comp_cor_19 WM 76.2953999669 0.0038053856 0.1416383225 True | ||
dropped543 WM 57.974868005 0.0021972603 0.503144646 False | ||
dropped544 WM 57.8953856222 0.0021912396 0.5053358856 False | ||
dropped545 WM 57.8412263429 0.0021871419 0.5075230275 False | ||
dropped546 WM 57.712694931 0.0021774324 0.5097004598 False | ||
dropped547 WM 57.6881631871 0.0021755817 0.5118760415 False | ||
dropped548 WM 57.5332376458 0.002163912 0.5140399535 False | ||
dropped549 WM 57.4248728403 0.0021557681 0.5161957217 False | ||
dropped550 WM 57.2839446853 0.0021452001 0.5183409217 False | ||
dropped551 WM 57.2749923068 0.0021445296 0.5204854513 False | ||
dropped552 WM 57.2083731386 0.0021395437 0.522624995 False | ||
dropped553 WM 57.1224483551 0.0021331215 0.5247581165 False | ||
dropped554 WM 57.0580867294 0.0021283173 0.5268864338 False | ||
dropped555 WM 56.8779500159 0.0021149 0.5290013338 False | ||
dropped556 WM 56.6491198238 0.002097917 0.5310992508 False | ||
dropped557 WM 56.5919145056 0.0020936821 0.5331929329 False | ||
dropped558 WM 56.5520028524 0.00209073 0.5352836629 False | ||
dropped559 WM 56.4734227579 0.0020849238 0.5373685867 False | ||
dropped560 WM 56.3868665406 0.0020785376 0.5394471243 False | ||
dropped561 WM 56.3074826046 0.0020726892 0.5415198135 False | ||
dropped562 WM 56.1904069084 0.002064079 0.5435838926 False | ||
a_comp_cor_00 combined 198.9777037853 0.0252962205 0.0252962205 True | ||
a_comp_cor_01 combined 154.343866075 0.0152203822 0.0405166027 True | ||
a_comp_cor_02 combined 144.8823205662 0.0134115075 0.0539281102 True | ||
a_comp_cor_03 combined 120.8445698188 0.0093304178 0.063258528 True | ||
a_comp_cor_04 combined 112.8109339075 0.0081310981 0.071389626 True | ||
a_comp_cor_05 combined 103.1053103638 0.0067921752 0.0781818012 True | ||
a_comp_cor_06 combined 101.536218232 0.0065870169 0.0847688181 True | ||
a_comp_cor_07 combined 94.2588177592 0.0056766326 0.0904454507 True | ||
a_comp_cor_08 combined 92.4469798367 0.0054604982 0.0959059488 True | ||
a_comp_cor_09 combined 91.5242270524 0.005352035 0.1012579839 True | ||
a_comp_cor_10 combined 89.1481999125 0.0050777576 0.1063357415 True | ||
a_comp_cor_11 combined 86.0081616799 0.0047263528 0.1110620943 True | ||
a_comp_cor_12 combined 84.3147231404 0.0045420681 0.1156041625 True | ||
a_comp_cor_13 combined 83.821614868 0.0044890956 0.1200932581 True | ||
a_comp_cor_14 combined 81.5457945837 0.0042486401 0.1243418982 True | ||
a_comp_cor_15 combined 80.7942317719 0.0041706863 0.1285125845 True | ||
a_comp_cor_16 combined 78.7768936096 0.0039650121 0.1324775965 True | ||
a_comp_cor_17 combined 77.8233137548 0.0038696015 0.1363471981 True | ||
a_comp_cor_18 combined 77.7936337977 0.0038666506 0.1402138486 True | ||
a_comp_cor_19 combined 77.0694477923 0.0037949958 0.1440088445 True | ||
dropped957 combined 58.498983616 0.0021864696 0.5028418222 False | ||
dropped958 combined 58.4583451584 0.0021834329 0.5050252551 False | ||
dropped959 combined 58.4084551025 0.0021797076 0.5072049627 False | ||
dropped960 combined 58.358803729 0.0021760034 0.5093809661 False | ||
dropped961 combined 58.0957193109 0.0021564286 0.5115373947 False | ||
dropped962 combined 57.9803871837 0.0021478751 0.5136852698 False | ||
dropped963 combined 57.9333367991 0.0021443906 0.5158296604 False | ||
dropped964 combined 57.8646604218 0.0021393095 0.51796897 False | ||
dropped965 combined 57.8129529833 0.0021354879 0.5201044579 False | ||
dropped966 combined 57.6361694545 0.0021224479 0.5222269057 False | ||
dropped967 combined 57.5798626323 0.0021183029 0.5243452086 False | ||
dropped968 combined 57.529751472 0.0021146174 0.526459826 False | ||
dropped969 combined 57.4223094632 0.0021067263 0.5285665523 False | ||
dropped970 combined 57.386187055 0.0021040766 0.5306706289 False | ||
dropped971 combined 57.1828951485 0.0020891955 0.5327598245 False | ||
dropped972 combined 57.1115317726 0.0020839842 0.5348438087 False | ||
dropped973 combined 56.9748270267 0.0020740195 0.5369178282 False | ||
dropped974 combined 56.9346930627 0.0020710986 0.5389889268 False | ||
dropped975 combined 56.9038934374 0.0020688584 0.5410577853 False | ||
dropped976 combined 56.7830846208 0.0020600833 0.5431178685 False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a docstring here?