Пример #1
0
def login(*args, **kwargs):
    """
    Prompt user for login information (domain/email/password).
    Domain, email and password are used to get the user's API key.

    Always updates the stored credentials file.
    """
    if args and args[0].api_key:
        # Handle command-line arguments if provided.
        solvebio.login(api_key=args[0].api_key)
    elif kwargs:
        # Run the global login() if kwargs are provided
        # or local credentials are found.
        solvebio.login(**kwargs)
    else:
        interactive_login()

    # Print information about the current user
    user = client.whoami()

    if user:
        print_user(user)
        save_credentials(user['email'].lower(), solvebio.api_key)
        _print_msg('Updated local credentials.')
        return True
    else:
        _print_msg('Invalid credentials. You may not be logged-in.')
        return False
Пример #2
0
def login(*args, **kwargs):
    """
    Prompt user for login information (domain/email/password).
    Domain, email and password are used to get the user's API key.

    Always updates the stored credentials file.
    """
    if args and args[0].api_key:
        # Handle command-line arguments if provided.
        solvebio.login(api_key=args[0].api_key)
    elif kwargs:
        # Run the global login() if kwargs are provided
        # or local credentials are found.
        solvebio.login(**kwargs)
    else:
        interactive_login()

    # Print information about the current user
    user = client.whoami()

    if user:
        print_user(user)
        save_credentials(user['email'].lower(), solvebio.api_key)
        _print_msg('Updated local credentials.')
        return True
    else:
        _print_msg('Invalid credentials. You may not be logged-in.')
        return False
def main():
    if len(sys.argv) < 3:
        print('Usage: {} <vault path> <local path>'.format(sys.argv[0]))
        sys.exit(1)

    solvebio.login()
    download_vault_folder(sys.argv[1], sys.argv[2], dry_run=True)
def main():
    if len(sys.argv) < 3:
        print('Usage: {} <vault path> <local path>'.format(sys.argv[0]))
        sys.exit(1)

    solvebio.login()
    download_vault_folder(sys.argv[1], sys.argv[2], dry_run=True)
Пример #5
0
def login_and_save_credentials(*args, **kwargs):
    """
    Domain, email and password are used to get the user's API key.
    """
    if args and args[0].api_key:
        # Handle command-line arguments if provided.
        logged_in = solvebio.login(api_key=args[0].api_key,
                                   api_host=solvebio.api_host)
    elif args and args[0].access_token:
        # Handle command-line arguments if provided.
        logged_in = solvebio.login(access_token=args[0].access_token,
                                   api_host=solvebio.api_host)
    elif solvebio.login(**kwargs):
        logged_in = True
    else:
        logged_in = False

    if logged_in:
        # Print information about the current user
        user = client.whoami()
        print_user(user)
        save_credentials(
            user['email'].lower(), client._auth.token,
            client._auth.token_type, solvebio.api_host)
        print('Updated local credentials file.')
    else:
        print('You are not logged-in. Visit '
              'https://docs.solvebio.com/#authentication to get started.')
Пример #6
0
def main(argv=sys.argv[1:]):
    """ Main entry point for SolveBio CLI """
    parser = SolveArgumentParser()
    args = parser.parse_solvebio_args(argv)

    solvebio.login(api_host=args.api_host or solvebio.api_host,
                   api_key=args.api_key or solvebio.api_key,
                   access_token=args.access_token or solvebio.access_token)

    return args.func(args)
Пример #7
0
    def test_init_login(self):
        from solvebio import login
        from solvebio.client import client
        _auth = client._auth

        client._auth = None
        login(api_key="TEST_KEY")
        self.assertEqual(client._auth.token, "TEST_KEY")

        # Reset the key
        client._auth = _auth
Пример #8
0
def import_file(args):
    """
    Given a dataset and a local path, upload and import the file(s).

    Command arguments (args):

        * create_dataset
        * template_id
        * genome_build
        * follow (default: False)
        * auto_approve (default: False)
        * dataset
        * file (list)

    """
    if not solvebio.api_key:
        solvebio.login()

    # Ensure the dataset exists. Create if necessary.
    try:
        dataset = solvebio.Dataset.retrieve(args.dataset)
    except solvebio.SolveError as e:
        if e.status_code != 404:
            raise e

        print("Dataset not found: {0}".format(args.dataset))

        if args.create_dataset:
            dataset = create_dataset(args)
        else:
            print("Tip: use the --create-dataset flag "
                  "to create one automatically")
            sys.exit(1)

    # Generate a manifest from the local files
    manifest = solvebio.Manifest()
    manifest.add(*args.file)

    # Create the manifest-based import
    imp = solvebio.DatasetImport.create(
        dataset_id=dataset.id,
        manifest=manifest.manifest,
        genome_build=args.genome_build,
        auto_approve=args.auto_approve)

    if args.follow:
        imp.follow()
    else:
        mesh_url = 'https://my.solvebio.com/jobs/imports/{0}'.format(imp.id)
        print("Your import has been submitted, view details at: {0}"
              .format(mesh_url))
Пример #9
0
import sys
import operator
import rebuildanal_helper
from collections import Counter
import Queue
import logging
import simplejson as json
import os
import bisect
import solvebio

solvebio.login()

###
# do it from json files
# chrom, start_position, rsid, reference_allele, alt (list), hugo_symbol,
# variant_classification
# amino acid residue (gene:pos)
###
#mutations = json.load(open('mutations.json'))
residues = json.load(open('residues.json')) 

### dictionary format
file = open('tcga_residues_dictionary')
tcga_residues = json.load(file)
file.close()

class Rows(object):
    def __init__(self,object):
        for x in object.keys():
            setattr(self, x, object[x])
Пример #10
0
import solvebio

solvebio.login()

vault = solvebio.Vault.get_personal_vault()

# The folders that will contain your dataset
path = '/SampleImport/1.0.0'

# The name of your dataset
dataset_name = 'SampleDataset'

# Create a dataset
dataset = solvebio.Dataset.get_or_create_by_full_path(
    '{0}:/{1}/{2}'.format(vault.name, path, dataset_name), )

# Create a manifest object and a file to it
manifest = solvebio.Manifest()
manifest.add_file('path/to/file.vcf.gz')

# Create the import
imp = solvebio.DatasetImport.create(dataset_id=dataset.id,
                                    manifest=manifest.manifest)

# Prints updates as the data is processed
# and indexed into SolveBio
imp.follow()

#
# You now have data!
#
Пример #11
0
def query_mutations(cnf, mutations):
    if not verify_module('solvebio'):
        err('Cannot import solvebio')
        return None

    saves_fpath = join(cnf.work_dir, 'solvebio.txt')
    if cnf.debug:
        if verify_file(saves_fpath, silent=True):
            info('Debug, reading hits from ' + saves_fpath)
            with open(saves_fpath) as f:
                for mut, l in zip(mutations, f):
                    if l:
                        l = l.strip().split('\t')
                        if len(l) == 2:
                            mut.solvebio = SolvebioRecord(clinsig=l[0],
                                                          url=l[1])
            info('Done, read ' + str(sum(1 for m in mutations if m.solvebio)) +
                 ' hits')
            return mutations

    ds = None
    from solvebio import login, Dataset, BatchQuery, SolveError
    try:
        login()
        ds = Dataset.retrieve('ClinVar/Variants')
    except SolveError:
        err(format_exc())
        err('Could not retrieve information for SolveBio, skipping')

    MAX_BATCH_SIZE = 250
    batches = []
    batch = None
    for i, m in enumerate(mutations):
        if i % MAX_BATCH_SIZE == 0:
            batch = []
            batches.append(batch)
        batch.append(ds.query().filter(gene_symbol=m.gene.name) \
            .position(m.chrom, position=m.pos) \
            .filter(allele=m.alt, reference_allele=m.ref))

    info('Querying mutations against SolveBio ClinVar depository...')
    try:
        for i, batch in enumerate(batches):
            if len(batches) > 1:
                info('  batch ' + str(i) + '...')
            for mut, res in zip(mutations, BatchQuery(batch).execute()):
                if res['results']:
                    solvebio_record = parse_response(res['results'][0], mut)
                    if solvebio_record:
                        mut.solvebio = solvebio_record
            info('  done, found ' +
                 str(sum(1 for m in mutations if m.solvebio)) + ' hits')
    except SolveError:
        err(format_exc())
        err('Could not retrieve information for SolveBio, skipping')

    if cnf.debug:
        with open(saves_fpath, 'w') as f:
            for mut in mutations:
                if mut.solvebio:
                    f.write(mut.solvebio.clinsig)
                    f.write('\t')
                    f.write(mut.solvebio.url)
                f.write('\n')
        info('Saved to ' + saves_fpath)

    info('-' * 70)
    return mutations