Coder Social home page Coder Social logo

ted-strauss-k1 / heudiconv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nipy/heudiconv

0.0 2.0 0.0 897 KB

A flexible DICOM converter for organizing brain imaging data into structured directory layouts

Home Page: http://nipy.org/heudiconv

License: Other

Python 99.51% Shell 0.49%

heudiconv's Introduction

HeuDiConv - Heuristic DICOM Converter

Build Status codecov

This is a flexible DICOM converter for organizing brain imaging data into structured directory layouts.

  • it allows flexible directory layouts and naming schemes through customizable heuristics implementations
  • it only converts the necessary DICOMs, not everything in a directory
  • you can keep links to DICOM files in the participant layout
  • it's faster than parsesdicomdir or mri_convert if you use dcm2niix option
  • it tracks the provenance of the conversion from DICOM to NIfTI in W3C PROV format
  • it provides assistance in converting to BIDS
  • it integrates with DataLad to place converted and original data under git/git-annex version control, while automatically annotating files with sensitive information (e.g., non-defaced anatomicals, etc)

Heuristics

HeuDiConv operates using a heuristic, which provides information on how your files should be converted. A number of example heuristics are provided to address various use-cases

  • the cmrr_heuristic provides an example for a conversion to BIDS
  • the reproin could be used to establish a complete imaging center wide automation to convert all acquired data to BIDS following a simple naming convention for studies and sequences

Install

Released versions

Released versions of HeuDiConv are available from PyPI so you could just pip install heudiconv[all] for the most complete installation, and it would require manual installation ony of the dcm2niix. On Debian-based systems we recommend to use NeuroDebian providing heudiconv Debian package.

From source

You can clone this directory and use pip install .[all] (with --user, -e and other flags appropriate for your case), or

pip install https://github.com/nipy/heudiconv/archive/master.zip

Dependencies

  • pydicom
  • dcmstack
  • nipype
  • nibabel
  • dcm2niix

and should be checked/installed during pip install call, all but dcm2niix which should be installed directly from upstream or using the distribution manager appropriate for your OS.

Tutorial with example conversion to BIDS format using Docker

Please read this tutorial to understand how heudiconv works in practice.

Slides here

To generate lean BIDS output, consider using both the -b and the --minmeta flags to your heudiconv command. The -b flag generates a json file with BIDS keys, while the --minmeta flag restricts the json file to only BIDS keys. Without --minmeta, the json file and the associated Nifti file contains DICOM metadata extracted using dicomstack.

How it works (in some more detail)

Call heudiconv like this:

heudiconv -d '{subject}*.tar*' -s xx05 -f ~/myheuristics/convertall.py

where -d '{subject}*tar*' is an expression used to find DICOM files ({subject} expands to a subject ID so that the expression will match any .tar files, compressed or not that start with the subject ID in their name). An additional flag for session ({session}) can be included in the expression as well. -s od05 specifies a subject ID for the conversion (this could be a list of multiple IDs), and -f ~/myheuristics/convertall.py identifies a heuristic implementation for this conversion (see below) for details.

This call will locate the DICOMs (in any number of matching tarballs), extract them to a temporary directory, search for any DICOM series it can find, and attempts a conversion storing output in the current directory. The output directory will contain a subdirectory per subject, which in turn contains an info directory with a full protocol of detected DICOM series, and how their are converted.

The info directory

The info directory contains a copy of the heuristic script as well as the dicomseries information. In addition there are two files NAME.auto.txt and NAME.edit.txt. You can change series number assignments in NAME.edit.txt and rerun the converter to apply the changes. To start from scratch remove the participant directory.

Outlook

soon you'll be able to:

  • add more tags to the metadata representation of the files
  • and push the metadata to a provenance store

The heuristic file

The heuristic file controls how information about the dicoms is used to convert to a file system layout (e.g., BIDS). This is a python file that must have the function infotodict, which takes a single argument seqinfo.

seqinfo and the s variable

seqinfo is a list of namedtuple objects, each containing the following fields:

  • total_files_till_now
  • example_dcm_file
  • series_id
  • dcm_dir_name
  • unspecified2
  • unspecified3
  • dim1
  • dim2
  • dim3
  • dim4
  • TR
  • TE
  • protocol_name
  • is_motion_corrected
  • is_derived
  • patient_id
  • study_description
  • referring_physician_name
  • series_description
  • image_type
128     125000-1-1.dcm  1       -       -       
-       160     160     128     1       0.00315 1.37    AAHScout        False

The dictionary returned by infotodict

This dictionary contains as keys a 3-tuple (template, a tuple of output types, annotation classes).

template - how the file should be relative to the base directory tuple of output types - what format of output should be created - nii.gz, dicom, etc.,. annotation classes - unused

Example: ('func/sub-{subject}_task-face_run-{item:02d}_acq-PA_bold', ('nii.gz',
        'dicom'), None)

A few fields are defined by default and can be used in the template:

  • item: index within category
  • subject: participant id
  • seqitem: run number during scanning
  • subindex: sub index within group
  • session: session info for multi-session studies and when session has been defined as a parameter for heudiconv

Additional variables may be added and can be returned in the value of the dictionary returned from the function.

info[some_3-tuple] = [12, 14, 16] would assign dicom sequence groups 12, 14 and 16 to be converted using the template specified in some_3-tuple.

if the template contained a non-sanctioned variable, it would have to be provided in the values for that key.

some_3_tuple = ('func/sub-{subject}_task-face_run-{item:02d}_acq-{acq}_bold', ('nii.gz',
        'dicom'), None)

In the above example {acq} is not a standard variable. In this case, values for this variable needs to be added.

info[some_3-tuple] = [{'item': 12, 'acq': 'AP'},
                      {'item': 14, 'acq': 'AP'},
                      {'item': 16, 'acq': 'PA'}]

heudiconv's People

Contributors

yarikoptic avatar mgxd avatar mvdoc avatar satra avatar mih avatar ted-strauss-k1 avatar matthew-brett avatar chrisgorgo avatar tsalo avatar cni-md avatar jpellman avatar danlurie avatar pvelasco avatar leej3 avatar jooh avatar bcschiffler avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.