{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8d48ca51-ba3b-412b-b5c1-8de044c96817", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loadLibrary\n", "remoteSourcesURL https://git0.fmf.uni-lj.si/studen/nixSuite/raw/master/remoteResources/resources.json\n", "{'labkeyInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'irAEMM': {'url': 'https://git0.fmf.uni-lj.si/studen/iraemm/archive/master.zip', 'branch': 'master', 'modules': ['iraemmBrowser']}, 'SlicerLabkeyExtension': {'url': 'https://git0.fmf.uni-lj.si/studen/SlicerLabkeyExtension/archive/SlicerExtensionIndex.zip', 'branch': 'SlicerExtensionIndex', 'modules': ['labkeyBrowser']}, 'limfomiPET': {'url': 'https://git0.fmf.uni-lj.si/studen/limfomiPET/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser', 'segmentationBrowser']}, 'parseConfig': {'url': 'https://git0.fmf.uni-lj.si/studen/parseConfig/archive/master.zip', 'branch': 'master', 'modules': []}, 'orthancInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'dynamicSPECT': {'url': 'https://git0.fmf.uni-lj.si/studen/dynamicSPECT/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser']}}\n", "{'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}\n", "File /home/studen/temp/labkeyInterface.zip: True\n" ] } ], "source": [ "#load required libraries\n", "import sys\n", "import os\n", "import chardet\n", "import json\n", "\n", "#you should get nixWrapper using an appropriate env\n", "#more details https://git0.fmf.uni-lj.si/studen/nixWrapper\n", "import nixWrapper\n", "nixWrapper.loadLibrary('labkeyInterface')\n", "import labkeyInterface\n", "import labkeyDatabaseBrowser\n", "import labkeyFileBrowser\n", "\n", "def connectDB(server):\n", " #check connectivity. This checks the configuration in $HOME/.labkey/network.json, \n", " #where paths to certificates are stored\n", " net=labkeyInterface.labkeyInterface()\n", " fconfig=os.path.join(os.path.expanduser('~'),'.labkey','{}.json'.format(server))\n", " net.init(fconfig)\n", " #this reports the certificate used\n", " try:\n", " print('Using: {}'.format(net.connectionConfig['SSL']['user']))\n", " except KeyError:\n", " pass\n", " #This gets a deafult CSRF code; It should report user name plus a long string of random hex numbers\n", " net.getCSRF()\n", " db=labkeyDatabaseBrowser.labkeyDB(net)\n", " fb=labkeyFileBrowser.labkeyFileBrowser(net)\n", " return db,fb" ] }, { "cell_type": "code", "execution_count": 4, "id": "1322d7a2-b34b-43ef-8c7a-74065d41b560", "metadata": {}, "outputs": [], "source": [ "def readFiles():\n", " db,fb=connectDB('labkey-public')\n", " return\n", " imageDir='preprocessedImages'\n", " idFilter={'variable':'ParticipantId','value':'1057/18','oper':'eq'}\n", " project='limfomiPET/Study'\n", " ds=db.selectRows(project,'study','Imaging1',[idFilter])\n", " localDir=os.path.join(os.path.expanduser('~'),'temp','limfomiPET')\n", " if not os.path.isdir(localDir):\n", " os.mkdir(localDir)\n", " for r in ds['rows']:\n", " print(r)\n", " remotePath='/'.join([imageDir,r['patientCode'],r['visitCode'],r['ctResampled']])\n", " urlPath=fb.formatPathURL(project,remotePath)\n", " #print('{}'.format(fb.entryExists(urlPath)))\n", " localPath=os.path.join(localDir,r['ctResampled'])\n", " fb.readFileToFile(urlPath,localPath)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "ca7a6974-8526-4039-9b8b-e5ee11e8eaed", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "User: andrej studen CSRF: 6c0eabd844a84d6713f144ede8aa881c\n" ] } ], "source": [ "readFiles()" ] }, { "cell_type": "code", "execution_count": null, "id": "e68e3f81-285e-46a7-a072-4c1b0a6618e2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "nix", "language": "python", "name": "nix" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }