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
Methods
drop_dynamic
(self)Remove images which are dynamic. groups
(self[, grouped_mci])Create a dataframe for each group and save it to a csv file. longitudinal
(self)Keep only longitudinal data. rid
(self)Add a roster ID column. standard_column_names
(self)Rename dataframe columns to module standard. standard_dates
(self)Change type of date columns to datetime. standard_index
(self[, index])Process dataframes into a standardized format. timepoints
(self[, second])Extract timepoints from a dataframe. -
drop_dynamic
(self)[source]¶ Remove images which are dynamic.
Drops all rows, in which the Description contains ‘Dynamic’.
Returns: - pd.DataFrame
All images that are not dynamic.
-
groups
(self, 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: - dict
Dictionnairy with a dataframe for each group.
-
longitudinal
(self)[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: - pd.DataFrame
A dataframe with only longitudinal data.
See also
-
rid
(self)[source]¶ Add a roster ID column.
Will not work if ‘RID’ is already present or ‘Subject ID’ is missing.
Returns: - pd.DataFrame
Dataframe with a ‘RID’ column.
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.rid() Subject ID RID 0 100_S_1000 1000 1 101_S_1001 1001
-
standard_column_names
(self)[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: - pd.DataFrame
This will have standardized columns names.
See also
Examples
>>> subjects = pd.DataFrame({"Subject": ["101_S_1001", "102_S_1002"]}) >>> subjects Subject 0 101_S_1001 1 102_S_1002 >>> subjects.standard_column_names() 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.standard_column_names() Image ID 0 100001 1 100002
-
standard_dates
(self)[source]¶ Change type of date columns to datetime.
Returns: - pd.DataFrame
Dates will have the appropriate dtype.
-
standard_index
(self, 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: - pd.DataFrame
An easy to read dataframe for humans.
-
adnipy.adnipy module¶
Process ADNI study data with adnipy.
-
adnipy.adnipy.
drop_dynamic
(images)[source]¶ Remove images which are dynamic.
Drops all rows, in which the Description contains ‘Dynamic’.
Parameters: - images : pd.DataFrame
This dataframe will be modified.
Returns: - pd.DataFrame
All images that are not dynamic.
-
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: - pd.DataFrame
For each timepoint there is a match from both inputs.
-
adnipy.adnipy.
groups
(collection, grouped_mci=True)[source]¶ Create a dataframe for each group and save it to a csv file.
Parameters: - collection : pd.DataFrame
DataFrame has to have a Group column.
- 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: - dict
Dictionnairy with a dataframe for each group.
-
adnipy.adnipy.
longitudinal
(images)[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: - pd.DataFrame
A dataframe with only longitudinal data.
See also
-
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: - pd.DataFrame
Returns the file as a dataframe.
-
adnipy.adnipy.
rid
(collection)[source]¶ Add a roster ID column.
Will not work if ‘RID’ is already present or ‘Subject ID’ is missing.
Parameters: - collection : pd.DataFrame
This dataframe will be modified.
Returns: - pd.DataFrame
Dataframe with a ‘RID’ column.
Examples
>>> collection = pd.DataFrame({"Subject ID": ["100_S_1000", "101_S_1001"]}) >>> collection Subject ID 0 100_S_1000 1 101_S_1001 >>> rid(collection) Subject ID RID 0 100_S_1000 1000 1 101_S_1001 1001
-
adnipy.adnipy.
standard_column_names
(dataframe)[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.
Parameters: - dataframe : pd.DataFrame
This dataframe will be modified.
Returns: - pd.DataFrame
This will have standardized columns names.
See also
Examples
>>> subjects = pd.DataFrame({"Subject": ["101_S_1001", "102_S_1002"]}) >>> subjects Subject 0 101_S_1001 1 102_S_1002 >>> standard_column_names(subjects) 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 >>> standard_column_names(images) Image ID 0 100001 1 100002
-
adnipy.adnipy.
standard_dates
(dataset)[source]¶ Change type of date columns to datetime.
Parameters: - dataset : pd.DataFrame
This dataframe will be modified.
Returns: - pd.DataFrame
Dates will have the appropriate dtype.
-
adnipy.adnipy.
standard_index
(df, 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: - df : pd.DataFrame
This dataframe will be modified.
- index : list of str, default None
These columns will be the new index.
Returns: - pd.DataFrame
An easy to read dataframe for humans.
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: - numpy.int64
Image as a integer.
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 and 3.7. 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?
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line