# terra-notebook-utils
Python API and CLI providing utilities for working with [DRS](https://support.terra.bio/hc/en-us/articles/360039330211)
objects, [VCF](https://samtools.github.io/hts-specs/VCFv4.1.pdf) files, and the
[Terra notebook environment](https://support.terra.bio/hc/en-us/articles/360027237871-Terra-s-Jupyter-Notebooks-environment-Part-I-Key-components).
## Installation
From the CLI:
```
pip install terra-notebook-utils
```
In a Jupyter notebook (note the ipython magic "[%pip](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-pip)"):
```
%pip install terra-notebook-utils
```
To upgrade to the newest version:
```
pip install --upgrade --no-cache-dir terra-notebook-utils
```
## Credentials
Much of the terra-notebook-utilities functionality requires credentialed access through a Google Cloud Platform account.
Credentials are already available when running in a Terra notebook environment. Otherwise, credentials may be obtained
with the command
```
gcloud auth application-default login
```
## Usage
terra-notebook-utils exposes a Python API, as well as wrappers to execute some functionality on the CLI. The Python
API is best explored with Pythons great `help` function. For instance, issuing the follow commands into a Python
interpreter or Jupyter notebook will produce help and usage for the `drs` module.
```
import terra_notebook_utils as tnu
help(tnu.drs)
```
Similarly, the CLI may be explored using the typical `-h` argument. Try the following commands at a bash prompt.
```
# See the command groups available to the CLI
tnu -h
```
```
# See the commands available to the vcf group
tnu vcf -h
```
```
# Show your available billing projects
tnu profile list-billing-projects
```
### CLI Configuration
Several CLI commands target a workspace or require a Google billing project. Defaults can be configured using the
commands
```
tnu config set-workspace my-workspace
tnu config set-workspace-google-project my-billing-project
```
Alternatively, workspace and billing project can be passed in to individual commands instead of, or as overrides to,
the configured defaults. See command help, e.g. `tnu table get --help`, for usage information.
Finally, workspace and billing project can be specified with the environment variables
`WORKSPACE_NAME` and `GOOGLE_PROJECT`. These values are used with lowest precedence.
### The DRS API and CLI
terra-notebook-utils provides several methods and CLI commands useful for working with
[DRS](https://github.com/ga4gh/data-repository-service-schemas) resolved objects:
#### Python API
Copy drs object to local file system or bucket:
```
from terra_notebook_utils import drs
drs.copy("drs://my-drs-url", "gs://my-dst-bucket/my-dst-key")
drs.copy("drs://my-drs-url", "local_filepath")
```
#### CLI
Copy drs object to local or bucket:
```
tnu drs copy drs://my-drs-url gs://my-dst-bucket/my-dstkey
tnu drs copy drs://my-drs-url local_filepath
```
### The VCF API and CLI
terra-notebook-utils provides some CLI commands useful for getting information about VCF files.
These commands work for VCFs stored locally, in a Google Storage bucket, or at a DRS url.
Print VCF header:
```
tnu vcf head drs://my-vcf
tnu vcf head gs://my-vcf
tnu vcf head my.vcf.gz
```
Print VCF samples:
```
tnu vcf samples drs://my-vcf
tnu vcf samples gs://my-vcf
tnu vcf samples my.vcf.gz
```
Print VCF stats. This command executes quickly, and shows the length and file size of the VCF. If
the VCF is compressed, the compressed size is returned.
```
tnu vcf stats drs://my-vcf
tnu vcf stats gs://my-vcf
tnu vcf stats my.vcf.gz
```
While a Python API for working with VCFs is currently available, usage is more complex. Please contact the
maintainer for more information.
## Local Development
For local development:
1. Make the decision whether you want to run this using your local environment, or develop from within a docker image.
Developing within a docker image is recommended, since that most closely models how users will use this. Additionally, there are some issues with installing the requirements.txt on mac.
If you don't wish to run this within a docker image, skip to step 5.
2. run `docker pull us.gcr.io/broad-dsp-gcr-public/terra-jupyter-python:0.0.12`
3. run the image from *one directory above* the root directory of this repo via `docker run -itd --entrypoint='/bin/bash' -v $PWD/terra-notebook-utils:/work -u root -e PIP_USER=false --name test-image terra-jupyter-python:0.0.12`
4. Attach your terminal to the image via `docker exec -it test-image bash`, then navigate to the directory the code is mounted to via `cd /work`. Note that the above command ensures any changes you make to files in the repo will be updated in the image as well.
5. log in with your Google credentials using `gcloud auth application-default login`,
6. install requirements with `pip install -r requirements.txt`
7. set up the following environment variables, depending on what you will be using:
- `export GOOGLE_PROJECT=[validProject]`
- `export WORKSPACE_NAME=[workspaceWithinProject]`
- `export TERRA_DEPLOYMENT_ENV=dev`
- `export WORKSPACE_BUCKET=[bucketWithinWorkspace]`
8. run the python shell via `python`, and import any modules you wish to use. For example, `from terra_notebook_utils import drs`
A sample non-protected test DRS url that resolves to a small file in dev: `drs://dg.712C/fa640b0e-9779-452f-99a6-16d833d15bd0`
## Tests
To run tests,
1. log in with your Google credentials using `gcloud auth application-default login`,
2. Your account must have access to the workspace `terra-notebook-utils-tests`
3. Run `export GOOGLE_PROJECT=firecloud-cgl; export TERRA_DEPLOYMENT_ENV=prod; export WORKSPACE_NAME=terra-notebook-utils-tests`
4. install requirements with `pip install -r requirements-dev.txt`,
5. run `make test` in the package root.
## Links
Project home page [GitHub](https://github.com/DataBiosphere/terra-notebook-utils)
Package distribution [PyPI](https://pypi.org/project/terra-notebook-utils)
### Bugs
Please report bugs, issues, feature requests, etc. on [GitHub](https://github.com/DataBiosphere/terra-notebook-utils).
![](https://biodata-integration-tests.net/xbrianh/terra-notebook-utils/badges/master/pipeline.svg) ![](https://badge.fury.io/py/terra-notebook-utils.svg)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共33个文件
py:21个
txt:5个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:terra-notebook-utils-0.2.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
terra-notebook-utils-0.2.1.tar.gz (33个子文件)
terra-notebook-utils-0.2.1
MANIFEST.in 43B
PKG-INFO 8KB
terra_notebook_utils.egg-info
PKG-INFO 8KB
requires.txt 78B
not-zip-safe 1B
SOURCES.txt 954B
top_level.txt 27B
dependency_links.txt 1B
tests
infra
testmode.py 214B
__init__.py 0B
setup.cfg 38B
requirements.txt 82B
setup.py 1KB
terra_notebook_utils
tar_gz.py 2KB
workspace.py 2KB
table.py 3KB
vcf.py 5KB
__init__.py 958B
progress.py 4KB
gs.py 4KB
xprofile.py 840B
profile.py 273B
drs.py 6KB
version.py 97B
cli
workspace.py 2KB
table.py 3KB
vcf.py 3KB
__init__.py 2KB
config.py 894B
profile.py 414B
drs.py 2KB
README.md 6KB
scripts
tnu 497B
共 33 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 软件仿真多机串行通信.doc
- Python大作业:音乐播放软件(爬虫+可视化+数据分析+数据库)
- 课程设计-python爬虫-爬取日报,爬取日报文章后存储到本地,附带源代码+课程设计报告
- 软件和信息技术服务行业投资与前景预测.pptx
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
- 软件定义无线电中的模拟电路测试技术.pptx
- 软件开发协议(作为技术开发合同附件).doc
- 软件开发和咨询行业技术趋势分析.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功