-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancing the `narps_open.data.results` module by making calls to Neurovault API and allowing data rectification as done by the NARPS team. Added a script for NARPS results dataset creation using datalad.
- Loading branch information
Showing
26 changed files
with
391 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Provide a command-line interface for the package narps_open.data.results """ | ||
|
||
from argparse import ArgumentParser | ||
|
||
from narps_open.data.results import ResultsCollectionFactory | ||
from narps_open.pipelines import implemented_pipelines | ||
|
||
# Parse arguments | ||
parser = ArgumentParser(description='Get Neurovault collection of results from NARPS teams.') | ||
group = parser.add_mutually_exclusive_group(required = True) | ||
group.add_argument('-t', '--teams', nargs='+', type=str, action='extend', | ||
help='a list of team IDs') | ||
group.add_argument('-a', '--all', action='store_true', help='download results from all teams') | ||
parser.add_argument('-r', '--rectify', action='store_true', default = False, required = False, | ||
help='rectify the results') | ||
arguments = parser.parse_args() | ||
|
||
factory = ResultsCollectionFactory() | ||
|
||
if arguments.all: | ||
for team_id, _ in implemented_pipelines.items(): | ||
collection = factory.get_collection(team_id) | ||
collection.download() | ||
if arguments.rectify: | ||
collection.rectify() | ||
else: | ||
for team in arguments.teams: | ||
collection = factory.get_collection(team) | ||
collection.download() | ||
if arguments.rectify: | ||
collection.rectify() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Generate a bash script to create the NARPS results dataset | ||
Warning: unfortunately, the script actually downloads the data. | ||
""" | ||
|
||
from os.path import join | ||
from argparse import ArgumentParser | ||
|
||
from narps_open.utils.configuration import Configuration | ||
from narps_open.data.results import ResultsCollectionFactory | ||
from narps_open.pipelines import implemented_pipelines | ||
|
||
if __name__ == '__main__': | ||
# Parse arguments | ||
parser = ArgumentParser( | ||
description='Generate a bash script to create the NARPS results dataset.' | ||
) | ||
parser.add_argument('-r', '--repository', type=str, required=True, | ||
help='adress of the repository where to push the dataset' | ||
) | ||
arguments = parser.parse_args() | ||
|
||
# Handle dataset directory | ||
dataset_dir = Configuration()['directories']['narps_results'] | ||
|
||
# Create a new dataset | ||
print(f'mkdir -p {dataset_dir}') | ||
print(f'datalad create -D "NARPS results dataset" {dataset_dir}') | ||
|
||
# Add files for each team results collection | ||
collection_factory = ResultsCollectionFactory() | ||
for team_id, _ in implemented_pipelines.items(): | ||
|
||
# Init collection | ||
collection = collection_factory.get_collection(team_id) | ||
|
||
# Create download directory if not existing | ||
print(f'mkdir -p {collection.directory}') | ||
|
||
# Create dataset entries | ||
for file_name, file_url in collection.files.items(): | ||
complete_file_name = join(collection.directory, file_name+".nii.gz") | ||
short_file_name = complete_file_name.replace(dataset_dir, '') | ||
command = 'datalad download-url' | ||
command += f' -m \"New file {short_file_name}\"' | ||
command += f' --path \"{complete_file_name}\"' | ||
command += f' --dataset \"{dataset_dir}\"' | ||
command += f' \"{file_url}\"' | ||
print(command) | ||
|
||
# Push dataset | ||
print(f'cd {dataset_dir}') | ||
print(f'git remote add origin {arguments.repository}') | ||
print('git push -u origin master') | ||
print('datalad push') |
Oops, something went wrong.