Commit 6d6d6e12 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'py-scripts' into 'master'

Py scripts

See merge request !1
parents cefcb263 a8aad40d
_site
.sass-cache
.jekyll-metadata
.idea
.cache
builds
test
Gemfile.lock
.DS_Store
##################################################
## MINERVA API version: 14.0
## Script purpose: An example of MINERVA API calls adding curators form the file users.txt
## Date: 23/03/2020
## Author: Piort Gawron (piotr.gawron@uni.lu)
## MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/users/
##################################################
### A convenience function to handle the text files and the server repsonses
import csv
import requests
session = requests.Session()
### INPUT YOUR CREDENTIALS TO LOGIN to PD map instance
login = " "
password = " "
api_url = "https://pdmap.uni.lu/minerva/api/"
# LOGIN to PD map instance with your credentials
login_request = session.post(api_url+"/doLogin", data = {'login': login, 'password': password})
print(login_request.text)
print(session.cookies.get_dict())
# READ USER LIST from the users.txt
with open("users.txt") as tsv:
for line in csv.reader(tsv, delimiter="\t"):
user_email = line[0]
user_name = line[1]
user_surname = line[2]
user_login = line[3]
user_password = line[4]
print ("User: ",user_login)
# GET USER DETAILS (check if user_login already exists in MINERVA)
user_request = session.get(api_url+"/users/"+user_login)
if user_request.status_code != 200: # if user does not exist
print("Creating")
# CREATE NEW USER with details provided in the file users.txt
create_user_request = session.post(api_url+"/users/"+user_login,
data = {'name':user_name, 'surname': user_surname, 'email':user_email, 'password':user_password})
print(create_user_request.status_code)
else:
print("User Exists")
# GET existing USER details
specific_user_data = session.get(api_url+"/users/"+user_login)
print(specific_user_data.text)
# UPDATE USER user_login details as per the file users.txt
update_user_request = session.patch(api_url+"/users/"+user_login,
data = '{"user":{"name":"'+user_name+'", "surname": "'+user_surname+'", "email":"'+user_email+
'", "password":"'+user_password+'"}}')
print(update_user_request.status_code)
# MODIFY USER PRIVILEGES from 'user' onto 'curator'
update_privileges_request = session.patch(api_url+"/users/"+user_login+
":updatePrivileges", data = '{"privileges":{"IS_CURATOR":true, "IS_ADMIN":false}}')
print(update_privileges_request.status_code)
curator-anna@dot.com Anna Kate anna.kate3 test1
curator-mike@dot.com Mike John mike.john3 test2
requests
\ No newline at end of file
##################################################
## MINERVA API version: 14.0
## Script purpose: An example of MINERVA API calls uploading zipped project
## Date: 23/03/2020
## Author: Piort Gawron (piotr.gawron@uni.lu)
## MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/projects/
##################################################
import requests
import os
import json
session = requests.Session()
### INPUT YOUR CREDENTIALS TO LOGIN to PD map instance
login = " "
password = " "
api_url = "https://pdmap.uni.lu/minerva/api/"
map_file = "example_advanced.zip"
# LOGIN to PD map instance with your credentials
login_request = session.post(api_url+"/doLogin", data = {'login': login, 'password': password})
print(login_request.text)
print(session.cookies.get_dict())
# UPLOAD FILE TO THE SYSTEM
stat_info = os.stat(map_file)
with open(map_file, mode ="rb") as f: file_content = f.read()
# Before creating a new project in MINERVA, source file 'map_file' must be uploaded to the instance (MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/files/)
# Allocate memory in the system for 'map_file', which length is 'stat_info.st_size' bytes
create_file_request = session.post(api_url+"/files/", data = {'filename': map_file, 'length': stat_info.st_size})
# Get the information about the uploaded file: the 'id' is necessary to upload the file's content.
content = json.loads(create_file_request.text)
file_id = content["id"]
# Upload file's content to the instance
upload_content_request = session.post(api_url+"/files/"+str(file_id)+":uploadContent", data = file_content)
# CREATE PROJECT FROM FILE
project_id = "adv_"+str(file_id)
# DEFINE PROJECT PARAMETERS (what is what in the zip file)
data = [
('projectId', project_id),
('name', ''),
('parser', 'lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser'),
('file-id', str(file_id)),
('auto-resize', 'true'),
('cache', 'false'),
('notify-email', ''),
('disease', ''),
('version', ''),
('organism', ''),
('mapCanvasType', 'OPEN_LAYERS'),
('sbgn', 'false'),
('semantic-zoom', 'false'),
('annotate', 'false'),
('verify-annotations', 'false'),
('zip-entries[0][_type]', 'MAP'),
('zip-entries[0][_filename]', 'example_advanced_map.xml'),
('zip-entries[0][_data][root]', 'true'),
('zip-entries[0][_data][name]', 'example_advanced_map'),
('zip-entries[0][_data][type][id]', 'UNKNOWN'),
('zip-entries[0][_data][type][name]', 'Unknown'),
('zip-entries[1][_type]', 'IMAGE'),
('zip-entries[1][_filename]', 'images/coords.txt'),
('zip-entries[2][_type]', 'IMAGE'),
('zip-entries[2][_filename]', 'images/overview_sub.png'),
('zip-entries[3][_type]', 'IMAGE'),
('zip-entries[3][_filename]', 'images/overview_main.png'),
('zip-entries[4][_type]', 'OVERLAY'),
('zip-entries[4][_filename]', 'overlays/example_upload_basic.txt'),
('zip-entries[4][_data][name]', 'Advanced example'),
('zip-entries[4][_data][description]', 'Advanced example of custom layout'),
('zip-entries[5][_type]', 'MAP'),
('zip-entries[5][_filename]', 'submaps/mapping.xml'),
('zip-entries[5][_data][mapping]', 'true'),
('zip-entries[5][_data][name]', 'mapping'),
('zip-entries[5][_data][type][id]', 'UNKNOWN'),
('zip-entries[5][_data][type][name]', 'Unknown'),
('zip-entries[6][_type]', 'MAP'),
('zip-entries[6][_filename]', 'submaps/example_submap.xml'),
('zip-entries[6][_data][name]', 'example_submap'),
('zip-entries[6][_data][type][id]', 'UNKNOWN'),
('zip-entries[6][_data][type][name]', 'Unknown'),
]
# AND CREATE A PROJECT
create_map_request = session.post(api_url+"/projects/"+project_id, data = data)
print(create_map_request.text)
##################################################
## MINERVA API version: 14.0
## Script purpose: An example of MINERVA API calls uploading overlays
## Date: 23/03/2020
## Author: Piort Gawron (piotr.gawron@uni.lu)
## MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/projects/
##################################################
import requests
import os
import json
session = requests.Session()
### INPUT YOUR CREDENTIALS TO LOGIN to PD map instance
login = " "
password = " "
api_url = "https://pdmap.uni.lu/minerva/api/"
overlay_file = "example_upload_basic.txt"
project_id = "empty"
# LOGIN to PD map instance with your credentials
login_request = session.post(api_url+"/doLogin", data = {'login': login, 'password': password})
print(login_request.text)
print(session.cookies.get_dict())
# UPLOAD OVERLAY FILE TO THE SYSYETM
stat_info = os.stat(overlay_file)
with open(overlay_file) as f: file_content = f.read()
# Before addind an overlay in MINERVA, data overlay file must be uploaded to the instance (MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/files/)
# Allocate memory in the system for 'overlay_file', which length is 'stat_info.st_size' bytes
create_file_request = session.post(api_url+"/files/", data = {'filename': overlay_file, 'length': stat_info.st_size})
# Get the information about the uploaded file: the 'id' is necessary to upload the file's content
content = json.loads(create_file_request.text)
file_id = content["id"]
# Upload file's content to the instance
upload_content_request = session.post(api_url+"/files/"+str(file_id)+":uploadContent", data = file_content)
# CREATE DATA OVERLAY FROM UPLOADED FILE
create_overlay_request = session.post(api_url+"/projects/"+project_id+"/overlays/", data = {"fileId":file_id, "filename":overlay_file, "name":"auto-overlay-simple"+str(file_id), "description":"there is a data overlay", "googleLicenseConsent":"true"})
print("Overlay Added: ", create_overlay_request.text)
NAME VALUE
SNCA -0.5
PARK2 0.75
\ No newline at end of file
##################################################
## MINERVA API version: 14.0
## Script purpose: An example of MINERVA API calls adding new project
## Date: 23/03/2020
## Author: Piort Gawron (piotr.gawron@uni.lu)
## MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/projects/
##################################################
import requests
import os
import json
import time
session = requests.Session()
### INPUT YOUR CREDENTIALS TO LOGIN to PD map instance
login = " "
password = " "
api_url = "https://pdmap.uni.lu/minerva/api/"
map_file = "example_map.xml"
# LOGIN to PD map instance with your credentials
login_request = session.post(api_url+"/doLogin", data = {'login': login, 'password': password})
print(login_request.text, "\n")
print(session.cookies.get_dict(), "\n")
# UPLOAD FILE TO THE SYSTEM
stat_info = os.stat(map_file)
with open(map_file) as f: file_content = f.read()
# Before creating a new project in MINERVA, source file 'map_file' must be uploaded to the instance (MANUAL: https://minerva.pages.uni.lu/doc/api/14.0/files/)
# Allocate memory in the system for 'map_file', which length is 'stat_info.st_size' bytes
create_file_request = session.post(api_url+"/files/", data = {'filename': map_file, 'length': stat_info.st_size})
# Get the information about the uploaded file: the 'id' is necessary to upload the file's content.
content = json.loads(create_file_request.text)
file_id = content["id"]
# Upload file's content to the instance
upload_content_request = session.post(api_url+"/files/"+str(file_id)+":uploadContent", data = file_content)
# CREATE THE PROJECT
project_id = "map_"+str(file_id)
project_name = "An example"
create_map_request = session.post(api_url+"/projects/"+project_id, data = {"file-id":file_id, "name": project_name , "version": "example", "mapCanvasType":"OPEN_LAYERS", "parser":"lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser"})
time.sleep(1)
# GET LIST of all (sub)maps in the project
get_submaps_request = session.get(api_url+"/projects/"+project_id+"/models/")
content = json.loads(get_submaps_request.text)
# In this example there is only one map uploaded
submap_id = content[0]['idObject']
# PUT A COMMENT to the map pinned to the coordinates (100.00,100.00)
create_comment_request = session.post(api_url+"/projects/"+project_id+"/comments/models/"+str(submap_id)+"/points/100.00,100.00", data = {"name":"Your Name", "email":"your_email@dot.com", "content":"automatically generated content","pinned":"true"})
print("Comment details:", create_comment_request.text)
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment