diff --git a/ingress2qsirecon/utils/interfaces.py b/ingress2qsirecon/utils/interfaces.py index 2e423bc..e41386c 100644 --- a/ingress2qsirecon/utils/interfaces.py +++ b/ingress2qsirecon/utils/interfaces.py @@ -3,11 +3,10 @@ """ import os +import pandas as pd import shutil -import tempfile from textwrap import indent -import itk import nibabel as nb import numpy as np import SimpleITK as sitk @@ -609,3 +608,38 @@ def _convert_fsl_to_mrtrix(bval_file, bvec_file, output_fname): vals = np.loadtxt(bval_file) gtab = np.column_stack([vecs.T, vals]) * np.array([-1, -1, 1, 1]) np.savetxt(output_fname, gtab, fmt=["%.8f", "%.8f", "%.8f", "%d"]) + +class _ScansTSVWriterInputSpec(BaseInterfaceInputSpec): + filenames = traits.List(traits.Str, mandatory=True, desc="List of filenames") + source_files = traits.List(traits.Str, mandatory=True, desc="List of source files") + out_file = File("output.tsv", usedefault=True, desc="Output TSV file") + +class _ScansTSVWriterOutputSpec(TraitedSpec): + out_file = File(desc="Output TSV file") + +class ScansTSVWriter(BaseInterface): + input_spec = _ScansTSVWriterInputSpec + output_spec = _ScansTSVWriterOutputSpec + + def _run_interface(self, runtime): + filenames = self.inputs.filenames + source_files = self.inputs.source_files + + # Check if lengths match + if len(filenames) != len(source_files): + raise ValueError("filenames and source_files must have the same length") + + # Create DataFrame + df = pd.DataFrame({ + "filename": filenames, + "source_file": source_files + }) + + # Write to TSV + df.to_csv(self.inputs.out_file, sep='\t', index=False) + return runtime + + def _list_outputs(self): + outputs = self.output_spec().get().copy() + outputs['out_file'] = self.inputs.out_file + return outputs \ No newline at end of file diff --git a/ingress2qsirecon/utils/workflows.py b/ingress2qsirecon/utils/workflows.py index c03d91a..a5e6a6d 100644 --- a/ingress2qsirecon/utils/workflows.py +++ b/ingress2qsirecon/utils/workflows.py @@ -3,7 +3,6 @@ """ import os -import shutil from pathlib import Path from nipype.pipeline.engine import Workflow diff --git a/pyproject.toml b/pyproject.toml index 5b3dd9b..db57b4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "Ingress2QSIRecon" -version = "0.1.0" +version = "0.1.1" description = "Tool to ingress data from other pipelines for use in QSIRecon" authors = ["Steven Meisler "] readme = "README.md" @@ -18,9 +18,11 @@ loguru = "^0.7.2" nibabel = "^5.2.1" nilearn = "^0.10.4" nipype = "^1.8.6" +niworkflows = "^1.11.0" pydantic = "^2.8" python = "^3.10" SimpleITK = "^2.4.0" +templateflow = "^24.2.0" [tool.poetry.urls] homepage = "https://github.com/PennLINC/ingress2qsirecon"