nidm package

Submodules module

class*args, **kwargs)[source]



Bases: flask_restful.Resource

return result of query on ttl file Paramters ========= qid: str

the uid associated with the query
ttl: str
the url of the turtle file
endpoint = 'apidoquery'
get(qid, output_format)[source]
methods = ['GET']

Bases: flask_restful.Resource

Main view for REST API to display all available queries

endpoint = 'apiindex'
methods = ['GET']

Bases: flask_restful.Resource

return complete meta data for specific query

endpoint = 'apiquerymeta'
methods = ['GET'][source][source][source][source]

nidm.experiment module

nidm.query module

query: part of the nidm-api general functions to work with query data structures for nidm-queries

class nidm.query.Queries(components=['experiment', 'results', 'workflow'])[source]
nidm.query.do_query(ttl_file, query, rdf_format='turtle', serialize_format='csv', output_df=True)[source]

Download queries repo to a destination Parameters ========== destination:

the full path to download the repo to
nidm.query.find_queries(query_folders, search_pattern='*.json')[source]

searches one or more folders for valid queries, meaning json files. In the case of multiple directories, will append the folder name as a variable to indicate the type Parameters ========== query_folders: list or str

one or more full paths to directories with json objects
search_pattern: str
pattern for glob to use to find query objects default is “*.json”
queries: list
a list of full paths to query object files

split sparql text into a list, and extract parameter options from select.

nidm.query.generate_query_template(output_dir=None, template_path=None, fields=None)[source]
output_dir: str
full path to output directory for json data structure. if none specified, will not save the data structure
template_path: str
path to json file to use as a template. Only should be specified if the user has reason to use a custom template default is the standard provided by nidm-api.
fields: dict (optional)
a dictionary with fields that correspond to template keys. if provided, template will be filled with keys. Possible values include
template: json (dict)
A python dictionary (json) that can be filled with new query information

get_query_directory: Download queries repo to tmp directory Parameters ========== tmpdir: str

path to directory to download queries to
nidm.query.make_lookup(query_list, key_field)[source]

returns dict object to quickly look up query based on uid Parameters ========== query_list: list

a list of query (dict objects)
key_field: str
the key in the dictionary to base the lookup key
query_dict: dict
dict (json) with key as “key_field” from query_list

Read in a list of query (json) objects. Parameters ========== query_paths: list a list of full paths to query objects to read Returns ======= queries_: list

dict to be served as json describing queries available a “type” variable is added to indicate folder query was found in
nidm.query.save_query_template(template, output_dir)[source]

generate_query_template Parameters ========== output_dir: string path

full path to output directory for json data structure. the template filename is generated from the uid variable
success: boolean
True if save was successful, false otherwise
nidm.query.validate_queries(query_dir, queries=None, components=['sparql'])[source]

returns json object with query data structures, and a field ‘valid’ to describe if query was valid Parameters ========== queries: list

a list of full paths to json files, each a query
query_dir: str
full path to a nidm-query repo
components: folders to include corresponding to nidm
query language (currently only option is sparql)
queries: json
dict (json) with all read in queries available

from nidm-query, provided by API

nidm.results module

nidm.scripts module part of nidmapi package Runtime executable


nidm.utils module

utils: part of the nidm-api general functions for the api


Ensures that keys and values of dictionary are in utf-8 so rendering in javascript is clean. Paramters ========= mydict: dict

dictionary to clean
newdict: dict
dictionary with all fields encoded in utf-8
nidm.utils.copy_directory(src, dest)[source]

Copy an entire directory recursively

nidm.utils.find_directories(root, fullpath=True)[source]

Return directories at one level specified by user (not recursive)


Return directories (and sub) starting from a base


returns installation directory of nidm-api


get_standard_template returns the full path to the standard template for queries


get_template: read in and return a template file


Checks for internet connectivity by way of trying to retrieve google IP address. Returns True/False

nidm.utils.is_type(var, types=[<type 'int'>, <type 'float'>, <type 'list'>])[source]

Check type


returns a loaded json file Parameters ========== json_path: str

full path to json file to load
thejson: json (dict)
loaded json (dict)
nidm.utils.remove_unicode_dict(input_dict, encoding='utf-8')[source]

remove unicode keys and values from dict, encoding in utf8

nidm.utils.save_template(output_file, html_snippet)[source]
nidm.utils.set_permissions(path, permission=128)[source]
nidm.utils.sub_template(template, template_tag, substitution)[source]

make a substitution for a template_tag in a template

nidm.workflow module

Module contents