Esempio n. 1
0
def get_workflow_status(user):
    # go through every galaxy instance
    gits = GalaxyInstanceTracking.objects.filter(
        galaxyuser__internal_user=user)
    dj_wfs = Workflow.objects.all()
    # loop through instances
    status = []
    for git in gits:
        ## loop through workflows for that instance
        gi, gu = get_gi_gu(user, git)
        wc = WorkflowClient(gi)
        hc = HistoryClient(gi)
        wfs = wc.get_workflows()
        for wf in wfs:
            wfd = wc.show_workflow(wf['id'])
            winvoke = wc.get_invocations(wf['id'])
            for wi in winvoke:
                wid = wc.show_invocation(wf['id'], wi['id'])
                h_l = hc.get_histories(wid['history_id'], deleted=True)

                if h_l:
                    h = h_l[0]
                else:
                    continue
                sd = get_status_d(wid)
                sd['name'] = wfd['name']
                hd = hc.show_history(h['id'])
                sd['history_name'] = h['name']
                datetime_object = datetime.strptime(hd['update_time'],
                                                    '%Y-%m-%dT%H:%M:%S.%f')
                # sd['history_url'] =  '{}{}'.format(git.url, hd['url'])

                sd['update_time'] = datetime_object.strftime(
                    '%Y-%m-%d %H:%M:%S')
                sd['update_time_unix'] = unixtime(datetime_object)
                sd['galaxy_instance'] = git.name
                status.append(sd)

    status = sorted(status, key=lambda k: k['update_time_unix'], reverse=True)

    return status
def main():
    galaxyInstance = GalaxyInstance(url=GALAXY_URL, key=API_KEY)
    toolClient = ToolClient(galaxyInstance)
    historyClient = HistoryClient(galaxyInstance)
    workflowsClient = WorkflowClient(galaxyInstance)
    libraryClient = LibraryClient(galaxyInstance)
    datasetClient = DatasetClient(galaxyInstance)

    histories = historyClient.get_histories(deleted=False)
    for hist in histories:
        hist_id = hist['id']
        countSecondary = historyClient.show_matching_datasets(
            hist_id, name_filter=name_filter)
        if len(countSecondary) != 0:
            #print(countSecondary)
            file_path = dir_name + '/' + hist[
                'name'] + '_' + name_filter + '.' + ext
            #print(file_path)
            #print(countSecondary[0]['dataset_id'])
            datasetClient.download_dataset(countSecondary[0]['id'],
                                           file_path=file_path,
                                           use_default_filename=False)
    sys.exit()
def get_history_status(user, hist_id=None):
    # go through every galaxy instance
    gits = GalaxyInstanceTracking.objects.filter(
        galaxyuser__internal_user=user)

    # loop through instances
    status = []
    for git in gits:
        ## loop through workflows for that instance
        gi, gu = get_gi_gu(user, git)
        hc = HistoryClient(gi)
        hists = hc.get_histories()

        # loop through and create a list of dictionaries for our django table
        for hist in hists:

            sd = {}
            # add useful info
            if hist_id and hist['id'] != hist_id:
                continue

            history_info = hc.show_history(hist['id'])

            # add status info
            sd_bioblend = hc.get_status(hist['id'])
            state_details = sd_bioblend['state_details']
            sd.update(state_details)

            sd['estimated_progress'] = sd_bioblend['percent_complete']
            datetime_object = datetime.strptime(history_info['update_time'],
                                                '%Y-%m-%dT%H:%M:%S.%f')
            sd['update_time'] = datetime_object.strftime('%Y-%m-%d %H:%M:%S')
            sd['update_time_unix'] = unixtime(datetime_object)
            sd['galaxy_instance'] = git.name

            sd['name'] = hist['name']

            hsq = History.objects.filter(galaxy_id=hist['id'],
                                         galaxyinstancetracking=git)

            if hsq:

                hs = hsq[0]
                hs.name = hist['name']
                hs.update_time = datetime_object.strftime('%Y-%m-%d %H:%M:%S')
                hs.empty = state_details['empty']
                hs.error = state_details['error']
                hs.failed_metadata = state_details['failed_metadata']
                hs.new = state_details['new']
                hs.ok = state_details['ok']
                hs.paused = state_details['paused']
                hs.running = state_details['running']
                hs.queued = state_details['queued']
                hs.setting_metadata = state_details['setting_metadata']
                hs.upload = state_details['upload']
                hs.estimated_progress = sd_bioblend['percent_complete']
            else:
                hs = History(
                    galaxyinstancetracking=git,
                    name=hist['name'],
                    update_time=datetime_object.strftime('%Y-%m-%d %H:%M:%S'),
                    empty=state_details['empty'],
                    error=state_details['error'],
                    failed_metadata=state_details['failed_metadata'],
                    new=state_details['new'],
                    ok=state_details['ok'],
                    paused=state_details['paused'],
                    running=state_details['running'],
                    queued=state_details['queued'],
                    setting_metadata=state_details['setting_metadata'],
                    upload=state_details['upload'],
                    galaxy_id=hist['id'],
                    estimated_progress=sd_bioblend['percent_complete'])

            hs.save()
            sd['history_data_bioblend_list'] = '/galaxy/history_data_bioblend_list/{}'.format(
                hs.pk)
            status.append(sd)

    status = sorted(status, key=lambda k: k['update_time_unix'], reverse=True)

    return status
Esempio n. 4
0
#!/usr/bin/python
import sys;
import galaxy_key;
from bioblend.galaxy import GalaxyInstance
from bioblend.galaxy.libraries import LibraryClient
from bioblend.galaxy.histories import HistoryClient
#Create a file called galaxy_key and add your key there

gi = GalaxyInstance(url=galaxy_key.galaxy_host, key=galaxy_key.galaxy_key);

hc = HistoryClient(gi);

my_history = hc.get_histories()[0];

my_history_id = my_history['id'];

dataset = hc.show_matching_datasets(my_history_id, 'sum_vector')[0];

dataset_provenance = hc.show_dataset_provenance(my_history_id, dataset['id']);

print(dataset_provenance);


Esempio n. 5
0
def getGalaxyData(accession, dataType, species, foldChangeOnly):

    api_key = 'ENTER_API_KEY'
    galaxy_host = 'http://localhost:8080'

    gi = GalaxyInstance(url=galaxy_host, key=api_key)

    history_client = HistoryClient(gi)

    dataDirectory = "Sybil/Shiny/data/" + accession
    if not os.path.exists(dataDirectory):
        os.makedirs(dataDirectory)

    wwwDirectory = "Shiny/www/microarrayQC.html/" + accession
    if not os.path.exists(wwwDirectory):
        os.makedirs(wwwDirectory)

    wwwDirectoryPlots = "Shiny/www/plots/" + accession
    if not os.path.exists(wwwDirectoryPlots):
        os.makedirs(wwwDirectoryPlots)

    #get the most recent history
    history = history_client.get_histories(name=accession)[0]

    #get the experiment level data
    getPCA(history, history_client, dataDirectory, galaxy_host)
    getChrDirTable(history, history_client, dataDirectory, galaxy_host)
    if dataType == "Microarray":
        getQC(history, history_client, wwwDirectory, galaxy_host)
    comparisons = getComparisonsTable(history, history_client, dataDirectory,
                                      galaxy_host)

    number_of_comparisons = -1
    for line in open(comparisons):
        if not line.isspace():
            number_of_comparisons += 1

    if foldChangeOnly == "FALSE":
        pvalues = ["1", "0.05"]
        foldchanges = ["1", "1.5", "2"]
        thresholds = list(itertools.product(pvalues, foldchanges))
        thresholds.pop(0)
    else:
        pvalues = ["1"]
        foldchanges = ["1.5", "2"]
        thresholds = list(itertools.product(pvalues, foldchanges))

    for i in reversed(range(number_of_comparisons)):

        getFoldChange(i, history, history_client, dataDirectory, galaxy_host)

    for index, values in reversed(
            list(
                enumerate(
                    list(
                        itertools.product(range(number_of_comparisons),
                                          thresholds))))):

        (comparison, (pvalue, foldchange)) = values

        print(index)
        print(values)

        getStringNetworks(index, comparison, history, history_client,
                          dataDirectory, galaxy_host)
        getBioGridNetworks(index, comparison, history, history_client,
                           dataDirectory, galaxy_host)

        getPathways(index, comparison, pvalue, foldchange, history,
                    history_client, dataDirectory, galaxy_host)

        getDrugEnrichment(index, comparison, pvalue, foldchange, history,
                          history_client, dataDirectory, galaxy_host)
        getGOEnrichment(index, comparison, pvalue, foldchange, history,
                        history_client, dataDirectory, wwwDirectoryPlots,
                        galaxy_host)

        if species in ["Human", "Mouse"]:
            getTFs(index, comparison, pvalue, foldchange, history,
                   history_client, dataDirectory, galaxy_host)