Skip to content

Commit

Permalink
updated matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
n-sinha committed Nov 16, 2024
1 parent 7330932 commit 206f563
Show file tree
Hide file tree
Showing 15 changed files with 1,313 additions and 299 deletions.
34 changes: 34 additions & 0 deletions MATLAB/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
test/*
config_iEEGrecon.m

# Windows default autosave extension
*.asv

# OSX / *nix default autosave extension
*.m~

# Compiled MEX binaries (all platforms)
*.mex*

# Packaged app and toolbox files
*.mlappinstall
*.mltbx

# Generated helpsearch folders
helpsearch*/

# Simulink code generation folders
slprj/
sccprj/

# Matlab code generation folders
codegen/

# Simulink autosave extension
*.autosave

# Simulink cache files
*.slxc

# Octave session info
octave-workspace
43 changes: 43 additions & 0 deletions MATLAB/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others’ private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
66 changes: 66 additions & 0 deletions MATLAB/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Contributing to iEEG Implant Reconstruction Pipeline

Thank you for considering contributing to the iEEG Implant Reconstruction Pipeline! We welcome contributions from the community to help improve the project.

## How to Contribute

### Reporting Issues

If you encounter any bugs or have suggestions for improvements, please use the [GitHub Issue Tracker](https://github.com/username/iEEG_implant_reconstruction/issues) to report them. When reporting an issue, please include:

- A clear and descriptive title
- A detailed description of the problem or suggestion
- Steps to reproduce the issue (if applicable)
- Any relevant error messages or screenshots

### Proposing Changes

If you have an idea for a new feature or an improvement, we encourage you to discuss it with us first. You can do this by opening a new issue or starting a discussion in the existing issues.

### Submitting Pull Requests

If you are ready to contribute code, please follow these steps:

1. **Fork the Repository**: Create a personal fork of the repository on GitHub.

2. **Clone the Fork**: Clone your fork to your local machine.

```bash
git clone https://github.com/your-username/iEEG_implant_reconstruction.git
```

3. **Create a Branch**: Create a new branch for your changes.

```bash
git checkout -b feature/your-feature-name
```

4. **Make Changes**: Implement your changes in the new branch.

5. **Test Your Changes**: Ensure that your changes work as expected and do not break existing functionality.

6. **Commit Your Changes**: Commit your changes with a descriptive commit message.

```bash
git commit -m "Add feature: your feature description"
```

7. **Push to Your Fork**: Push your changes to your fork on GitHub.

```bash
git push origin feature/your-feature-name
```

8. **Submit a Pull Request**: Go to the original repository and submit a pull request. Please provide a clear description of your changes and reference any related issues.

### Code Style

Please follow the existing code style and conventions used in the project. Consistency helps maintain readability and ease of maintenance.

### Code of Conduct

By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md).

## Thank You!

We appreciate your contributions and efforts to improve the iEEG Implant Reconstruction Pipeline. If you have any questions, feel free to reach out to the maintainers through the issue tracker.
21 changes: 21 additions & 0 deletions MATLAB/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Nishant Sinha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
176 changes: 171 additions & 5 deletions MATLAB/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,174 @@
# iEEG_implant_reconstruction
# iEEG Implant Reconstruction Pipeline

## Startup
* Make sure that FSL is setup properly and added to the shell profile.
A MATLAB-based pipeline for reconstructing intracranial EEG (iEEG) electrode locations from post-implant CT and pre-implant MRI scans.

## Download example data
## Overview

* To test the codes, download example data and put it in this directory: [Dropbox](https://www.dropbox.com/sh/ylxc586grm0p7au/AAAs8QQwUo0VQOSweDyj1v_ta?dl=0)
This pipeline provides tools for:
- Extracting electrode coordinates from post-implant CT scans
- Co-registering CT and MRI images
- Mapping electrodes to anatomical regions
- Quality assurance visualization

## Prerequisites

### Required Software
- MATLAB (version 2019b or later recommended)
- FSL (FMRIB Software Library)
- ITK-SNAP
- FreeSurfer

### System Requirements
- Operating System: Linux/Unix (recommended), macOS, or Windows with Unix subsystem
- RAM: 8GB minimum, 16GB recommended
- Storage: At least 10GB free space for processing

## Installation

1. Clone this repository:
```bash
git clone https://github.com/username/iEEG_implant_reconstruction.git
```

2. Add FSL to your shell profile:
```bash
export FSLDIR=/path/to/fsl
source ${FSLDIR}/etc/fslconf/fsl.sh
export PATH=${FSLDIR}/bin:${PATH}
```

3. Configure paths in `config_iEEGrecon.m`

## Configuration Example

After cloning the repository and setting up the required software, you need to configure the paths in `config_iEEGrecon.m`. Below is an example configuration:

```matlab
%% Set external library in path
addpath(genpath('/path/to/your/dependencies'))
%% FSL Setup
setenv('FSLDIR', '/path/to/fsl');
setenv('FSLOUTPUTTYPE', 'NIFTI_GZ');
fsldir = getenv('FSLDIR');
fsldirmpath = sprintf('%s/etc/matlab', fsldir);
path(path, fsldirmpath);
clear fsldir fsldirmpath;
%% ITK Snap Setup
setenv('ITKSNAPDIR', '/path/to/ITK-SNAP');
itksnapdir = getenv('ITKSNAPDIR');
itksnapmpath = sprintf('%s', itksnapdir);
path(path, itksnapmpath);
clear itksnapdir itksnapmpath;
%% Freesurfer setup
setenv('FREESURFER_HOME', '/path/to/freesurfer');
setenv('SUBJECTS_DIR', '/path/to/your/subjects_dir');
FREESURFER_HOME = getenv('FREESURFER_HOME');
freesurferdirmpath = sprintf('%s/SetUpFreeSurfer.sh', FREESURFER_HOME);
system(['sh ' freesurferdirmpath], '-echo');
clear freesurferdirmpath FREESURFER_HOME;
```

Make sure to replace `/path/to/your/dependencies`, `/path/to/fsl`, `/path/to/ITK-SNAP`, `/path/to/freesurfer`, and `/path/to/your/subjects_dir` with the actual paths on your system.


## Usage

### Module 1: Electrode Coordinate Export
This module extracts electrode coordinates from post-implant CT scans in both voxel and native space.

```matlab
% Initialize the pipeline object
obj = iEEGReconPipeline();
% Run Module 1
obj.module1();
```

### Module 2: Image Registration
This module performs CT-MRI co-registration. You can choose between:
- Greedy registration with image centering (`'gc'`)
- FLIRT registration fine-tuned with greedy (`'g'`)

```matlab
% Run Module 2 with greedy registration and no visualization
fileLocations = obj.module2('gc', false);
```

### Module 3: ROI Mapping
This module maps electrodes to anatomical regions using an atlas.

```matlab
% Run Module 3
obj.module3();
```

### Notes
- Ensure that all input files are correctly placed in the expected directories before running the modules.
- Adjust the parameters as needed for your specific dataset and analysis requirements.


## Data Structure

### Input Files
- **Pre-implant MRI scan (T1-weighted):** Required for anatomical reference.
- **Post-implant CT scan:** Used to locate electrode positions.
- **Electrode coordinates file:** Contains initial electrode positions.
- **Atlas file (optional):** Used for mapping electrodes to anatomical regions.
- **Lookup table (optional):** Provides additional mapping information.

### Output Structure
The pipeline generates the following output files organized by module:

```
ieeg_recon/
├── module1/
│ ├── electrode_names.txt # List of electrode names
│ ├── electrodes_inCTvox.txt # Electrode coordinates in CT voxel space
│ └── electrodes_inCTmm.txt # Electrode coordinates in CT millimeter space
├── module2/
│ ├── ct_to_mri.nii.gz # Registered CT to MRI image
│ ├── electrodes_inMRI.nii.gz # Electrode positions in MRI space
│ └── QA_registration_.png # Quality assurance image for registration
└── module3/
└── electrodes2ROI.csv # Mapping of electrodes to regions of interest
```

### Notes
- Ensure that input files are correctly formatted and placed in the expected directories before running the pipeline.
- The output files are organized by module to facilitate easy access and analysis.

## Example Data

Example data is available for testing: [download](https://www.dropbox.com/sh/ylxc586grm0p7au/AAAs8QQwUo0VQOSweDyj1v_ta?dl=0)

## Quality Assurance

The pipeline includes built-in quality assurance tools:
- Registration quality checks
- Electrode placement verification
- Visual inspection tools

## Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Citation

If you use this software in your research, please cite:

> **Lucas A, Scheid BH, Pattnaik AR, Gallagher R, Mojena M, Tranquille A, Prager B, Gleichgerrcht E, Gong R, Litt B, Davis KA, Das S, Stein JM, Sinha N. iEEG-recon: A fast and scalable pipeline for accurate reconstruction of intracranial electrodes and implantable devices. Epilepsia. 2024 Mar;65(3):817-829. doi: 10.1111/epi.17863. Epub 2024 Jan 10. PMID: 38148517; PMCID: PMC10948311.**
## Support

For bug reports and feature requests, please use the [GitHub Issue Tracker](https://github.com/username/iEEG_implant_reconstruction/issues).
Loading

0 comments on commit 206f563

Please sign in to comment.