Welcome to adnipy’s documentation!¶
adnipy¶
Process ADNI study data with adnipy.
Adnipy is a python package designed for working with the ADNI database. It also offers some handy tools for file operations.
- Free software: MIT license
- Documentation: https://adnipy.readthedocs.io
Credits¶
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Installation¶
Stable release¶
To install adnipy, run this command in your terminal:
$ pip install adnipy
This is the preferred method to install adnipy, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for adnipy can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/mcsitter/adnipy
Or download the tarball:
$ curl -OL https://github.com/mcsitter/adnipy/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
adnipy¶
adnipy package¶
Submodules¶
adnipy.adni module¶
Pandas dataframe extension for ADNI.
-
class
adnipy.adni.
ADNI
(pandas_dataframe)[source]¶ Bases:
object
Dataframe deals with ADNI data.
This class presents methods, which are designed to work with data from the ADNI database.
-
DATES
= ['Acq Date', 'Downloaded', 'EXAMDATE', 'EXAMDATE_bl', 'update_stamp', 'USERDATE', 'update_stamp', 'USERDATE', 'USERDATE2', 'SCANDATE', 'TAUTRANDT', 'update_stamp', 'USERDATE', 'USERDATE2', 'SCANDATE', 'TRANDATE', 'update_stamp']¶
-
INDEX
= ['Subject ID', 'Image ID']¶
-
MAPPER
= {'ASSAYTIME': 'TAUTIME', 'Acq Date': 'SCANDATE', 'Image': 'Image ID', 'Image Data ID': 'Image ID', 'PTID': 'Subject ID', 'Subject': 'Subject ID'}¶
-
drop_dynamic
()[source]¶ Remove images which are dynamic.
Drops all rows, in which the Description contains ‘Dynamic’.
Returns: All images that are not dynamic. Return type: pd.DataFrame
-
groups
(grouped_mci=True)[source]¶ Create a dataframe for each group and save it to a csv file.
Parameters: grouped_mci (bool, default True) – If true, ‘LMCI’ and ‘EMCI’ are treated like ‘MCI’. However, the original values will stills be in the output. Returns: Dictionnairy with a dataframe for each group. Return type: dict
-
longitudinal
()[source]¶ Keep only longitudinal data.
This requires an ‘RID’ or ‘Subject ID’ column in the dataframe. Do not use if multiple images are present for a single timepoint.
Parameters: images (pd.DataFrame) – This dataframe will be modified. Returns: A dataframe with only longitudinal data. Return type: pd.DataFrame See also
-
rid
()[source]¶ Add a roster ID column.
Will not work if ‘RID’ is already present or ‘Subject ID’ is missing.
Returns: Dataframe with a ‘RID’ column. Return type: pd.DataFrame Examples
>>> subjects = {"Subject ID": ["100_S_1000", "101_S_1001"]} >>> collection = pd.DataFrame(subjects) >>> collection Subject ID 0 100_S_1000 1 101_S_1001 >>> collection.adni.rid() Subject ID RID 0 100_S_1000 1000 1 101_S_1001 1001
-
standard_column_names
()[source]¶ Rename dataframe columns to module standard.
This function helps when working with multiple dataframes, since the same data can have different names. It will also call rid() on the dataframe.
Returns: This will have standardized columns names. Return type: pd.DataFrame See also
Examples
>>> subjects = pd.DataFrame({"Subject": ["101_S_1001", "102_S_1002"]}) >>> subjects Subject 0 101_S_1001 1 102_S_1002 >>> subjects.adni.standard_column_names() "VISCODE2" not included. Subject ID RID 0 101_S_1001 1001 1 102_S_1002 1002
>>> images = pd.DataFrame({"Image": [100001, 100002]}) >>> images Image 0 100001 1 100002 >>> images.adni.standard_column_names() "VISCODE2" not included. Image ID 0 100001 1 100002
-
standard_dates
()[source]¶ Change type of date columns to datetime.
Returns: Dates will have the appropriate dtype. Return type: pd.DataFrame
-
standard_index
(index=None)[source]¶ Process dataframes into a standardized format.
The output is easy to read. Applying functions the the output may not work as expected.
Parameters: index (list of str, default None) – These columns will be the new index. Returns: An easy to read dataframe for humans. Return type: pd.DataFrame
-
adnipy.adnipy module¶
Process ADNI study data with adnipy.
-
adnipy.adnipy.
get_matching_images
(left, right)[source]¶ Match different scan types based on closest date.
The columns ‘Subject ID’ and ‘SCANDATE’ are required.
Parameters: - left (pd.DataFrame) – Dataframe containing the tau scans.
- right (pd.DataFrame) – Dataframe containing the mri scans.
Returns: For each timepoint there is a match from both inputs.
Return type: pd.DataFrame
-
adnipy.adnipy.
read_csv
(file)[source]¶ Return a csv file as a pandas.DataFrame.
Recognizes missing values used in the ADNI database.
Parameters: file (str, pathlib.Path) – The path to the .csv file. Returns: Returns the file as a dataframe. Return type: pd.DataFrame See also
standard_column_names()
,standard_dates()
,standard_index()
adnipy.data module¶
Process data created in Matlab.
-
adnipy.data.
image_id_from_filename
(filename)[source]¶ Extract image ID of single ADNI .nii filename.
Images from the ADNI database have a specific formatting. Using regular expressions the image ID can be extracted from filenames.
Parameters: filename (str) – It must contain the Image ID at the end. Returns: Image as a integer. Return type: numpy.int64 Examples
>>> image_id_from_filename("*_I123456.nii") 123456
Module contents¶
Process ADNI study data with adnipy.
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/mcsitter/adnipy/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
adnipy could always use more documentation, whether as part of the official adnipy docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/mcsitter/adnipy/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up adnipy for local development.
Fork the adnipy repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/adnipy.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv adnipy $ cd adnipy/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 adnipy tests $ python setup.py test or py.test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 3.5, 3.6, 3.7 and 3.8. Check https://travis-ci.org/mcsitter/adnipy/pull_requests and make sure that the tests pass for all supported Python versions.
Deploying¶
A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:
$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags
Travis will then deploy to PyPI if tests pass.
Credits¶
Development Lead¶
- Maximilian Cosmo Sitter <msitter@smail.uni-koeln.de>
Contributors¶
None yet. Why not be the first?