Skip to content

Commit

Permalink
Merge pull request #2 from PennLINC/enh/conform_metadata
Browse files Browse the repository at this point in the history
Enh/conform metadata
  • Loading branch information
smeisler authored Sep 4, 2024
2 parents ccd8fd1 + bd2bcd3 commit e229205
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 48 deletions.
50 changes: 15 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,25 @@
A tool for ingressing outputs from other processing pipelines (e.g., HCP, UKB) for use in QSIRecon.

## Overview
Your description here
This tool can be used to import data from bespoke and widely-used DWI preprocessing pipelines (e.g., Human Connectome Project and UK Biobank) into QSIRecon for post-processing.

## Usage
This project is set up using poetry. To install the dependencies, run `poetry install` from the root of the project.

```shell
poetry install
## Installation
This project can be installed via PyPi. In your virtual environment run
```

To add a new dependency, run `poetry add <dependency>` from the root of the project.

```shell
poetry add <dependency>
pip install Ingress2QSIRecon
```

### Pre-Commit Hooks
This project uses [pre-commit](https://pre-commit.com/) to run linting and formatting tools before each commit. To install the pre-commit hooks, run `pre-commit install` from the root of the project.

```shell
poetry run pre-commit install
For the master/development branch, you can clone the github repo, and run from within it:
```

To run the pre-commit hooks manually, run `pre-commit run --all-files` from the root of the project.

```shell
poetry run pre-commit run --all-files
pip install -e .
```


### Testing
This project uses [pytest](https://docs.pytest.org/en/stable/) for testing. To run the tests, run `pytest` from the root of the project in the poetry shell.

```shell
poetry run pytest
```

There are sensible defaults for pytest setup in the `pyproject.toml` file. You can override these defaults by passing in command line arguments. For example, to run the tests with debug logging enabled, run `pytest --log-cli-level=DEBUG` from the root of the project.

```shell
poetry run pytest --log-cli-level=DEBUG
## Usage
Assuming you have the data to ingress locally availble, you can run the following:
```

ingress2qsirecon \
/PATH/TO/INPUT/DATA \ # E.g., path to HCP1200 directory
/PATH/TO/OUTPUT \ # BIDS directory with ingressed data will be made here
PIPELINE_NAME \ # Currently support "hcpya" and "ukb" \
-w /PATH/TO/WORKING/DIR \ # Where intermediate files and workflow information will be stored
--participant-label 100307 # Name(s) of folder within /PATH/TO/INPUT/DATA. If not specified, will process everyone
```
20 changes: 20 additions & 0 deletions ingress2qsirecon/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from pathlib import Path
from warnings import warn

import nibabel as nb

# Files: file paths relative to subject input folder
# MNI: MNI template version
# DIR_PATTERN: regex pattern for subject ID within input folder
Expand Down Expand Up @@ -109,13 +111,15 @@ def make_bids_file_paths(subject_layout: dict) -> dict:
bids_bval_file = os.path.join(bids_base, "dwi", sub_session_string + "_dwi.bval")
bids_bvec_file = os.path.join(bids_base, "dwi", sub_session_string + "_dwi.bvec")
bids_b_file = os.path.join(bids_base, "dwi", sub_session_string + "_dwi.b")
bids_bmtxt_file = os.path.join(bids_base, "dwi", sub_session_string + "_dwi.bmtxt")
bids_dwiref_file = os.path.join(bids_base, "dwi", sub_session_string + "_dwiref.nii.gz")

bids_file_paths = {
"bids_dwi": Path(bids_dwi_file),
"bids_bvals": Path(bids_bval_file),
"bids_bvecs": Path(bids_bvec_file),
"bids_b": Path(bids_b_file),
"bids_bmtxt": Path(bids_bmtxt_file),
"bids_dwiref": Path(bids_dwiref_file),
}

Expand Down Expand Up @@ -228,3 +232,19 @@ def create_layout(input_dir: Path, output_dir: Path, input_pipeline: str, partic
raise ValueError("No subjects found in layout.")

return layout


def to_lps(input_img, new_axcodes=("L", "P", "S")):
if isinstance(input_img, str):
input_img = nb.load(input_img)
input_axcodes = nb.aff2axcodes(input_img.affine)
# Is the input image oriented how we want?
if not input_axcodes == new_axcodes:
# Re-orient
input_orientation = nb.orientations.axcodes2ornt(input_axcodes)
desired_orientation = nb.orientations.axcodes2ornt(new_axcodes)
transform_orientation = nb.orientations.ornt_transform(input_orientation, desired_orientation)
reoriented_img = input_img.as_reoriented(transform_orientation)
return reoriented_img
else:
return input_img
Loading

0 comments on commit e229205

Please sign in to comment.