Skip to content

Commit

Permalink
Merge pull request #5 from PennLINC/enh/acres
Browse files Browse the repository at this point in the history
Use acres for loading package data
  • Loading branch information
smeisler authored Sep 13, 2024
2 parents 381deaa + 31ec34a commit 56752c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ingress2qsirecon/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from beartype import beartype

import ingress2qsirecon
from ingress2qsirecon.cli.parser import _build_parser
from ingress2qsirecon.data import load_resource
from ingress2qsirecon.utils.functions import create_layout
from ingress2qsirecon.utils.workflows import create_ingress2qsirecon_wf

Expand Down Expand Up @@ -43,9 +43,9 @@ def _ingress2qsirecon(**kwargs):
output_dir.mkdir(parents=True)

# Move BIDS scaffold files to output directory
ingress2recon_dir = os.path.dirname(ingress2qsirecon.__file__)
bids_scaffold = str(load_resource('bids_scaffold/'))
if not os.path.exists(os.path.join(output_dir, "dataset_description.json")):
shutil.copytree(os.path.join(ingress2recon_dir, "data", "bids_scaffold"), output_dir, dirs_exist_ok=True)
shutil.copytree(bids_scaffold, output_dir, dirs_exist_ok=True)

# If participant_label not defined, make it empty list
if participant_label is None:
Expand Down
14 changes: 14 additions & 0 deletions ingress2qsirecon/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''Data package
.. autofunction:: load_resource
.. automethod:: load_resource.readable
.. automethod:: load_resource.as_path
.. automethod:: load_resource.cached
'''

from acres import Loader

load_resource = Loader(__package__)
12 changes: 6 additions & 6 deletions ingress2qsirecon/utils/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""

import os
import pandas as pd
import shutil
from textwrap import indent

import nibabel as nb
import numpy as np
import pandas as pd
import SimpleITK as sitk
from nilearn import image as nim
from nipype import logging
Expand Down Expand Up @@ -609,14 +609,17 @@ def _convert_fsl_to_mrtrix(bval_file, bvec_file, output_fname):
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
Expand All @@ -630,10 +633,7 @@ def _run_interface(self, runtime):
raise ValueError("filenames and source_files must have the same length")

# Create DataFrame
df = pd.DataFrame({
"filename": filenames,
"source_file": source_files
})
df = pd.DataFrame({"filename": filenames, "source_file": source_files})

# Write to TSV
df.to_csv(self.inputs.out_file, sep='\t', index=False)
Expand All @@ -642,4 +642,4 @@ def _run_interface(self, runtime):
def _list_outputs(self):
outputs = self.output_spec().get().copy()
outputs['out_file'] = self.inputs.out_file
return outputs
return outputs
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Ingress2QSIRecon"
version = "0.1.3"
version = "0.1.4"
description = "Tool to ingress data from other pipelines for use in QSIRecon"
authors = ["Steven Meisler <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 56752c3

Please sign in to comment.