跳转到主要内容

用于与Galaxy服务器交互的命令行实用程序(http://galaxyproject.org/)。

项目描述

PyPi Documentation Requirements Status Build Status License

用于协助与Galaxy服务器工作的命令行实用程序。

安装

$ pip install galaxy-parsec
$ parsec init

支持Python 3.6+

有问题吗?

Gitter

快速入门

此快速入门演示了使用parsec命令操作Galaxy历史和数据集。如果您还没有,您可能需要安装jq

连接到Galaxy服务器

要连接到正在运行的Galaxy服务器,您需要该实例的账户和账户的API密钥。获取API密钥的说明可以在http://wiki.galaxyproject.org/Learn/API找到。

首先初始化parsec

$ parsec init

初始化后,parsec将可用于命令行。请注意,创建数据库或访问用户API密钥等操作需要管理员账户。您的配置必须允许访问/api而不需要用户名或密码。更多信息可以在https://galaxyproject.org/admin/config/performance/production-server/找到。

Parsec简介

Parsec 是一组自动生成的 BioBlend 函数包装器。我发现自己编写了大量的小型/一次性脚本,用于调用简单的 bioblend 函数。这些脚本难以组合和使用在 Linux 友好的方式。我在所有这些实用脚本之间复制和粘贴代码。

Parsec 是解决所有这些问题的答案。它提取了我所编写的所有单独的函数,作为可以连接在一起、并行运行的独立 CLI 命令。

安装后,运行 parsec 将显示您可以执行的子命令列表。

$ parsec
Usage: parsec [OPTIONS] COMMAND [ARGS]...

  Command line wrappers around BioBlend functions. While this sounds
  unexciting, with parsec and jq you can easily build powerful command line
  scripts.

Options:
  --version               Show the version and exit.
  -v, --verbose           Enables verbose mode.
  --galaxy_instance TEXT  name of galaxy instance from ~/.planemo.yml
                          [required]
  --help                  Show this message and exit.

Commands:
  config
  datasets
  datatypes
  folders
  forms
  ...

这些命令中每个都有更多的子命令

$ parsec histories
Usage: parsec histories [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  create_dataset_collection       Create a new dataset collection
  create_history                  Create a new history, optionally setting
                                  the...
  create_history_tag              Create history tag
  delete_dataset                  Mark corresponding dataset as deleted.
  delete_dataset_collection       Mark corresponding dataset collection as...
  delete_history                  Delete a history.
  download_dataset                Deprecated method, use...
  download_history                Download a history export archive.
  export_history                  Start a job to create an export archive
                                  for...
  ...

查看历史记录和数据集

要获取您账户中当前历史记录的信息,请调用 history get_histories,然后我们将将其传递给一个 jq 命令,该命令从 JSON 数组中选择第一个元素。

$ parsec histories get_histories | jq '.[0]'

Parsec 将回应您第一个历史记录的信息

{
  "name": "BuildID=Manual-2017.05.02T16:13 WF=PAP_2017_Comparative_(v1.0)_BOOTSTRAPPED Org=CCS Source=Jenkins",
  "url": "/galaxy/api/histories/548c0777ac615645",
  "annotation": null,
  "model_class": "History",
  "id": "548c0777ac615645",
  "tags": [
    "Automated",
    "Annotation",
    "BICH464"
  ],
  "purged": false,
  "published": false,
  "deleted": false
}

这可能不是您对历史记录期望的所有信息。在这种情况下,您可能想要调用 show_history,这将显示单个历史记录的更多详细信息。您可以手动输入 parsec histories show_history 548c0777ac615645,或者我们可以批量执行此操作

$ parsec histories get_histories | jq '.[0].id' | xargs -n 1 parsec histories show_history

这会提取第一个历史记录,选择 id 属性,然后再传递给 xargs。如果您之前没有使用过它,xargs 允许我们为某些输入数据执行多个命令。在这里,我们为每行输入(即从 jq 调用返回的每个 ID)执行 parsec histories show_history 命令。 xargs -n 1 确保我们只会将单个 ID 传递给 show_history 的单个调用。如果您要使用 jq '.[].id' 而不是 jq '.[0].id',它将输出您拥有的每个历史记录的 ID。然后您可以将此输出到 xargs,并运行 show_history 查看您所有的历史记录!

{
  "annotation": null,
  "contents_url": "/galaxy/api/histories/548c0777ac615645/contents",
  "create_time": "2017-05-02T16:18:21.285382",
  "deleted": false,
  "empty": false,
  "genome_build": null,
  "id": "548c0777ac615645",
  "importable": true,
  "model_class": "History",
  "name": "BuildID=Manual-2017.05.02T16:13 WF=PAP_2017_Comparative_(v1.0)_BOOTSTRAPPED Org=CCS Source=Jenkins",
  "published": false,
  "purged": false,
  "size": 34760258,
  "slug": "buildidmanual-20170502t1613-wfpap2017comparativev10bootstrapped-orgccs-sourcejenkins",
  "state": "ok",
  "state_details": {
    "discarded": 0,
    "empty": 0,
    "error": 0,
    "failed_metadata": 0,
    "new": 0,
    "ok": 29,
    "paused": 0,
    "queued": 0,
    "running": 0,
    "setting_metadata": 0,
    "upload": 0
  },
  "state_ids": {
    "discarded": [
      "a6cc986453fae8ba",
      "f2f9b7b017f20578",
      "70eb5af78c588bd1"
    ],
    "empty": [],
    "error": [
      "d643e34e1114cc52",
      "98ae3d35d73f82c9"
    ],
    "failed_metadata": [],
    "new": [],
    "ok": [
      "e510305efbee5f49",
      "0d595b7c2b6e9b93",
      "d04ac6f949ae266c",
      "175f283ddaeca39c",
      "b34432b8a0847c04",
      "ea7ff5323ddebcb8",
      "3e40a393efafc45c",
      "7ce5ec5d51ef85cb",
      "577e4242cdfbe1aa",
      "193d15527d13f45e",
      "4543f9456af7f0df",
      "5e1293df75b4f95b",
      "a57bae35eca5fbfe",
      "6c306b2ed4533f1f",
      "97c5f81b159505f0",
      "64d1d8e46b4554bd",
      "8e9432496d7e2b43",
      "5c8579257c579aae",
      "243ad216fbfa268e",
      "8336d9eb27b27677",
      "a1d4cc61bdba629d",
      "7f93a80890822fa9",
      "c479b351902302e2",
      "36b60fb58ad24a71",
      "041dd3cb6879f1f7",
      "36992e90715c9c77",
      "4bddfe152467e972",
      "2d9f5c0c36d89e10",
      "e53ad6f3133b2816"
    ],
    "paused": [
      "4a8143557292a233",
      "b0f8a75aa6be2c1d"
    ],
    "queued": [],
    "running": [],
    "setting_metadata": [],
    "upload": []
  },
  "tags": [
    "Automated",
    "Annotation",
    "BICH464"
  ],
  "update_time": "2017-05-02T16:49:07.941097",
  "url": "/galaxy/api/histories/548c0777ac615645",
  "user_id": "f570ade6e7840ba0",
  "username_and_slug": "u/helena-rasche/h/buildidmanual-20170502t1613-wfpap2017comparativev10bootstrapped-orgccs-sourcejenkins"
}

如此多的元数据可供玩转和筛选!请注意,许多这些命令都有额外的标志,例如 parsec histories show_history --help 将告诉我们我们还可以传递 –contents 选项来检索该历史记录中数据集的列表,甚至可以根据其可见性进行筛选。

$ parsec histories show_history --help
Usage: parsec histories show_history [OPTIONS] HISTORY_ID

  Get details of a given history. By default, just get the history meta
  information.

Options:
  --contents      When ``True``, the complete list of datasets in the given
                  history.
  --deleted TEXT  Used when contents=True, includes deleted datasets in
                  history dataset list
  --visible TEXT  Used when contents=True, includes only visible datasets in
                  history dataset list
  --details TEXT  Used when contents=True, includes dataset details. Set to
                  'all' for the most information

因此,通过简单的查询

$ parsec histories show_history 548c0777ac615645 --contents --deleted True | jq -S '.[0]'

我们看到历史记录中的第一个已删除数据集。

{
  "create_time": "2017-05-02T16:18:54.272050",
  "dataset_id": "93c926a0dabafde3",
  "deleted": true,
  "extension": "fasta",
  "hid": 30,
  "history_content_type": "dataset",
  "history_id": "548c0777ac615645",
  "id": "d643e34e1114cc52",
  "name": "Feature Sequence Export Unique on data 27 and data 20",
  "purged": false,
  "state": "error",
  "type": "file",
  "type_id": "dataset-d643e34e1114cc52",
  "update_time": "2017-05-02T16:47:57.807506",
  "url": "/galaxy/api/histories/548c0777ac615645/contents/d643e34e1114cc52",
  "visible": true
}

这给我们一个包含历史记录元数据的字典。使用 contents=False(默认值),我们只得到历史记录中包含的数据集 ID 列表;使用 contents=True 我们将得到每个数据集的元数据。我们还可以通过将数据集的 ID 传递给 show_dataset 方法来直接访问特定数据集的更多详细信息。

$ parsec datasets_show_dataset 10a4b652da44e82a
{
    "accessible": true,
    "annotation": null,
    "api_type": "file",
    "create_time": "2015-02-27T23:46:27.642906",
    "data_type": "galaxy.datatypes.data.Text",
    "dataset_id": "10a4b652da44e82a",
    "deleted": false,
    "display_apps": [],
    "display_types": [],
    "download_url": "/api/histories/f3c2b0f3ecac9f02/contents/10a4b652da44e82a/display",
    "extension": "fastq",
    "file_ext": "fastq",
    "file_path": null,
    "file_size": 16527060,
    "genome_build": "dm3",
    "hda_ldda": "hda",
    "hid": 1,
    "history_content_type": "dataset",
    "history_id": "f3c2b0f3ecac9f02",
    "id": "10a4b652da44e82a",
    "meta_files": [],
    "metadata_data_lines": 4,
    "metadata_dbkey": "dm3",
    "misc_blurb": "15.8 MB",
    "misc_info": "uploaded fastqsanger file",
    "model_class": "HistoryDatasetAssociation",
    "name": "C1_R2_1.chr4.fq",
    "purged": false,
    "resubmitted": false,
    "state": "ok",
    "tags": [],
    "type": "file",
    "update_time": "2015-02-27T23:46:34.659590",
    "url": "/api/histories/f3c2b0f3ecac9f02/contents/10a4b652da44e82a",
    "uuid": "ccad6f3a-f75d-472f-9142-2d4c39ad1a35",
    "visible": true,
    "visualizations": []
}

关于 JQ

花点时间看看使用 JQ 可以做些什么,这是值得的。上面的例子可能一开始看起来并不那么令人兴奋,但您可以使用 parsec、jq 和 xargs 的组合做一些了不起的事情。以下是一些示例供您考虑

  • 查找所有具有公共链接但未在共享历史记录部分发布的历史记录,并打印出历史记录名称和共享链接。

    $ parsec histories get_histories | \
       jq '.[].id' | \
       xargs -n 1 parsec histories show_history | \
       jq '. | select(.published == false) | select(.importable == true) | [.published, .importable, .id, .username_and_slug] | @tsv' -r
  • 一次性重置 30 个用户的 API 密钥。

    $ parsec users get_users | \
       jq '.[] | \
       select(.username | contains("janedoe")) | .id' | \
       xargs -n 1 parsec users create_user_apikey
  • 下载一组历史记录中的所有 OK 数据集。

    $ parsec histories get_histories | \
       jq '.[].id' | \ # Or other, more complex filtering?
       xargs -n 1 parsec histories show_history | \ # Get history details
       jq '.state_ids.ok[]' | \ # Find OK datasets
       xargs -n 1 parsec datasets download_dataset --file_path '.' --use_default_filename # Download

查看工作流程

访问工作流程的方法被组织在 GalaxyInstance.workflows.* 下。

要获取您账户中当前工作流的详细信息,请使用

$ parsec workflows get_workflows
[
    {
        'id': 'e8b85ad72aefca86',
        'name': u"TopHat + cufflinks part 1",
        'url': '/api/workflows/e8b85ad72aefca86'
    },
    {
       'id': 'b0631c44aa74526d',
        'name': 'CuffDiff',
        'url': '/api/workflows/b0631c44aa74526d'
    }
]

例如,要进一步调查一个工作流,我们可以请求

$ parsec workflows show_workflow ded67e5aa1371841 | jq 'del(.steps)'

工作流输出通常非常大,因为它包含工作流的完整副本。在上面的 JQ 命令中,为了简洁,我已从输出中删除了 steps 属性。

{
  "annotation": "",
  "model_class": "StoredWorkflow",
  "latest_workflow_uuid": "94c40212-c4bb-43b7-a43b-eadc1a3b2894",
  "id": "ded67e5aa1371841",
  "url": "/galaxy/api/workflows/ded67e5aa1371841",
  "deleted": false,
  "tags": [],
  "owner": "helena-rasche",
  "name": "PAP 2017 Functional (v8.15)",
  "inputs": {
    "0": {
      "value": "",
      "uuid": "9397916e-afb7-4e48-b89e-d4c99bf202de",
      "label": "Apollo Organism JSON File"
    },
    "2": {
      "value": "",
      "uuid": "eca835c6-328a-4698-a387-d0719b24d19d",
      "label": "Genome Sequence"
    },
    "1": {
      "value": "",
      "uuid": "5511d038-e96b-49b2-998a-d037935f6e06",
      "label": "Annotation Set"
    }
  },
  "published": false
}

查看用户

管理用户的方法归入 GalaxyInstance.users.*。用户管理仅限于 Galaxy 管理员,也就是说,连接到 Galaxy 所使用的 API 密钥必须是管理员账户的密钥。

要获取用户列表,请调用

$ parsec users get_users
[
    {
        "username": "test",
        "model_class": "User",
        "email": "test@local.host",
        "id": "f2db41e1fa331b3e"
    },
    ...
]

深度示例

作为一个更详细的示例,我们将启动一个简单的工作流。

步骤 1. 输入是什么

$ parsec workflows show_workflow ded67e5aa1371841 | jq .inputs > inputs.json

实际上,这个文件可能看起来像这样

{
  "0": {
    "value": "",
    "uuid": "9397916e-afb7-4e48-b89e-d4c99bf202de",
    "label": "Apollo Organism JSON File"
  },
  "2": {
    "value": "",
    "uuid": "eca835c6-328a-4698-a387-d0719b24d19d",
    "label": "Genome Sequence"
  },
  "1": {
    "value": "",
    "uuid": "5511d038-e96b-49b2-998a-d037935f6e06",
    "label": "Annotation Set"
  }
}

步骤 2: 准备历史记录和加载数据集

首先,我们将创建一个历史记录来管理我们的所有工作

$ HISTORY_ID=$(parsec histories create_history | jq .id)
$ parsec histories update_history --name 'Parsec test'

接下来,我们必须获取一些数据集。您可以将它们上传

$ parsec tools upload_file my-file.gff3 $HISTORY_ID

但在我这个例子中,我需要运行一个生成这些数据集的工具

JOB_ID=$(parsec tools run_tool $HISTORY_ID edu.tamu.cpt2.webapollo.export \
   '{"org_source|source_select": "direct", "org_source|org_raw": "Miro"}' | \
   jq .id)

$ parsec jobs show_job .outputs $JOB_ID

通过将作业 ID 存储在变量中,我们可以反复请求检查它。第二个 parsec 命令从该步骤获取输出数据集。

{
  "fasta_out": {
    "id": "61513e15ce98c986",
    "src": "hda",
    "uuid": "0de1442b-c410-4a38-b9ca-49cff973d9b8"
  },
  "gff_out": {
    "id": "62ee69adcf74378c",
    "src": "hda",
    "uuid": "887aaf6f-ed07-4ee8-a396-c16612f83d83"
  },
  "json_out": {
    "id": "1f73e96543934ac8",
    "src": "hda",
    "uuid": "3be3d364-83c5-4a23-87fa-ebd8c27f2094"
  }
}

步骤 3: 调用工作流

回想一下步骤 1 中的输入,我们将它们匹配起来并创建一个 inputs.json 文件

  • 0 / organism json file => json_out

  • 1 / genome sequence => gff_out

  • 2 / annotation set => fasta_out

这样我们得到一个看起来像这样的 inputs.json

{
  "0": {
    "id": "1f73e96543934ac8",
    "src": "hda"
  },
  "1": {
    "id": "62ee69adcf74378c",
    "src": "hda"
  },
  "2": {
    "id": "61513e15ce98c986",
    "src": "hda"
  }
}

现在我们可以使用 parsec 调用我们的工作流了!由于输入是 JSON 参数,它可以通过多种方式方便地提供。以下所有行为相同。

$ cat params.json | parsec jobs search_jobs -; # Stdin
$ parsec jobs search_jobs params.json; # Filename
$ parsec jobs search_jobs $(cat params.json); # String argument

运行调用

$ parsec workflows invoke_workflow ded67e5aa1371841 --inputs inputs.json --history_id $HISTORY_ID

产生一个非常简洁的工作流启动输出

{
    "uuid": "94246003-2f8b-11e7-9427-20474784cc00",
    "state": "new",
    "workflow_id": "3daf5606d767a471",
    "id": "c7f60cfda02f0f46",
    "update_time": "2017-05-02T23:03:39.693288",
    "model_class": "WorkflowInvocation",
    "history_id": "0d17c6f8cd8d49a5"
}

现在我们可以使用 parsec 检查所有数据集的状态

$ parsec workflows show_invocation 3daf5606d767a471 c7f60cfda02f0f46 | jq '.steps[].state' | sort | uniq -c
   3 "running"
  72 "new"
   3 null
   1 "ok"

或者我们可以使用其中一个实用脚本等待工作流完成后再继续执行其他任务

$ parsec utils wait_on_invocation 3daf5606d767a471 c7f60cfda02f0f46 && ...

许可证

版权 2016-2021 Galaxy IUC

根据 Apache 许可证 2.0 版(“许可证”);除非遵守许可证规定,否则不得使用此文件。您可以在以下位置获取许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”提供,不提供任何明示或暗示的保证或条件。有关许可证的具体语言,请参阅许可证。

支持

本材料基于美国国家科学基金会资助的研究成果,资助编号(奖号 1565146)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分布

galaxy-parsec-1.16.0.tar.gz (61.3 kB 查看哈希值)

上传时间 源代码

构建版本

galaxy_parsec-1.16.0-py3.7.egg (346.2 kB 查看哈希值)

上传时间 源代码

galaxy_parsec-1.16.0-py2.py3-none-any.whl (156.8 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面