Git Product home page Git Product logo

pynidm's Introduction

Logo.png

A Python library to manipulate the Neuroimaging Data Model.

Status of PyNIDM Testing ReadTheDocs Documentation of master branch

  • Git-annex
  • Graphviz (native package):
    • Fedora: dnf install graphviz
    • OS-X: brew install graphviz
$ pip install pynidm

This software is open source and community developed. As such, we encourage anyone and everyone interested in semantic web and neuroimaging to contribute. To begin contributing code to the repository, please fork the main repo into your user space and use the pull request GitHub feature to submit code for review. Please provide a reasonably detailed description of what was changed and why in the pull request.

To establish development environment, we recommend to install the clone of this repository in development mode with development tools installed via

$ pip install -e .[devel]

We also recommend using pre-commit for ensuring that your contributions would conform our conventions for code quality etc. You can enable pre-commit by running once in your clone

$ pre-commit install

which would then ensure that all commits would be subject to black code reformatting etc.

If you encounter a bug, you can directly report it in the issues section. Please describe how to reproduce the issue and include as much information as possible that can be helpful for fixing it. If you would like to suggest a fix, please open a new pull request or include your suggested fix in the issue.

We would love to hear your thoughts on our Python toolbox. Feedback, questions, or feature requests can also be submitted as issues. Note, we are a small band of researchers who mostly volunteer our time to this project. We will respond as quickly as possible.

This program will convert a BIDS MRI dataset to a NIDM-Experiment RDF document. It will parse phenotype information and simply store variables/values and link to the associated json data dictionary file. To use this tool please set your INTERLEX_API_KEY environment variable to your unique API key. To get an Interlex API key you visit SciCrunch, register for an account, then click on "MyAccount" and "API Keys" to add a new API key for your account.

$ bidsmri2nidm -d [ROOT BIDS DIRECT] -bidsignore

usage: bidsmri2nidm [-h] -d DIRECTORY [-jsonld] [-bidsignore] [-no_concepts]
                 [-json_map JSON_MAP] [-log LOGFILE] [-o OUTPUTFILE]

This program will represent a BIDS MRI dataset as a NIDM RDF document and provide user with opportunity to annotate
the dataset (i.e. create sidecar files) and associate selected variables with broader concepts to make datasets more
FAIR.

Note, you must obtain an API key to Interlex by signing up for an account at scicrunch.org then going to My Account
and API Keys.  Then set the environment variable INTERLEX_API_KEY with your key.

optional arguments:
  -h, --help            show this help message and exit
  -d DIRECTORY          Full path to BIDS dataset directory
  -jsonld, --jsonld     If flag set, output is json-ld not TURTLE
  -bidsignore, --bidsignore
                     If flag set, tool will add NIDM-related files to .bidsignore file
  -no_concepts, --no_concepts
                     If flag set, tool will no do concept mapping
  -log LOGFILE, --log LOGFILE
                     Full path to directory to save log file. Log file name is bidsmri2nidm_[basename(args.directory)].log
  -o OUTPUTFILE         Outputs turtle file called nidm.ttl in BIDS directory by default..or whatever path/filename is set here

map variables to terms arguments:
  -json_map JSON_MAP, --json_map JSON_MAP
                     Optional full path to user-suppled JSON file containing data element definitions.

This program will load in a CSV file and iterate over the header variable names performing an elastic search of https://scicrunch.org/nidm-terms for NIDM-ReproNim tagged terms that fuzzy match the variable names. The user will then interactively pick a term to associate with the variable name. The resulting annotated CSV data will then be written to a NIDM data file. To use this tool please set your INTERLEX_API_KEY environment variable to your unique API key. To get an Interlex API key you visit SciCrunch, register for an account, then click on "MyAccount" and "API Keys" to add a new API key for your account.

usage: csv2nidm [-h] -csv CSV_FILE [-json_map JSON_MAP | -redcap REDCAP]
                [-nidm NIDM_FILE] [-no_concepts] [-log LOGFILE] -out
                OUTPUT_FILE

This program will load in a CSV file and iterate over the header variable
names performing an elastic search of https://scicrunch.org/ for NIDM-ReproNim
tagged terms that fuzzy match the variable names. The user will then
interactively pick a term to associate with the variable name. The resulting
annotated CSV data will then be written to a NIDM data file. Note, you must
obtain an API key to Interlex by signing up for an account at scicrunch.org
then going to My Account and API Keys. Then set the environment variable
INTERLEX_API_KEY with your key.  The tool supports import of RedCap data
dictionaries and will convert relevant information into a json-formatted
annotation file used to annotate the data elements in the resulting NIDM file.

optional arguments:
  -h, --help            show this help message and exit
  -csv CSV_FILE         Full path to CSV file to convert
  -json_map JSON_MAP    Full path to user-suppled JSON file containing
                        variable-term mappings.
  -redcap REDCAP        Full path to a user-supplied RedCap formatted data
                        dictionary for csv file.
  -nidm NIDM_FILE       Optional full path of NIDM file to add CSV->NIDM
                        converted graph to
  -no_concepts          If this flag is set then no concept associations will
                        beasked of the user. This is useful if you already
                        have a -json_map specified without concepts and want
                        tosimply run this program to get a NIDM file with user
                        interaction to associate concepts.
  -log LOGFILE, --log LOGFILE
                        full path to directory to save log file. Log file name
                        is csv2nidm_[arg.csv_file].log
  -out OUTPUT_FILE      Full path with filename to save NIDM file

This function will convert NIDM files to various RDF-supported formats and name then / put them in the same place as the input file.

Usage: pynidm convert [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT      A comma separated list of NIDM files with
                                full path  [required]
  -t, --type [turtle|jsonld|xml-rdf|n3|trig]
                                If parameter set then NIDM file will be
                                exported as JSONLD  [required]
  --help                          Show this message and exit.

This function will concatenate NIDM files. Warning, no merging will be done so you may end up with multiple prov:agents with the same subject id if you're concatenating NIDM files from multiple visits of the same study. If you want to merge NIDM files on subject ID see pynidm merge

Usage: pynidm concat [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT  A comma separated list of NIDM files with full
                            path  [required]
  -o, --out_file TEXT         File to write concatenated NIDM files
                            [required]
  --help                      Show this message and exit.

This command will produce a visualization(pdf) of the supplied NIDM files named the same as the input files and stored in the same directories.

Usage: pynidm visualize [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT  A comma separated list of NIDM files with full
                            path  [required]
  --help                      Show this message and exit.

This function will merge NIDM files. See command line parameters for supported merge operations.

Usage: pynidm merge [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT  A comma separated list of NIDM files with full
                           path  [required]
  -s, --s                     If parameter set then files will be merged by
                           ndar:src_subjec_id of prov:agents
      -o, --out_file TEXT         File to write concatenated NIDM files
                           [required]
      --help                      Show this message and exit.

This function provides query support for NIDM graphs.

Usage: pynidm query [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT      A comma separated list of NIDM files with
                                  full path  [required]
  -nc, --cde_file_list TEXT       A comma separated list of NIDM CDE files
                                  with full path. Can also be set in the
                                  CDE_DIR environment variable
  -q, --query_file FILENAME       Text file containing a SPARQL query to
                                  execute
  -p, --get_participants          Parameter, if set, query will return
                                  participant IDs and prov:agent entity IDs
  -i, --get_instruments           Parameter, if set, query will return list of
                                  onli:assessment-instrument:
  -iv, --get_instrument_vars      Parameter, if set, query will return list of
                                  onli:assessment-instrument: variables
  -de, --get_dataelements         Parameter, if set, will return all
                                  DataElements in NIDM file
  -debv, --get_dataelements_brainvols
                                  Parameter, if set, will return all brain
                                  volume DataElements in NIDM file along with
                                  details
  -bv, --get_brainvols            Parameter, if set, will return all brain
                                  volume data elements and values along with
                                  participant IDs in NIDM file
  -o, --output_file TEXT          Optional output file (CSV) to store results
                                  of query
  -u, --uri TEXT                  A REST API URI query
  -j / -no_j                      Return result of a uri query as JSON
  -v, --verbosity TEXT            Verbosity level 0-5, 0 is default
  --help                          Show this message and exit.

Details on the REST API URI format and usage can be found on the REST API usage page.

This function provides linear regression support for NIDM graphs.

Usage: pynidm linear-regression [OPTIONS]

Options:
  -nl, --nidm_file_list TEXT      A comma-separated list of NIDM files with
                                  full path  [required]
  -r, --regularization TEXT       Parameter, if set, will return the results of
                                  the linear regression with L1 or L2 regularization
                                  depending on the type specified, and the weight
                                  with the maximum likelihood solution. This will
                                  prevent overfitting. (Ex: -r L1)
  -model, --ml TEXT                   An equation representing the linear
                                  regression. The dependent variable comes
                                  first, followed by "=" or "~", followed by
                                  the independent variables separated by "+"
                                  (Ex: -model "fs_003343 = age*sex + sex +
                                  age + group + age*group + bmi") [required]
  -contstant, --ctr TEXT              Parameter, if set, will return differences in
                                  variable relationships by group. One or
                                  multiple parameters can be used (multiple
                                  parameters should be separated by a comma-
                                  separated list) (Ex: -contrast group,age)
  -o, --output_file TEXT          Optional output file (TXT) to store results
                                  of query
  --help                          Show this message and exit.

To use the linear regression algorithm successfully, structure, syntax, and querying is important. Here is how to maximize the usefulness of the tool:

First, use pynidm query to discover the variables to use. PyNIDM allows for the use of either data elements (PIQ_tca9ck), specific URLs (http://uri.interlex.org/ilx_0100400), or source variables (DX_GROUP).

An example of a potential query is:

pynidm query -nl /simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl,/simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_b/nidm.ttl -u /projects?fields=fs_000008,DX_GROUP,PIQ_tca9ck,http://uri.interlex.org/ilx_0100400

You can also do:

pynidm query -nl /simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl,/Users/Ashu/Downloads/simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_b/nidm.ttl -gf fs_000008,DX_GROUP,PIQ_tca9ck,http://uri.interlex.org/ilx_0100400

The query looks in the two files specified in the -nl parameter for the variables specified. In this case, we use fs_000008 and DX_GROUP (source variables), a URL (http://uri.interlex.org/ilx_0100400), and a data element (PIQ_tca9ck). The output of the file is slightly different depending on whether you use -gf or -u. With -gf, it will return the variables from both files separately, while -u combines them.

Now that we have selected the variables, we can perform a linear regression. In this example, we will look at the effect of DX_GROUP, age at scan, and PIQ on supratentorial brain volume.

The command to use for this particular data is:

pynidm linear-regression -nl /simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_a/nidm.ttl,/simple2_NIDM_examples/datasets.datalad.org/abide/RawDataBIDS/CMU_b/nidm.ttl -model "fs_000008 = DX_GROUP + PIQ_tca9ck + http://uri.interlex.org/ilx_0100400" -contrast "DX_GROUP" -r L1

-nl specifies the file(s) to pull data from, while -model is the model to perform a linear regression model on. In this case, the variables are fs_000008 (the dependent variable, supratentorial brain volume), DX_GROUP (diagnostic group), PIQ_tca9ck (PIQ), and http://uri.interlex.org/ilx_0100400 (age at scan). The -contrast parameter says to contrast the data using DX_GROUP, and then do a L1 regularization to prevent overfitting.

Details on the REST API URI format and usage can be found below.

There are two main ways to interact with NIDM data using the PyNIDM REST API. First, the pynidm query command line utility will accept queries formatted as REST API URIs. Second, the rest-server.py script can be used to run a HTTP server to accept and process requests. This script can either be run directly or using a docker container defined in the docker directory of the project.

Example usage:

$ pynidm query -nl "cmu_a.ttl,cmu_b.ttl" -u /projects

dc1bf9be-10a3-11ea-8779-003ee1ce9545
ebe112da-10a3-11ea-af83-003ee1ce9545

To use the REST API query syntax on the command line, follow the PyNIDM installation instructions.

The simplest way to deploy a HTTP REST API server would be with the provided docker container. You can find instructions for that process in the README.md file in the docker directory of the Github repository.

You can find details on the REST API at the SwaggerHub API Documentation. The OpenAPI specification file is part of the Github repository in 'docs/REST_API_definition.openapi.yaml'

Here is a list of the current operations. See the SwaggerHub page for more details and return formats.

- /projects
- /projects/{project_id}
- /projects/{project_id}/subjects
- /projects/{project_id}/subjects?filter=[filter expression]
- /projects/{project_id}/subjects/{subject_id}
- /projects/{project_id}/subjects/{subject_id}/instruments/{instrument_id}
- /projects/{project_id}/subjects/{subject_id}/derivatives/{derivative_id}
- /statistics/projects/{project_id}

You can append the following query parameters to many of the operations:

- filter
- field
/projects

Get a list of all project IDs available.

Supported query parameters: none

/projects/{project_id}

See some details for a project. This will include the list of subject IDs and data elements used in the project

Supported query parameters: filter

/projects/{project_id}/subjects

Get the list of subjects in a project

Supported query parameters: filter

/projects/{project_id}/subjects/{subject_id}

Get the details for a particular subject. This will include the results of any instrumnts or derivatives associated with the subject, as well as a list of the related activities.

Supported query parameters: none

/projects/{project_id}/subjects/{subject_id}/instruments/{instrument_id}

Get the values for a particular instrument

Supported query parameters: none

/projects/{project_id}/subjects/{subject_id}/derivatives/{derivative_id}

Get the values for a particular derivative

Supported query parameters: none

/statistics/projects/{project_id}

See project statistics. You can also use this operation to get statsitcs on a particular instrument or derivative entry by use a field query option.

Supported query parameters: filter, field

/statistics/projects/{project_id}/subjects/{subject_id}

See some details for a project. This will include the list of subject IDs and data elements used in the project

Supported query parameters: none

filter

The filter query parameter is used when you want to receive data only on subjects that match some criteria. The format for the filter value should be of the form:

identifier op value [ and identifier op value and ... ]

Identifiers should be formatted as "instrument.ID" or "derivatives.ID" You can use any value for the instrument ID that is shown for an instrument or in the data_elements section of the project details. For the derivative ID, you can use the last component of a derivative field URI (ex. for the URI http://purl.org/nidash/fsl#fsl_000007, the ID would be "fsl_000007") or the exact label shown when viewing derivative data (ex. "Left-Caudate (mm^3)").

The op can be one of "eq", "gt", "lt".

Example filters:
?filter=instruments.AGE_AT_SCAN gt 30 ?filter=instrument.AGE_AT_SCAN eq 21 and derivative.fsl_000007 lt 3500
fields

The fields query parameter is used to specify what fields should be detailed in a statistics operation. For each field specified the result will show minimum, maximum, average, median, and standard deviation for the values of that field across all subjects matching the operation and filter. Multiple fields can be specified by separating each field with a comma.

Fields should be formatted in the same way as identifiers are specified in the filter parameter.

Example field query:
http://localhost:5000/statistics/projects/abc123?field=instruments.AGE_AT_SCAN,derivatives.fsl_000020

By default the HTTP REST API server will return JSON formatted objects or arrays. When using the pynidm query command line utility the default return format is text (when possible) or you can use the -j option to have the output formatted as JSON.

curl http://localhost:5000/projects

Example response:

[
    "dc1bf9be-10a3-11ea-8779-003ee1ce9545"
]
curl http://localhost:5000/projects/dc1bf9be-10a3-11ea-8779-003ee1ce9545

Example response:

{
 "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": "http://purl.org/nidash/nidm#Project",
 "dctypes:title": "ABIDE CMU_a Site",
 "http://www.w3.org/ns/prov#Location": "/datasets.datalad.org/abide/RawDataBIDS/CMU_a",
 "sio:Identifier": "1.0.1",
 "nidm:NIDM_0000171": 14,
 "age_max": 33.0,
 "age_min": 21.0,
 "ndar:gender": [
     "1",
     "2"
 ],
 "obo:handedness": [
     "R",
     "L",
     "Ambi"
 ]
}
pynidm query -nl "cmu_a.nidm.ttl" -u http://localhost:5000/projects/dc1bf9be-10a3-11ea-8779-003ee1ce9545/subjects

Example response:

deef8eb2-10a3-11ea-8779-003ee1ce9545
df533e6c-10a3-11ea-8779-003ee1ce9545
ddbfb454-10a3-11ea-8779-003ee1ce9545
df21cada-10a3-11ea-8779-003ee1ce9545
dcfa35b2-10a3-11ea-8779-003ee1ce9545
de89ce4c-10a3-11ea-8779-003ee1ce9545
dd2ce75a-10a3-11ea-8779-003ee1ce9545
ddf21020-10a3-11ea-8779-003ee1ce9545
debc0f74-10a3-11ea-8779-003ee1ce9545
de245134-10a3-11ea-8779-003ee1ce9545
dd5f2f30-10a3-11ea-8779-003ee1ce9545
dd8d4faa-10a3-11ea-8779-003ee1ce9545
df87cbaa-10a3-11ea-8779-003ee1ce9545
de55285e-10a3-11ea-8779-003ee1ce9545
pynidm query -nl ttl/cmu_a.nidm.ttl -u /statistics/projects/dc1bf9be-10a3-11ea-8779-003ee1ce9545?fields=instruments.AGE_AT_SCAN,derivatives.fsl_000001

Example response:

-------------------------------------------------  ---------------------------------------------
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"  http://www.w3.org/ns/prov#Activity
"title"                                            ABIDE CMU_a Site
"Identifier"                                       1.0.1
"prov:Location"                                    /datasets.datalad.org/abide/RawDataBIDS/CMU_a
"NIDM_0000171"                                     14
"age_max"                                          33.0
"age_min"                                          21.0

  gender
--------
       1
       2

handedness
------------
R
L
Ambi

subjects
------------------------------------
de89ce4c-10a3-11ea-8779-003ee1ce9545
deef8eb2-10a3-11ea-8779-003ee1ce9545
dd8d4faa-10a3-11ea-8779-003ee1ce9545
ddbfb454-10a3-11ea-8779-003ee1ce9545
de245134-10a3-11ea-8779-003ee1ce9545
debc0f74-10a3-11ea-8779-003ee1ce9545
dd5f2f30-10a3-11ea-8779-003ee1ce9545
ddf21020-10a3-11ea-8779-003ee1ce9545
dcfa35b2-10a3-11ea-8779-003ee1ce9545
df21cada-10a3-11ea-8779-003ee1ce9545
df533e6c-10a3-11ea-8779-003ee1ce9545
de55285e-10a3-11ea-8779-003ee1ce9545
df87cbaa-10a3-11ea-8779-003ee1ce9545
dd2ce75a-10a3-11ea-8779-003ee1ce9545

-----------  ------------------  --------
AGE_AT_SCAN  max                 33
AGE_AT_SCAN  min                 21
AGE_AT_SCAN  median              26
AGE_AT_SCAN  mean                26.2857
AGE_AT_SCAN  standard_deviation   4.14778
-----------  ------------------  --------

----------  ------------------  -----------
fsl_000001  max                 1.14899e+07
fsl_000001  min                 5.5193e+06
fsl_000001  median              7.66115e+06
fsl_000001  mean                8.97177e+06
fsl_000001  standard_deviation  2.22465e+06
----------  ------------------  -----------

Use -j for a JSON-formatted response

pynidm query -j -nl "cmu_a.nidm.ttl" -u http://localhost:5000/projects/dc1bf9be-10a3-11ea-8779-003ee1ce9545/subjects/df21cada-10a3-11ea-8779-003ee1ce9545

Example response:

 {
"uuid": "df21cada-10a3-11ea-8779-003ee1ce9545",
"id": "0050665",
"activity": [
  "e28dc764-10a3-11ea-a7d3-003ee1ce9545",
  "df28e95a-10a3-11ea-8779-003ee1ce9545",
  "df21c76a-10a3-11ea-8779-003ee1ce9545"
],
"instruments": {
  "e28dd218-10a3-11ea-a7d3-003ee1ce9545": {
    "SRS_VERSION": "nan",
    "ADOS_MODULE": "nan",
    "WISC_IV_VCI": "nan",
    "WISC_IV_PSI": "nan",
    "ADOS_GOTHAM_SOCAFFECT": "nan",
    "VINELAND_PLAY_V_SCALED": "nan",
    "null": "http://www.w3.org/ns/prov#Entity",
    "VINELAND_EXPRESSIVE_V_SCALED": "nan",
    "SCQ_TOTAL": "nan",
    "SRS_MOTIVATION": "nan",
    "PIQ": "104.0",
    "FIQ": "109.0",
    "WISC_IV_PRI": "nan",
    "FILE_ID": "CMU_a_0050665",
    "VIQ": "111.0",
    "WISC_IV_VOCAB_SCALED": "nan",
    "VINELAND_DAILYLVNG_STANDARD": "nan",
    "WISC_IV_SIM_SCALED": "nan",
    "WISC_IV_DIGIT_SPAN_SCALED": "nan",
    "AGE_AT_SCAN": "33.0"
    }
 },
"derivatives": {
    "b9fe0398-16cc-11ea-8729-003ee1ce9545": {
       "URI": "http://iri.nidash.org/b9fe0398-16cc-11ea-8729-003ee1ce9545",
       "values": {
         "http://purl.org/nidash/fsl#fsl_000005": {
           "datumType": "ilx_0102597",
           "label": "Left-Amygdala (voxels)",
           "value": "1573",
           "units": "voxel"
         },
         "http://purl.org/nidash/fsl#fsl_000004": {
           "datumType": "ilx_0738276",
           "label": "Left-Accumbens-area (mm^3)",
           "value": "466.0",
           "units": "mm^3"
         },
         "http://purl.org/nidash/fsl#fsl_000003": {
           "datumType": "ilx_0102597",
           "label": "Left-Accumbens-area (voxels)",
           "value": "466",
           "units": "voxel"
         }
       },
       "StatCollectionType": "FSLStatsCollection"
    }
 }

pynidm's People

Contributors

adswa avatar akumar0019 avatar albertcrowley avatar dbkeator avatar dependabot[bot] avatar djarecka avatar glatard avatar jwodder avatar maxbachmann avatar mih avatar natachaperez avatar nqueder avatar sanuann avatar satra avatar surchs avatar tgbugs avatar tiborauer avatar yarikoptic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pynidm's Issues

PyDOT package new installation

When testing the csv2nidm instructions, I get the following error: (mac OSX 10.12.6 (16G1510)); following instructions at: https://docs.google.com/document/d/1N_olJLBHW2WarKpu73PwGdmCS83d57iMZDI662fXZuc/edit#

Writing NIDM file...
Traceback (most recent call last):
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/site-packages/pydot.py", line 1915, in create
working_dir=tmp_dir,
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/site-packages/pydot.py", line 136, in call_graphviz
**kwargs
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/subprocess.py", line 775, in init
restore_signals, start_new_session)
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/bin/csv2nidm", line 7, in
exec(compile(f.read(), file, 'exec'))
File "/Users/davidkennedy/simple_annotate/PyNIDM/bin/CSV2NIDM", line 7, in
main(sys.argv)
File "/Users/davidkennedy/simple_annotate/PyNIDM/nidm/experiment/tools/CSV2NIDM.py", line 266, in main
project.save_DotGraph(str(args.output_file + ".png"), format="png")
File "/Users/davidkennedy/simple_annotate/PyNIDM/nidm/experiment/Core.py", line 348, in save_DotGraph
dot.write(filename,format=format)
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/site-packages/pydot.py", line 1817, in write
s = self.create(prog, format, encoding=encoding)
File "/Users/davidkennedy/anaconda/envs/pynidm_py3/lib/python3.7/site-packages/pydot.py", line 1922, in create
raise OSError(*args)
FileNotFoundError: [Errno 2] "dot" not found in path.

Locally-defined terms in github repo for variable-> term mappings

Currently tools like BIDSMRI2NIDM.py and CSV2NIDM.py use a github repository (nidm_local_terms) to create issues for terms one wants to define in the process of converting assessment data and/or BIDS data to NIDM files. We'd like to change this so it instead adds a JSON file for each term instead of creating an issue because then we can track the terms better. We also discussed forking https://github.com/ReproNim/ni-terms instead of creating a new repo (nidm_local_terms) such that we could have the tool create pull requests back to the ReproNim ni-terms central repo for easier coordination with other groups and loading of terms to Interlex to make them broadly available.

BIDS_convert.py is broken

I found this in bin/, thinking it would be the cmdline entrypoint. However, when running it (no args) I get:

Traceback (most recent call last):
  File "/home/mih/hacking/PyNIDM/bin/BIDS_convert.py", line 5, in <module>
    from nidm.experiment import Project,Session,Acquisition,AcquisitionObject,Demog
ImportError: cannot import name 'DemographicsAcquisitionObject'

and it is not in the repo:

% git grep DemographicsAcquisitionObject
bin/BIDS_convert.py:from nidm.experiment import Project,Session,Acquisition,AcquisitionObject,DemographicsAcquisitionObject,MRAcquisitionObject
bin/BIDS_convert.py:            acq_entity = DemographicsAcquisitionObject(acquisition=acq)
nidm/terms/nidm-experiment.owl:###  http://purl.org/nidash/nidm#DemographicsAcquisitionObject
nidm/terms/nidm-experiment.owl:nidm:DemographicsAcquisitionObject rdf:type owl:Class ;

tests for GetProjectsComputedMetadata

@albertcrowley

We should discuss one of the tests for GetProjectsComputedMetadata. It isn't returning correct results and I'm fairly sure I know why but maybe a quick hangout is better to explain.
See:

In brief, the current query depends on the Project activity UUID which isn't guaranteed to remain consistent in the simple2 ReproNim commits...there's also a problem with retrieving age but I'm not entirely sure why that's happening...

Add support for producing BIDS data dictionaries to CSV2NIDM

Currently, CSV2NIDM does not create a JSON file compatible with BIDS

Here's how an example JSON data dictionary in BIDS looks like:

  "test": {
    "LongName": "Education level",
    "Description": "Education level, self-rated by participant",
    "Levels": {
      "1": "Finished primary school",
      "2": "Finished secondary school",
      "3": "Student at university",
      "4": "Has degree from university"
    }
  },
  "bmi": {
    "LongName": "Body mass index",
    "Units": "kilograms per squared meters",
    "TermURL": "http://purl.bioontology.org/ontology/SNOMEDCT/60621009"
  }
}

You can read more about the syntax at https://bids-specification.readthedocs.io/en/v.1.1.2/02-common-principles.html#tabular-files

API: discussion

@glatard, @dbkeator - i think it may be good to discuss the api a little bit as we work on the library.

for experiment it could look something like:

doc = nidm.Document()
project = doc.add_project(...)
project.add_session(...)
...
session = doc.add_session(...)
project = doc.add_project(session=session, ...)

#generators
doc.projects
doc.sessions

#queries
doc.find_project(name='crazyscan')
doc.find_participant()

for workflows:

doc = nidm.Document()
proc_exec = doc.add_process_execution()
proc_exec.add_specification(...)

getattr(proc_exec, NIDM.cmdline, None)

...

spec = doc.add_specification()
process_activity = doc.add_process_exec(specification=specification, ...)

#generators
doc.process_execs
doc.process_specs
doc.files

# built-in sort capability based on timestamp
sorted(doc.process_execs) # topological sort

also Constants.py should be generated automatically from the owl file. @smpadhy is going to look into it. this should allow us to do things like:

nidm.Project in addition to nidm['000123']

[greater good pledge] request for participation

hey NIDM family!

I'm creating a new initiative, The Greater Good that aims to highlight projects with no underlying incentives or ulterior motives - those that are "for the greater good." Many of the nidm projects (I believe) fit strongly within the criteria, and I'm hoping that the community would like to participate. Participation simply means adding the community name to the pledge, and then (optionally) adding a badge to any associated project repos.

Details are provided at the page, and any maintainers / users here are welcome to also join the organization The Good Labs if open source transparency is important to them. It's still early (I'm going to be creating media and other community interactions) and right now I'm getting in touch with projects that I've worked with.

Missing Git-annex external Dependency

Creating NIDM file...
Traceback (most recent call last):
File "/Users/nazekqueder/opt/anaconda3/bin/csv2nidm", line 7, in
exec(compile(f.read(), file, 'exec'))
File "/Users/nazekqueder/Documents/Coding/PyNIDM/bin/CSV2NIDM", line 7, in
main(sys.argv)
File "/Users/nazekqueder/Documents/Coding/PyNIDM/nidm/experiment/tools/CSV2NIDM.py", line 300, in main
num_sources = addGitAnnexSources(obj=acq_entity,filepath=args.csv_file,bids_root=os.path.dirname(args.csv_file))
File "/Users/nazekqueder/Documents/Coding/PyNIDM/nidm/experiment/Utils.py", line 1148, in addGitAnnexSources
repo = AnnexRepo(bids_root)
File "/Users/nazekqueder/opt/anaconda3/lib/python3.7/site-packages/datalad/support/repo.py", line 151, in call
instance = type.call(cls, *new_args, **new_kwargs)
File "/Users/nazekqueder/opt/anaconda3/lib/python3.7/site-packages/datalad/support/annexrepo.py", line 268, in init
self._init(version=version, description=description)
File "/Users/nazekqueder/opt/anaconda3/lib/python3.7/site-packages/datalad/support/annexrepo.py", line 1142, in _init
annex_options=opts)
File "/Users/nazekqueder/opt/anaconda3/lib/python3.7/site-packages/datalad/support/annexrepo.py", line 928, in _run_annex_command
self._check_git_annex_version()
File "/Users/nazekqueder/opt/anaconda3/lib/python3.7/site-packages/datalad/support/annexrepo.py", line 550, in _check_git_annex_version
raise MissingExternalDependency(**exc_kwargs)
datalad.support.exceptions.MissingExternalDependency: git-annex of version >= 7.20190503 is missing. Visit http://git-annex.branchable.com/install/
(base) dhcp-v126-066:repronim nazekqueder$

add Etelemetry to tools

Etelemetry software service to track usage....add to csv2nidm, bids2nidm, and probably the API in general. Query ReproNim about adding this

Please release/upload to pypi

as this beast to be used within datalad now, it would be nice to have it released and versioned
Note , that currently

$> python -c 'import nidm; print nidm.__version__'
0.1.dev

so released version should be 0.1.1 or 0.2.

ideally also would be great to see a conda package, and we will take care about neurodebian ;)

BIDSMRI2NIDM - remove dependencies on participants.tsv files

Currently BIDSMRI2NIDM gets a list of subject IDs + optional metadata from the participants.tsv file which is currently optional in the BIDS spec. Need to change converter to get subject IDs from the directory names using pybids layout.get_subjects().

nfo:fileName in constants.py

I fixed the nidm-experiment.owl file so that the term for file name (nfo:fileName) is imported correctly and is now available for use. Note that in constants.py it's called "filename":

NIDM_FILENAME = QualifiedName(provNamespace("nfo", NFO), "filename")

additional types serialized as Literals by provtoolbox?

Hey @satra,
In the NIDM-Exp API, when adding additional prov:types using the add_attributes function of provtoolbox, the additional rdf:types get serialized as Literals of type ^^xsd:string instead of URIs. Any idea how to change this? It makes querying the document for nidm:Project information quite challenging...

Here's an example: https://github.com/incf-nidash/PyNIDM/blob/master/nidm/experiment/tools/ds000030_single_subj.ttl#L31

Code that added this rdf:type is here:
https://github.com/incf-nidash/PyNIDM/blob/master/nidm/experiment/Project.py#L45

PluginException: No plugin registered for (ttl, <class 'rdflib.serializer.Serializer'>)

Originally mentioned in #10, running tests ATM still causes that error, and here is a full "how I did it":

(git)hopa:~/proj/PyNIDM[master]git
$> virtualenv --system-site-packages --python=python venvs/dev  
Running virtualenv with interpreter /usr/bin/python           
New python executable in /home/yoh/proj/PyNIDM/venvs/dev/bin/python
Installing setuptools, pkg_resources, pip, wheel...source done.

$> source venvs/dev/bin/activate 

$> pip install -e .                                           
Obtaining file:///home/yoh/proj/PyNIDM
Requirement already satisfied: prov in /usr/lib/python2.7/dist-packages (from nidm==0.1.dev0)
Requirement already satisfied: rdflib in /usr/lib/python2.7/dist-packages (from nidm==0.1.dev0)
Collecting graphviz (from nidm==0.1.dev0)
  Downloading graphviz-0.8.2-py2.py3-none-any.whl
Requirement already satisfied: pydotplus in /usr/lib/python2.7/dist-packages (from nidm==0.1.dev0)
Requirement already satisfied: pydot in /usr/lib/python2.7/dist-packages (from nidm==0.1.dev0)
Collecting validators (from nidm==0.1.dev0)
  Downloading validators-0.12.1.tar.gz
Requirement already satisfied: six>=1.4.0 in /usr/lib/python2.7/dist-packages (from validators->nidm==0.1.dev0)
Requirement already satisfied: decorator>=3.4.0 in /usr/lib/python2.7/dist-packages (from validators->nidm==0.1.dev0)
Building wheels for collected packages: validators
  Running setup.py bdist_wheel for validators ... done
  Stored in directory: /home/yoh/.cache/pip/wheels/00/4a/b0/a600f1daeb048823b584ca8687ca8402891b48606ab6f2f709
Successfully built validators
Installing collected packages: graphviz, validators, nidm
  Running setup.py develop for nidm
Successfully installed graphviz-0.8.2 nidm validators-0.12.1

$> python -m pytest -s -v .
============================== test session starts ==============================
platform linux2 -- Python 2.7.14+, pytest-3.3.2, py-1.5.2, pluggy-0.6.0 -- /home/yoh/proj/PyNIDM/venvs/dev/bin/python
cachedir: .cache
rootdir: /home/yoh/proj/PyNIDM, inifile:
plugins: xdist-1.22.2, localserver-0.3.7, forked-0.2, cov-2.5.1, hypothesis-3.44.1, celery-4.1.0
collected 11 items                                                              

nidm/experiment/tests/test_experiment.py::test_main FAILED                [  9%]
nidm/experiment/tests/test_experiment_basic.py::test_1 FAILED             [ 18%]
nidm/experiment/tests/test_experiment_basic.py::test_2 FAILED             [ 27%]
nidm/experiment/tests/test_experiment_basic.py::test_sessions_1 PASSED    [ 36%]
nidm/experiment/tests/test_experiment_basic.py::test_sessions_2 PASSED    [ 45%]
nidm/experiment/tests/test_experiment_basic.py::test_sessions_3 PASSED    [ 54%]
nidm/experiment/tests/test_experiment_basic.py::test_project_noparameters PASSED [ 63%]
nidm/experiment/tests/test_experiment_basic.py::test_project_emptygraph PASSED [ 72%]
nidm/experiment/tests/test_experiment_basic.py::test_project_uuid PASSED  [ 81%]
nidm/experiment/tests/test_experiment_basic.py::test_project_att PASSED   [ 90%]
nidm/experiment/tests/test_experiment_basic.py::test_session_noparameters PASSED [100%]

=================================== FAILURES ====================================
___________________________________ test_main ___________________________________

    def test_main():
>       main(sys.argv[1:])

nidm/experiment/tests/test_experiment.py:88: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
nidm/experiment/tests/test_experiment.py:78: in main
    f.write (project.serializeTurtle())
nidm/experiment/Core.py:303: in serializeTurtle
    return self.graph.serialize(None, format='rdf', rdf_format='ttl')
/usr/lib/python2.7/dist-packages/prov/model.py:1671: in serialize
    serializer.serialize(stream, **args)
/usr/lib/python2.7/dist-packages/prov/serializers/provrdf.py:101: in serialize
    container.serialize(buf, **newargs)
/usr/lib/python2.7/dist-packages/rdflib/graph.py:935: in serialize
    serializer = plugin.get(format, Serializer)(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'ttl', kind = <class 'rdflib.serializer.Serializer'>

    def get(name, kind):
        """
        Return the class for the specified (name, kind). Raises a
        PluginException if unable to do so.
        """
        try:
            p = _plugins[(name, kind)]
        except KeyError:
            raise PluginException(
>               "No plugin registered for (%s, %s)" % (name, kind))
E           PluginException: No plugin registered for (ttl, <class 'rdflib.serializer.Serializer'>)

/usr/lib/python2.7/dist-packages/rdflib/plugin.py:103: PluginException
____________________________________ test_1 _____________________________________

tmpdir = local('/home/yoh/.tmp/pytest-of-yoh/pytest-0/test_10')

    def test_1(tmpdir):
        tmpdir.chdir()
    
        project = Project()
    
        #save a turtle file
        with open("test.ttl",'w') as f:
>           f.write(project.serializeTurtle())

/home/yoh/proj/PyNIDM/nidm/experiment/tests/test_experiment_basic.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/yoh/proj/PyNIDM/nidm/experiment/Core.py:303: in serializeTurtle
    return self.graph.serialize(None, format='rdf', rdf_format='ttl')
/usr/lib/python2.7/dist-packages/prov/model.py:1671: in serialize
    serializer.serialize(stream, **args)
/usr/lib/python2.7/dist-packages/prov/serializers/provrdf.py:101: in serialize
    container.serialize(buf, **newargs)
/usr/lib/python2.7/dist-packages/rdflib/graph.py:935: in serialize
    serializer = plugin.get(format, Serializer)(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'ttl', kind = <class 'rdflib.serializer.Serializer'>

    def get(name, kind):
        """
        Return the class for the specified (name, kind). Raises a
        PluginException if unable to do so.
        """
        try:
            p = _plugins[(name, kind)]
        except KeyError:
            raise PluginException(
>               "No plugin registered for (%s, %s)" % (name, kind))
E           PluginException: No plugin registered for (ttl, <class 'rdflib.serializer.Serializer'>)

/usr/lib/python2.7/dist-packages/rdflib/plugin.py:103: PluginException
____________________________________ test_2 _____________________________________

tmpdir = local('/home/yoh/.tmp/pytest-of-yoh/pytest-0/test_20')

    def test_2(tmpdir):
        tmpdir.chdir()
    
        kwargs={Constants.NIDM_PROJECT_NAME:"FBIRN_PhaseII",Constants.NIDM_PROJECT_IDENTIFIER:9610,Constants.NIDM_PROJECT_DESCRIPTION:"Test investigation"}
        project = Project(attributes=kwargs)
    
        with open("test.ttl",'w') as f:
>           f.write(project.serializeTurtle())

/home/yoh/proj/PyNIDM/nidm/experiment/tests/test_experiment_basic.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/yoh/proj/PyNIDM/nidm/experiment/Core.py:303: in serializeTurtle
    return self.graph.serialize(None, format='rdf', rdf_format='ttl')
/usr/lib/python2.7/dist-packages/prov/model.py:1671: in serialize
    serializer.serialize(stream, **args)
/usr/lib/python2.7/dist-packages/prov/serializers/provrdf.py:101: in serialize
    container.serialize(buf, **newargs)
/usr/lib/python2.7/dist-packages/rdflib/graph.py:935: in serialize
    serializer = plugin.get(format, Serializer)(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'ttl', kind = <class 'rdflib.serializer.Serializer'>

    def get(name, kind):
        """
        Return the class for the specified (name, kind). Raises a
        PluginException if unable to do so.
        """
        try:
            p = _plugins[(name, kind)]
        except KeyError:
            raise PluginException(
>               "No plugin registered for (%s, %s)" % (name, kind))
E           PluginException: No plugin registered for (ttl, <class 'rdflib.serializer.Serializer'>)

/usr/lib/python2.7/dist-packages/rdflib/plugin.py:103: PluginException

pycharm debugging after switch to click

@djarecka After switching nidm_query.py to click, I can't seem to debug things in Pycharm. I have my configuration set to run the following:

Script: nidm_query.py
Script parameters: -q sample_query.txt -nl nidm.ttl -o test.csv
Working directory: /..../PyNIDM/nidm/experiment/tools

The debugger fails on import click even though it's an installed package. Seems from the error there's some parent package that needs to be loaded?

Connected to pydev debugger (build 143.2370)
Traceback (most recent call last):
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydevd.py", line 2411, in
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydevd.py", line 1802, in run
launch(file, globals, locals) # execute the script
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "nidm_query.py", line 40, in
import click
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydev_monkey_qt.py", line 71, in patched_import
return original_import(name, *args, **kwargs)
File "/Users/dbkeator/Documents/Coding/PyNIDM/nidm/experiment/tools/click.py", line 2, in
from .click_base import cli
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydev_monkey_qt.py", line 71, in patched_import
return original_import(name, *args, **kwargs)
SystemError: Parent module '' not loaded, cannot perform relative import

Use of generic Acquisitions and Acquisition Objects

In the nidm-experiment.owl file, I've been using a schema in which there is a generic acquisition activity called "Acquisition" and that activity has an associated "Acquisition Modality", which would cover things like "demographics", "behaviorial", "magnetic resonance imaging", "computed tomography", and would produce a generic "Acquisition Object" that would also have an associated "Acquisition Modality" and "Acquisition Method" (e.g., "susceptibility-weighted imaging"). Would that cause issues in PyNIDM? (Note that I haven't completely converted to that point of view as there are still a couple of terms that I have yet to change like "Behavioral Acquisition".)

validate data matches term definitions in csv2nidm

If user selects particular term to associate with column in CSV file, we should verify that labels in that column match what term specificies..e.g. if term label for categorical variable 'gender' says they should be 'M' or 'F' the CSV file column for gender should be coded as 'M' or 'F' and if not script should tell user they need to select a different term that matches their use or define a new one.

Add git-annex sources to bidsmri2nidm

When converting BIDS datasets provided through datalad, multiple prov:atLocation sources can be extracted from "git annex info" command about remotes hashes of clones...see git show git-annex:remote.log...cat .datalad/config gies the unique ID of the datalad dataset...can in the future ask datalad if it has this UUID...

bids conversion setup issues

@dbkeator:

  • pandas should be a requirement of pynidm since the converter needs this
  • the bids conversion scripts should be installed by setup.py instead of having to call it (one way to do this is using click)
  • conversion should be added to a test

@sanuann - could you please help learn and implement this in pynidm? (you can use nipype as an example for click)

sio:'subject role'

In constants.py the term subject is assigned to the sio: namespace. However, the actual SIO term is "subject role", which is not consistent with our naming convention, e.g. we don't have nidm:"research assistant role", but rather just nidm:"research assistant". Do we have the SIO term be a synonym to a NIDM term? This is also a general question about how we want to use terms that are already defined and in a namespace, but not in our particular format.

NIDM_PARTICIPANT = QualifiedName(provNamespace("sio", SIO),"Subject")

Magic missing in test setup?

I installed PyNIDM following the instructions on the frontpage. But I cannot run the tests:

% pytest-3
========================================================================== test session starts ==========================================================================
platform linux -- Python 3.6.3, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/mih/hacking/PyNIDM, inifile:
plugins: xonsh-0.5.12
collected 0 items / 2 errors                                                                                                                                             

================================================================================ ERRORS =================================================================================
_______________________________________________________ ERROR collecting nidm/experiment/tests/test_experiment.py _______________________________________________________
ImportError while importing test module '/home/mih/hacking/PyNIDM/nidm/experiment/tests/test_experiment.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
nidm/experiment/__init__.py:1: in <module>
    from .Core import Core
nidm/experiment/Core.py:4: in <module>
    from rdflib import Namespace
E   ModuleNotFoundError: No module named 'rdflib'
____________________________________________________ ERROR collecting nidm/experiment/tests/test_experiment_basic.py ____________________________________________________
ImportError while importing test module '/home/mih/hacking/PyNIDM/nidm/experiment/tests/test_experiment_basic.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
nidm/experiment/__init__.py:1: in <module>
    from .Core import Core
nidm/experiment/Core.py:4: in <module>
    from rdflib import Namespace
E   ModuleNotFoundError: No module named 'rdflib'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================== 2 error in 0.14 seconds ========================================================================

failure is not pytest-specific, nosetests has the same issue. But

% python --version
Python 3.6.3

% python -c "from rdflib import Namespace; print('happy')"
INFO:rdflib:RDFLib Version: 4.2.2
happy

% python -c "import nidm.experiment; print ('happy')"
INFO:rdflib:RDFLib Version: 4.2.2
happy

So the general installation seems to be working, but I am missing something to be able to run the tests.

missing "tabulate" library after pip install e .

Hi @albertcrowley,
I tried the installation instructions. In my new conda environment after "pip install -e ." I receive the following error even though this package has been added to nidm/version.py INSTALL_REQUIRES. If I instead run "python setup.py install" everything is ok. So, how do we edit the installation files to get "pip install -e ." working again?

(pynidm_py3) [~/Documents/Coding/PyNIDM]$ pynidm
Traceback (most recent call last):
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/bin/pynidm", line 6, in
from pkg_resources import load_entry_point
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 3254, in
def _initialize_master_working_set():
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 3237, in _call_aside
f(*args, **kwargs)
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 3266, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 584, in _build_master
ws.require(requires)
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 901, in require
needed = self.resolve(parse_requirements(requirements))
File "/Users/dbkeator/opt/anaconda3/envs/pynidm_py3/lib/python3.8/site-packages/pkg_resources/init.py", line 787, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'tabulate' distribution was not found and is required by pynidm

Incompatible with recent pybids?

>>> bidsmri2project('.')
Converting subject: 01
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-9ae7860adb47> in <module>()
----> 1 bidsmri2project('.')

/home/mih/hacking/PyNIDM/nidm/experiment/tools/BIDSMRI2NIDM.py in bidsmri2project(directory)
    190 
    191             #print(file_tpl.type)
--> 192             if file_tpl.modality == 'anat':
    193                 #do something with anatomicals
    194                 acq_obj = MRObject(acq)

/home/mih/env/datalad3-dev/lib/python3.6/site-packages/bids/layout/core.py in __getattr__(self, attr)
    283             return self.entities[attr]
    284         raise AttributeError("%s object has no attribute named %r" %
--> 285                              (self.__class__.__name__, attr))
    286 
    287     def __repr__(self):

AttributeError: BIDSFile object has no attribute named 'modality'

It seems that "modality" is in .entities['suffix'].

This is happening on current master, with pybids (0.8.0).

Question about evolution of PyNIDM and NIDM

Hi!

How different is the development of the actual NIDM ontology (especially NIDM-experiment) from this library?

I get the feel that this library evolves faster than the ontology, at least from what the repo contains.
It looks like there are a lot of terms referenced in the constants files that are missing or still not coded in the actual NIDM owl file.

Maybe I am missing something?

Thanks!
Santi

Should not "print"

DataLad is now using this as a library. It would be nice, if it would not print anything, but use a proper logger.

Constants.py - assessments

Hi @dbkeator -
In the current constants.py file, the terms for assessments are:

NIDM_ASSESSMENT_ACQUISITION = QualifiedName(provNamespace("nidm", NIDM), "assessment-instrument")
NIDM_ASSESSMENT_ENTITY = QualifiedName(provNamespace("nidm", NIDM), "assessment-instrument")

The term covering a generic assessment instrument already exists in the ontoneurolog import file: ontoneurolog_instruments_import.ttl in the imports file and there are more terms in that file that cover the different sub-classes of instruments (e.g., psychological, behavioral, neuroclinical).

add dct:isPartOf edges to DOT graphs

Function prov_to_dot from provtoolbox does not create edges in dot graph for relationships not defined in prov. In NIDM we use the dct:isPartOf relationship between sessions and projects, acquisition activities and sessions. PyNIDM's function:

def save_DotGraph(self,filename,format=None):
is used to create/write graph. Please add support for dct:isPartOf to dot object.

BIRNLex terms for roles of Investigator and Co-Investigator (active terminologies only?)

Currently, I have defined both of these terms as NIDM terms in nidm-experiment.owl. What is the current state of BIRNLex? I can create a BIRNLex imports file, if we agree to use these two terms. This is basically a question regarding our policy for using terminologies. Do they need to be active for us to reuse terms?

NIDM_PI = QualifiedName(provNamespace("birnlex", BIRNLEX), "birnlex_2152")
NIDM_COI = QualifiedName(provNamespace("birnlex", BIRNLEX),"birnlex_2199")

change model for diffusion scans

Associated b-value / b-vector files from BIDS dataset need to have nidm:AcquisitionObject type and nidm:b-value / nidm:b-vector types should be moved to tuples nidm:hadImageUsageType nidm:b-value/b-vector

participant.tsv column name breaks NIDM conversion/serialization

I pointed BIDSMRI2NIDM.py randomly to ds000200 from OpenFMRI. It seems it cannot handles spaces in column names.

Presumable cause:

% python -c 'print(repr(open("participants.tsv").readlines()[0]))'
'participant_id\tMnExposition\tage\tgender\tObvolume_mm3\tId12items\tavg_rating\tBOLD in VOI Olf\tnotes\n'

Log of explosion:

% ~/hacking/PyNIDM/nidm/experiment/tools/BIDSMRI2NIDM.py -d . -o please.ttl
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
Converting subject: 2001
Converting subject: 2002
Converting subject: 2003
Converting subject: 2004
Converting subject: 2005
Converting subject: 2006
Converting subject: 2007
Converting subject: 2008
Converting subject: 2009
Converting subject: 2010
Converting subject: 2011
Converting subject: 2012
Converting subject: 2013
Converting subject: 2014
Serializing NIDM graph and creating graph visualization..
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
http://bids.neuroimaging.io/BOLD in VOI Olf does not look like a valid URI, trying to serialize this will break.
Traceback (most recent call last):
  File "/home/mih/hacking/PyNIDM/nidm/experiment/tools/BIDSMRI2NIDM.py", line 318, in <module>
    main(sys.argv[1:])
  File "/home/mih/hacking/PyNIDM/nidm/experiment/tools/BIDSMRI2NIDM.py", line 313, in main
    f.write(project.serializeTurtle())
  File "/home/mih/hacking/PyNIDM/nidm/experiment/Core.py", line 300, in serializeTurtle
    return self.graph.serialize(None, format='rdf', rdf_format='ttl')
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/prov/model.py", line 2388, in serialize
    serializer.serialize(stream, **args)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/prov/serializers/provrdf.py", line 111, in serialize
    container.serialize(buf, **newargs)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/graph.py", line 947, in serialize
    serializer.serialize(stream, base=base, encoding=encoding, **args)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 232, in serialize
    if self.statement(subject) and not firstTime:
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 293, in statement
    return self.s_squared(subject) or self.s_default(subject)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 298, in s_default
    self.predicateList(subject)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 400, in predicateList
    self.verb(predicate, newline=True)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 404, in verb
    self.path(node, VERB, newline)
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 312, in path
    or self.p_default(node, position, newline)):
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 318, in p_default
    self.write(self.label(node, position))
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/plugins/serializers/turtle.py", line 334, in label
    return self.getQName(node, position == VERB) or node.n3()
  File "/home/mih/env/datalad3-dev/lib/python3.6/site-packages/rdflib/term.py", line 247, in n3
    raise Exception('"%s" does not look like a valid URI, I cannot serialize this as N3/Turtle. Perhaps you wanted to urlencode it?'%self)
Exception: "http://bids.neuroimaging.io/BOLD in VOI Olf" does not look like a valid URI, I cannot serialize this as N3/Turtle. Perhaps you wanted to urlencode it?

NIDM data structure as JSON-LD?

Is there a way to get the output of BIDS2NIDM as JSON-LD? ATM turtle is hard-coded, and I cannot see something in the Python API that would allow me to do all of what this tool does, but then serialize to something else.

I do not need a file in JSON-LD, the corresponding runtime data structure would be sufficient, and actually more useful.

Thanks!

pypi packing broken

BIDSMRI2NIDM and CSV2NIDM are capitalized on pypi package.

perhaps time to change the release process to go thrpugh standard travis/github actions deploy.

Tests todo

Test cases:

  1. Project- level tests
  • Instantiating Project class with no parameters should use Constants.p_graph ProvDocument() graph with namespaces included in Constants.py, add a prov:Activity to graph with rdf.types prov:Activity and Constants.NIDM_PROJECT types

  • Instantiating Project class with empty_graph=True should create new empty ProvDocument() with default ProvDocument() namespaces + NIDM namespace, add a prov:Activity to graph with rdf.types prov:Activity and Constants.NIDM_PROJECT types

  • Instantiating Project class with uuid=UUID should use UUID for subject of new project prov:Activity

  • Instantiating Project class with attributes={attributes_dict} should create new project prov:Activity, adding tuples in attributes_dict

  1. Session-level tests
  • Instantiating Session class with no parameters adds session prov:Activity to graph and links session prov:Activity to project with dct:isPartOf and adds session to project._sessions list

  • Instantiating Session class with parameter uuid=UUID, should use UUID for subject of new session prov:Activity and links session prov:Activity to project with dct:isPartOf and adds session to project._sessions list

  • Instantiating Session class with parameter attributes={attributes_dict}, adds session prov:Activity to graph and links session prov:Activity to project with dct:isPartOf and adds session to project._sessions list and adds tuples in attributes_dict

  1. Acquisition-level Tests
  • Instantiating Acquisition class adds acquisition activity links to session with dct:isPartOf, adds acquisition activity to session._acqusitions list

  • Instantiating Acquisition class with parameter uuid=UUID, should use UUID for subject of acquisition activity, link to session with dct:isPartOf, and add acquisition activity to session._acqusitions list

  • Instantiating Acquisition class with parameter attributes={attributes_dict} adds acquisition activity, links to session with dct:isPartOf, adds acquisition activity to session._acqusitions list, and adds tuples in attributes_dict

  1. AcquisitionObject Tests
  • Instantiating AcquisitionObject class adds acquisition entity link to acquisition activity with prov:wasGeneratedBy, adds acquisition entity to acquisition._acquisition_objects list
    object.add_attributes for Project, Session, Acquisition, and AcquisitionObject adds tuple to object

DWI datatype fails with newer versions of pybids

After pybids 0.7 you can no longer access entities as attributes.
So, on line 508 and 509 of BIDSMRI2NIDM.py the lines:

(508) if 'run' in file_tpl._fields:
(509) acq_obj.add_attributes({BIDS_Constants.json_keys["run"]:file_tpl.run})

Should be:
if 'run' in file_tpl.entities:
acq_obj.add_attributes({BIDS_Constants.json_keys["run"]:file_tpl. entities[‘run’]})

check existing namespaces before adding duplicates

Effects tool csv2nidm when adding data to existing NIDM file. If namespace already exists then don't add it a second time. This will also effect bidsmri2nidm once there's support for adding to existing NIDM files.

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.