{"id":18142420,"url":"https://github.com/benoitberanger/nifti2database","last_synced_at":"2025-04-06T19:20:42.833Z","repository":{"id":117580383,"uuid":"481218347","full_name":"benoitberanger/nifti2database","owner":"benoitberanger","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-03T10:06:27.000Z","size":94,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-13T01:24:55.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benoitberanger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-13T13:01:01.000Z","updated_at":"2024-06-04T08:11:12.000Z","dependencies_parsed_at":"2024-06-03T12:10:50.262Z","dependency_job_id":null,"html_url":"https://github.com/benoitberanger/nifti2database","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitberanger%2Fnifti2database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitberanger%2Fnifti2database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitberanger%2Fnifti2database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benoitberanger%2Fnifti2database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benoitberanger","download_url":"https://codeload.github.com/benoitberanger/nifti2database/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535897,"owners_count":20954643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-01T18:21:56.813Z","updated_at":"2025-04-06T19:20:42.814Z","avatar_url":"https://github.com/benoitberanger.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nifti2database\n\n## Usage\n```\nusage: nifti2database [-h] -i DIR [DIR ...] [-o DIR] [--connect | --prepare] [--config_file FILE] [--credentials FILE] [-v]\n\n    Parse nifti and json sidecare paramters and export them into a database for easy query.\n    \n\nRequired arguments:\n  -i DIR [DIR ...], --in_dir DIR [DIR ...]\n                        Nifti directories that will be parsed.\n                        This directory is usually in xnat/archive.\n                        This argument accepts several paths. You can use syntax such as /path/to/nii/2021_*\n\nOptional arguments:\n  -h, --help            show this help message and exit\n  -o DIR, --out_dir DIR\n                        Output directory, receiving the log file.\n  --connect             Use psycopg2.connect() to execute SQL 'INSERT' request (default)\n  --prepare             Do not connect and write all SQL 'INSERT' lines in an output file\n  --config_file FILE    If you want to use non-coded sequences such as new Products, WIP or C2P,\n                        you can provide a config file.\n                        Default location is ~/niix2bids_config_file/siemens.py\n                        If default location is not present, try to use the template file \n                        located in [niix2bids]/config_file/siemens.py\n  --credentials FILE    [nifti2database] will by default look for a credential json files \n                        located here : ~/credentials_nifti2database.json \n                        Otherwise, the user can provide it's path using this argument \n                        The file should lool like this :  \n                        { \n                            \"user\": \"username\", \n                            \"password\": \"********\", \n                            \"database\": \"mydatabase\", \n                            \"host\": \"ip_adress/host_name\", \n                            \"port\": \"5432\", \n                            \"schema: \"myschema\", \n                            \"table: \"mytable\" \n                           [\"sslmode\": \"disable\"] \n                           [\"gssencmode\": \"disable\"] \n                        } \n                        !!! fields in [brackets] are optional, it depends on the server config \n                        \n  -v, --version         show program's version number and exit\n\nnifti2database version = 3.0.0\n```\n\n## Installation\n\n### Python version \u0026 other dependencies \n\n#### Python version\n\n`python \u003e= 3.10` Tested on `3.10`\n\n#### Package dependencies\n- `pandas` # for DataFrame\n- `nibabel` # to read nifti header\n- `psycopg2-binary` # postgresql connection\n- `niix2bids` # decision tree of the nifti \u0026 json fields\n- `Flask` # for API using HTTP\n\n## PostgreSQL\nSome notes/commands for initialization of the test database, schema and table are in [db_scripts](db_scripts)\n\n### How to\n\n#### Recommended setup\n\nUse [conda](https://docs.conda.io/en/latest/miniconda.html) to create a new python environment.\n\n**Standard**\n\n```shell\nconda create --name nifti2database python=3.10\nconda activate nifti2database\npip install git+https://github.com/benoitberanger/nifti2database\n```\n\n**Developer**\n\nIf you want to install in \"developer\" mode using the Git local repository, clone the repo before, then change the installation line :\n\n```shell\ncd /path/to/mydir/\ngit clone https://github.com/benoitberanger/nifti2database\nconda create --name nifti2database python=3.10\nconda activate nifti2database\npip install -e nifti2database/\n```\n\n\n#### **NOT** recommended installation procedure\n\n`pip install git+https://github.com/benoitberanger/nifti2database`  \nThe installation might crash because of wrong dependency management.\n\n## Known issues\n\n`pip install nifti2database` is not possible yet. I did not register this packaged on https://pypi.org.\n\n\n# Perform SQL requests\n\n## Software\nhttps://dbeaver.io/  \nDBeaver can connect to a database, have a script editor to execute requests in 1 click and display the result\n\n## Demo\n\n[sample_request.sql](sample_request.sql)\n\nExample :\n\n```pgsql\n-- count different resolution for mprage\nselect distinct dict-\u003e'Resolution', count(*)  from xdat_search.nifti_json\nwhere dict-\u003e\u003e'PulseSequenceName'='tfl' and jsonb_typeof(dict-\u003e'InversionTime')='number'\ngroup by dict-\u003e'Resolution' order by count desc;\n```\n\n|resolution|count|\n|----------|-----|\n|[1, 1, 1]|15827|\n|[1.2, 1.25, 1.25]|2013|\n|[1.1, 1.102, 1.102]|1473|\n|[0.8, 0.8, 0.8]|1276|\n|[1.1, 1.094, 1.094]|906|\n|[1.1, 1, 1]|717|\n|[1.2, 1.055, 1.055]|371|\n|[0.7, 0.7, 0.7]|346|\n|[0.9, 0.889, 0.889]|238|\n|[1.2, 1, 1]|226|\n|[1.2, 0.938, 0.938]|76|\n|[0.5, 0.5, 0.5]|73|\n|[0.6, 0.602, 0.602]|73|\n|[0.82, 0.82, 0.8]|72|\n|[1, 0.977, 0.977]|63|\n|[0.602, 0.602, 0.6]|23|\n|[0.802, 0.802, 0.8]|22|\n|[0.9, 0.898, 0.898]|19|\n|[0.9, 0.896, 0.896]|18|\n|[0.9, 0.903, 0.903]|18|\n\n## Python script to send request\n[template_request.py](template_request.py)\n\n# API\n\n## Flask\n[Flask](https://flask.palletsprojects.com/) is used to build an API using HTTP\n\n### Syntax\n`POST` with :\n- address : `http://ipaddress:port/nifti2database`\n- header : `Content-Type: application/json` to say it's JSON\n- data : _see just bellow_\n\n```json\n{\"args\":\"\u003csame args as the CLI\u003e\"}\n```\nIn the `args` field, just use the same arguments as the CLI. Such as :\n```json\n{\"args\":\"-i /path/to/data --credentials /path/to/credentials.json\"}\n```\n\n### is it running ?\n`GET` request at the root `http://ipaddress:port/` will send a back a message : `API is running`  \n`GET` request at  `http://ipaddress:port/help` will send back the help of the CLI\n\n## Docker\n[Docker](https://docs.docker.com/) is used as container\n\n### Build\n```bash\ndocker build -f Dockerfile -t nifti2database .\n```\n\n### Run\n**!!! incomplete command !!!** :\n```bash\ndocker run -p 5000:5000 nifti2database\n```\nThe command misses mounting points :\n- to the credential JSON file\n- to the data directory\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitberanger%2Fnifti2database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenoitberanger%2Fnifti2database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenoitberanger%2Fnifti2database/lists"}