Git Product home page Git Product logo

Comments (1)

nickhir avatar nickhir commented on June 14, 2024 1

In case anyone stumbles across this. You can use the imputation bot to download your results.
A script could look something like this:

### THIS SCRIPT USES THE IMPUTATIONBOT TO SUBMIT OUR IMPUTATION JOB TO THE SERVER AND DOWNLOAD THE RESULTS.
### BEFORE YOU CAN RUN THIS SCRIPT, YOU HAVE TO PROPERLY SET UP THE IMPUTATION BOT, WHICH IS SHOWN HERE:
### https://imputationserver.readthedocs.io/en/latest/workshops/ASHG2020/Session5/

import subprocess
import os
import requests
import json
import time

def listdir_fullpath(d):
    return [os.path.join(d, f) for f in os.listdir(d)]


# imputation server url
url = 'https://imputationserver.sph.umich.edu/api/v2'
token = "token"

# There should only be vcf files in that directory.
vcf_dir = "processed_vcfs"
vcfs = listdir_fullpath(vcf_dir)

imputation_bot_exe = "/g/imputationbot/imputationbot"

# add token to header (see Authentication)
headers = {'X-Auth-Token': token}
data = {
    'refpanel': 'hrc-r1.1',
    'population': 'eur',
    "mode": "imputation",
    "phasing": "eagle",
    "build": "hg19",
    "r2Filter": "0.3"
}

# submit new job
# open the files
files = [("files", open(i, "rb")) for i in vcfs]
print("Submitting Job")
r = requests.post(url + "/jobs/submit/minimac4", files=files, data=data, headers=headers)

if r.status_code != 200:
    print(r.json()['message'])
    raise Exception('POST /jobs/submit/minimac4 {}'.format(r.status_code))

# print message
job_id = (r.json()['id'])
print(f"Job was sucessfully submitted with id: {job_id}")

while True:
    # monitor the job status, as soon as it starts running execute the download command.
    r = requests.get(f"{url}/jobs/{job_id}", headers=headers).json()["running"]

    if r.status_code != 200:
        print(r.json()["message"])
        print("Continuing")
        continue

    # r -> True -> job is running
    # r -> False -> job is not running yet
    if r:
        print("Job started running. Downloading it as soon as it finishes")
        subprocess.run(f"{imputation_bot_exe} download {job_id}", shell=True)
        print(
            f"Encrypted zip files are located in {job_id} directory. The password necessary to decrypt the file was sent to the email you registered with")

        break
    else:
        subprocess.run(f"{imputation_bot_exe} jobs", shell=True)
        print("Job is still in the queuing.")
        time.sleep(45)

from imputationserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.