Skip to content

Commit

Permalink
Apply pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed May 1, 2023
1 parent 57f67d6 commit 51c48bc
Show file tree
Hide file tree
Showing 100 changed files with 12,935 additions and 8,534 deletions.
23 changes: 11 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Creating a conda environment and installing the library (tested with OSX)
=========================================================================

macOS
-----
-----
.. code-block:: bash
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Expand Down Expand Up @@ -75,10 +75,10 @@ This program will convert a BIDS MRI dataset to a NIDM-Experiment RDF document.
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.
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.
and API Keys. Then set the environment variable INTERLEX_API_KEY with your key.
optional arguments:
-h, --help show this help message and exit
Expand Down Expand Up @@ -183,7 +183,7 @@ If you want to merge NIDM files on subject ID see pynidm merge
-o, --out_file TEXT File to write concatenated NIDM files
[required]
--help Show this message and exit.
visualize
---------
This command will produce a visualization(pdf) of the supplied NIDM files
Expand All @@ -197,7 +197,7 @@ named the same as the input files and stored in the same directories.
-nl, --nidm_file_list TEXT A comma separated list of NIDM files with full
path [required]
--help Show this message and exit.
merge
-----
This function will merge NIDM files. See command line parameters for
Expand Down Expand Up @@ -268,25 +268,25 @@ 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
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 +
(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
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:
Expand All @@ -304,7 +304,7 @@ Now that we have selected the variables, we can perform a linear regression. In
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.
-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.
Expand Down Expand Up @@ -645,4 +645,3 @@ Additional NIDM-related Tools
* Freesurfer stats -> NIDM <https://github.com/repronim/segstats_jsonld>
* FSL structural segmentation -> NIDM <https://github.com/ReproNim/fsl_seg_to_nidm>
* ANTS structural segmentation -> NIDM <https://github.com/ReproNim/ants_seg_to_nidm>
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ RUN git config --global user.name "docker user" && git config --global user.emai
ENV TMPDIR=/opt/project/cache

COPY . .

1 change: 0 additions & 1 deletion docker/Dockerfile-datalad
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ RUN wget -O- http://neuro.debian.net/lists/bionic.us-nh.full | tee /etc/apt/sour
RUN apt-get install -y git-annex-standalone

RUN datalad install ///abide2/RawData/NYU_1

10 changes: 5 additions & 5 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Docker and REST API

This dockerfile can be used to create a development docker container suitable for both
interactive use and also as a proof of concept REST API server.
interactive use and also as a proof of concept REST API server.

#Build the container

Expand All @@ -11,7 +11,7 @@ To build the container, start in this directory and use the command:
```
./build.sh
```

## Interactive

You can then run the container interactively with:
Expand All @@ -25,13 +25,13 @@ in the directory /opt/PyNIDM in the container.
## REST Server

This section assumes you have the PyNIDM source code in ~/PyNIDM. You should
also put any NIDM ttl files you want the REST s erver to process somewhere under the
also put any NIDM ttl files you want the REST s erver to process somewhere under the
~/PyNIDM/ttl directory. Once you have done those things, use the command:
```
./runrest.sh
```

This should start a HTTP server that is listening on port 5000 of your
This should start a HTTP server that is listening on port 5000 of your
local system. You should be able to connect to the following routes:
```
http://localhost:5000/projects
Expand All @@ -41,5 +41,5 @@ http://localhost:5000/projects/[Project-UUID]/subjects/[Subject-UUID]
```

After the server is started you can continue to modify the files in your
~/PyNIDM/ttl directory and those changes will immediately be reflected in the
~/PyNIDM/ttl directory and those changes will immediately be reflected in the
REST API results.
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

mkdir -p ../cache
sudo docker build -f Dockerfile -t pynidm .
sudo docker build -f Dockerfile-rest -t pynidm-rest .
sudo docker build -f Dockerfile-rest -t pynidm-rest .
51 changes: 31 additions & 20 deletions docker/rest-blaze.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
#!/usr/bin/python

from flask import Flask, request
from flask_restful import Resource, Api
import glob
from nidm.experiment.tools.rest import RestParser
import os
from flask import Flask, request
from flask_cors import CORS
from flask_restful import Api, Resource
from nidm.experiment.tools.rest import RestParser
import simplejson
import os


def getTTLFiles():
files = []
for filename in glob.glob('/opt/project/ttl/**/*.ttl', recursive=True):
for filename in glob.glob("/opt/project/ttl/**/*.ttl", recursive=True):
files.append(filename)
return files


class NIDMRest(Resource):
def get(self, all):

query_bits = []
for a in request.args.keys():
query_bits.append("{}={}".format(a, request.args.get(a)))
query = "&".join(query_bits)

files = getTTLFiles()
if len(files) == 0:
return ({'error' : 'No NIDM files found. You may need to add NIDM ttl files to ~/PyNIDM/ttl'})
restParser = RestParser(output_format=RestParser.OBJECT_FORMAT, verbosity_level=5)

json_str = simplejson.dumps(restParser.run(files, "{}?{}".format(all, query)), indent=2)
response = app.response_class(response=json_str, status=200, mimetype='application/json')
return {
"error": "No NIDM files found. You may need to add NIDM ttl files to ~/PyNIDM/ttl"
}
restParser = RestParser(
output_format=RestParser.OBJECT_FORMAT, verbosity_level=5
)

json_str = simplejson.dumps(
restParser.run(files, "{}?{}".format(all, query)), indent=2
)
response = app.response_class(
response=json_str, status=200, mimetype="application/json"
)

return response


class Instructions(Resource):
def get(self):

return ({'message' : 'You probably want to start at {}projects See instructions at PyNIDM/docker/README.md for details on the API and loading data.'.format(request.url_root)})

return {
"message": "You probably want to start at {}projects See instructions at PyNIDM/docker/README.md for details on the API and loading data.".format(
request.url_root
)
}


app = Flask(__name__)
CORS(app)
api = Api(app)
api.add_resource(Instructions, '/')
api.add_resource(NIDMRest, '/<path:all>')

if __name__ == '__main__':
api.add_resource(Instructions, "/")
api.add_resource(NIDMRest, "/<path:all>")

os.system('java -server -Xmx512mb -jar /opt/blazegraph.jar')
app.run(debug=True, host='0.0.0.0')
if __name__ == "__main__":
os.system("java -server -Xmx512mb -jar /opt/blazegraph.jar")
app.run(debug=True, host="0.0.0.0")
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading

0 comments on commit 51c48bc

Please sign in to comment.