Skip to content

Commit

Permalink
[DOC] Improve logging of component table-based manual classification (#…
Browse files Browse the repository at this point in the history
…852)

* Update tedana.py

* Test manual classification using comptable.

* Change clfs in five-echo manual clf test.

* Fix the test.

* Update test_integration.py
  • Loading branch information
tsalo authored Mar 28, 2022
1 parent 65e8ddf commit f42ba63
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
50 changes: 44 additions & 6 deletions tedana/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ def download_test_data(osf, outpath):


def test_integration_five_echo(skip_integration):
"""Integration test of the full tedana workflow using five-echo test data"""
"""Integration test of the full tedana workflow using five-echo test data."""

if skip_integration:
pytest.skip("Skipping five-echo integration test")

out_dir = "/tmp/data/five-echo/TED.five-echo"
out_dir_manual = "/tmp/data/five-echo/TED.five-echo-manual"

if os.path.exists(out_dir):
shutil.rmtree(out_dir)

if os.path.exists(out_dir_manual):
shutil.rmtree(out_dir_manual)

# download data and run the test
download_test_data("https://osf.io/9c42e/download", os.path.dirname(out_dir))
prepend = "/tmp/data/five-echo/p06.SBJ01_S09_Task11_e"
Expand All @@ -103,8 +109,7 @@ def test_integration_five_echo(skip_integration):
assert isinstance(df, pd.DataFrame)

# Test re-running, but use the CLI
out_dir2 = "/tmp/data/five-echo/TED.five-echo-manual"
acc_comps = df.loc[df["classification"] == "accepted"].index.values
acc_comps = df.loc[df["classification"] == "ignored"].index.values
acc_comps = [str(c) for c in acc_comps]
mixing = os.path.join(out_dir, "desc-ICA_mixing.tsv")
t2smap = os.path.join(out_dir, "T2starmap.nii.gz")
Expand All @@ -115,7 +120,7 @@ def test_integration_five_echo(skip_integration):
+ [str(te) for te in echo_times]
+ [
"--out-dir",
out_dir2,
out_dir_manual,
"--debug",
"--verbose",
"--manacc",
Expand All @@ -140,10 +145,16 @@ def test_integration_four_echo(skip_integration):

if skip_integration:
pytest.skip("Skipping four-echo integration test")

out_dir = "/tmp/data/four-echo/TED.four-echo"
out_dir_manual = "/tmp/data/four-echo/TED.four-echo-manual"

if os.path.exists(out_dir):
shutil.rmtree(out_dir)

if os.path.exists(out_dir_manual):
shutil.rmtree(out_dir_manual)

# download data and run the test
download_test_data("https://osf.io/gnj73/download", os.path.dirname(out_dir))
prepend = "/tmp/data/four-echo/"
Expand All @@ -161,8 +172,30 @@ def test_integration_four_echo(skip_integration):
verbose=True,
)

# Test re-running with the component table
mixing_matrix = os.path.join(out_dir, "desc-ICA_mixing.tsv")
comptable = os.path.join(out_dir, "desc-tedana_metrics.tsv")
temporary_comptable = os.path.join(out_dir, "temporary_metrics.tsv")
comptable_df = pd.read_table(comptable)
comptable_df.loc[comptable_df["classification"] == "ignored", "classification"] = "accepted"
comptable_df.to_csv(temporary_comptable, sep="\t", index=False)
tedana_cli.tedana_workflow(
data=datalist,
tes=[11.8, 28.04, 44.28, 60.52],
out_dir=out_dir_manual,
tedpca="kundu-stabilize",
gscontrol=["gsr", "mir"],
png_cmap="bone",
mixm=mixing_matrix,
ctab=temporary_comptable,
debug=True,
verbose=False,
)
os.remove(temporary_comptable)

# compare the generated output files
fn = resource_filename("tedana", "tests/data/fiu_four_echo_outputs.txt")

check_integration_outputs(fn, out_dir)


Expand All @@ -171,11 +204,16 @@ def test_integration_three_echo(skip_integration):

if skip_integration:
pytest.skip("Skipping three-echo integration test")

out_dir = "/tmp/data/three-echo/TED.three-echo"
out_dir2 = "/tmp/data/three-echo/TED.three-echo-rerun"
out_dir_manual = "/tmp/data/three-echo/TED.three-echo-rerun"

if os.path.exists(out_dir):
shutil.rmtree(out_dir)

if os.path.exists(out_dir_manual):
shutil.rmtree(out_dir_manual)

# download data and run the test
download_test_data("https://osf.io/rqhfc/download", os.path.dirname(out_dir))
tedana_cli.tedana_workflow(
Expand All @@ -195,7 +233,7 @@ def test_integration_three_echo(skip_integration):
"38.5",
"62.5",
"--out-dir",
out_dir2,
out_dir_manual,
"--debug",
"--verbose",
"--ctab",
Expand Down
1 change: 1 addition & 0 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ def tedana_workflow(
)
comptable, metric_metadata = selection.kundu_selection_v2(comptable, n_echos, n_vols)
else:
LGR.info("Using supplied component table for classification")
comptable = pd.read_table(ctab)
# Change rationale value of rows with NaN to empty strings
comptable.loc[comptable.rationale.isna(), "rationale"] = ""
Expand Down

0 comments on commit f42ba63

Please sign in to comment.