Skip to content

Commit

Permalink
Add config param for requiring functional data to run the code. Exit …
Browse files Browse the repository at this point in the history
…if not functional. Closes #3.
  • Loading branch information
lmperry committed Oct 26, 2018
1 parent 921805f commit 60dc99e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"description": "Number of initial time-points to skip. [ DEFAULT = 6 ]",
"default": 6,
"type": "integer"
},
"require_functional": {
"description": "Require that the dataset be classified as Intent==Functional. [ DEFAULT = true ]. If true, the gear will exit (0) without attempting to process the data.",
"default": true,
"type": "boolean"
}
},
"inputs": {
Expand Down
21 changes: 20 additions & 1 deletion qa-report-fmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def generate_metadata(config, qa_stats_file):
Output:
metadata_file: Path to .metadata.json file.
"""
from pprint import pprint as pp

print('%s Generating metadata...' % (time.asctime()))
outbase = '/flywheel/v0/output'
output_files = os.listdir(outbase)
Expand Down Expand Up @@ -87,7 +89,7 @@ def generate_metadata(config, qa_stats_file):
with open(metadata_file, 'w') as metafile:
json.dump(metadata, metafile)

print('%s Generated %s' % (time.asctime(), metadata_file))
pp(metadata)

return metadata_file

Expand Down Expand Up @@ -313,6 +315,23 @@ def generate_qa_report(nifti_file, nifti_path, output_dir, force=False, spike_th
with open(config_file, 'r') as f:
config = json.load(f)

# Check if this is a Funcitonal scan
classification = []
if config['config']['require_functional'] == True:
if config['inputs']['nifti']['object'].has_key('classification') and config['inputs']['nifti']['object']['classification'].has_key('Intent'):
classification = config['inputs']['nifti']['object']['classification']
if 'Functional' not in classification['Intent']:
print('%s QA: This algorithm is designed for fMRI (Functional) datasets.' % (time.asctime()))
print('%s QA: These data are not classified as "Intent=Functional" and config.require_functional==true.' % (time.asctime()))
print('%s QA: If you want to force this dataset through, then re-run and set config.require_functional==false or correctly classify this dataset.' % (time.asctime()))
print('%s QA: No errors here, but I will exit now.' % (time.asctime()))
sys.exit(0)
else:
print('%s QA: This algorithm is designed for fMRI (Functional) datasets.' % (time.asctime()))
print('%s QA: No classification info found and config.require_functional==true.' % (time.asctime()))
print('%s QA: If you want to force this dataset through, then re-run and set config.require_functional==false, or modify the classifcation of this dataset to include Functional Intent.' % (time.asctime()))
print('%s QA: No errors here, but I will exit now.' % (time.asctime()))
sys.exit(0)
# Run Report
json_file, img_file = generate_qa_report(config['inputs']['nifti']['location']['name'],
os.path.dirname(config['inputs']['nifti']['location']['path']),
Expand Down

0 comments on commit 60dc99e

Please sign in to comment.