# Initialize PYTHONPATH for pyopencga
import sys
import os
from pprint import pprint

cwd = os.getcwd()
print("current_dir: ...."+cwd[-10:])

base_modules_dir = os.path.dirname(cwd)
print("base_modules_dir: ...."+base_modules_dir[-10:])

sys.path.append(base_modules_dir)

from pyopencga.opencga_config import ConfigClient
from pyopencga.opencga_client import OpenCGAClient
import json

"""
Explanation: pyOpenCGA basic alignment and coverage usage

[NOTE] The server methods used by pyopencga client are defined in the following swagger URL:
- http://bioinfodev.hpc.cam.ac.uk/opencga-test/webservices
[NOTE] Current implemented methods are registered at the following spreadsheet:
- https://docs.google.com/spreadsheets/d/1QpU9yl3UTneqwRqFX_WAqCiCfZBk5eU-4E3K-WVvuoc/edit?usp=sharing
Loading pyOpenCGA
End of explanation
"""


## Reading user config/credentials to connect to server
user_config_json = "./__user_config.json"
with open(user_config_json,"r") as f:
    user_credentials = json.loads(f.read())
    
print('User: {}***'.format(user_credentials["user"][:3]))

user = user_credentials["user"]
passwd = user_credentials["pwd"]

"""
Explanation: Setting credentials for LogIn
Credentials 
Plese add the credentials for opencga login into a file in json format and read them from there.
i.e:
file: __user_config.json
flie_content: {"user":"xxx","pwd":"yyy"}
End of explanation
"""


## Creating ConfigClient
host = 'http://bioinfodev.hpc.cam.ac.uk/opencga-test'
cc = ConfigClient()
config_dict = cc.get_basic_config_dict(host)
print("Config information:\n",config_dict)

"""
Explanation: Creating ConfigClient for server connection configuration
End of explanation
"""


oc = OpenCGAClient(configuration=config_dict, 
                   user=user, 
                   pwd=passwd)

## Getting the session id / token
token = oc.session_id
print("Session token:\n{}...".format(token[:10]))

oc = OpenCGAClient(configuration=config_dict, 
                   session_id=token)

"""
Explanation: LogIn with user credentials
End of explanation
"""


