LoginSignup
1
0

More than 3 years have passed since last update.

変異のHGVS表記の変換ツールpython hgvsをローカルリソースのみで実行する

Last updated at Posted at 2019-05-30

python hgvsローカルで実行する

python hgvsをローカルシステムだけで実行するには

  • seqrepo: シーケンスデータファイルを格納したファイルコンテナの作成
    • Docker Hub からのイメージの取得
  • uta: データベースのインストール
    • githubからソースを取得し、Docker imageを作成
    • uta_20180821 では問題が生じたのでuta_0171026を利用した
  • hgvs: Docker imageの作成
    • dockerfileを作成して Docker imageの作成

上記の3つの作業が必要

seqrepoの最新状況は下記で確認できる
http://dl.biocommons.org/seqrepo/

seqrepoのインストール

Dockerを利用してシーケンスデータをファイルコンテナとして準備する

$ docker pull biocommons/seqrepo
$ docker run --name seqrepo biocommons/seqrepo

docker pullコマンドは比較的短い時間で終了する
ただし配列データのダウンロードにかなりの時間が必要になるので、じっくり待つ必要がある

hgvsのインストール

Alpine Linuxを利用してpython3のdocker imageを元にしてhgvsのイメージを作成する

hgvs.dockerfile
FROM python:3.7.3-alpine3.9

# docker build -f hgvs.dockerfile --build-arg seqrepo_version=20180821 --rm=true -t hgvs:hgvs .
RUN apk update &&\
    apk upgrade &&\
    apk --no-cache add \
    build-base gcc \
    zlib-dev bzip2-dev \
    xz-dev libxml2-dev \
    libxslt-dev \
    postgresql-dev

# Install numpy and hgvs by pip
RUN python3 -mpip install numpy
RUN python3 -mpip install hgvs

# by default I'd like to use uta_20180821. But unfortunately the db doesn't work as expected. So, use the second last version 'uta_20171026' instead. 
# please provide custom versions with the command line parameter
# --build-arg uta_version=uta_MYVERSION

ARG uta_version=uta_20171026
ARG seqrepo_version=20180821
ENV HGVS_SEQREPO_DIR=/usr/local/share/seqrepo/${seqrepo_version}
ENV UTA_DB_URL="postgresql://anonymous:anonymous@172.17.0.1:50827/uta/${uta_version}"
# How to Run
# $ docker run -it -e HGVS_SEQREPO_DIR="/usr/local/share/seqrepo/2018-08-21" -e UTA_DB_URL="postgresql://anonymous:anonymous@172.17.0.1:50827/uta/${uta_version}" --name hgvs --volumes-from seqrepo --rm hgvs:hgvs hgvs-shell

docker buildを利用してhgvs.dockerfileのイメージを作成する

docker build -f hgvs.dockerfile --build-arg seqrepo_version=20180821 --rm=true -t hgvs .

まず、このイメージを利用してseqrepoが利用できる事を確認する

$ docker run -it -e HGVS_SEQREPO_DIR="/usr/local/share/seqrepo/2018-08-21" -e --name hgvs --volumes-from seqrepo --rm hgvs ipython

下記の一連のコマンドで配列が取得できることを確認する

from biocommons.seqrepo import SeqRepo
sr = SeqRepo("/usr/local/share/seqrepo/2018-08-21")
sr["NM_000059.3"][:10]

最後はexitで終了


Python 3.7.3 (default, May 11 2019, 02:00:41) 
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from biocommons.seqrepo import SeqRepo

In [2]: sr = SeqRepo("/usr/local/share/seqrepo/2018-08-21")

In [3]: sr["NM_000059.3"][:10]
Out[3]: 'GTGGCGCGAG'

In [4]: exit

uta のインストール

$ docker pull biocommons/uta

しかし、2019年5月の時点では、このDockerfileで利用されているDBは20180821のものでは無かった
20180821はdbに問題があり、ダウンロードしても正常に動作しないため以下は20171026を利用する

imageを作成するためのdockerfileが提供されているので、Docker imageを手元で作成する

  • github から biocommons/uta を取得し適切なパラメータを指定してdocker buildを行う
    • git コマンドが利用できるシステム上で実行すること

ソースコードの取得

$ git clone https://github.com/biocommons/uta.git

uta/misc/dokcerディレクトリに移動してdocker build を実行

$ pushd uta/misc/docker/
$ docker build -f uta.dockerfile --build-arg uta_version=uta_20171026 --rm=true -t uta:uta_20171026 .

作成されたコンテナを実行する事で、postgres sql上のテーブルの構築とデータのダウンロードを行う

$ docker run -dit --name uta_20171026 -p 50827:5432 uta:uta_20171026

起動しているツールのログ(log)を参照する

$ docker logs -f uta_20171026

下記のように表示されたら準備完了

PostgreSQL init process complete; ready for start up.

LOG:  database system was shut down at 2019-05-29 07:39:30 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

ctrl+cでログ参照を終了する

動作の確認

作成したhgvsのdockerイメージを利用してhgvs-shellの動作を確認する

172.17.0.1の部分はdocker内部からみたのホストのIPアドレス

docker run -it -e HGVS_SEQREPO_DIR="/usr/local/share/seqrepo/2018-08-21" -e UTA_DB_URL="postgresql://anonymous:anonymous@172.17.0.1:50827/uta/uta_20171026" --name hgvs_20180821 --volumes-from seqrepo --rm hgvs hgvs-shell

hgvs-shellのプロンプトが表示される

Python 3.7.3 (default, May 11 2019, 02:00:41) 
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.


############################################################################
hgvs-shell -- interactive hgvs
hgvs version: 1.3.0.post0
data provider url: postgresql://anonymous:anonymous@172.17.0.1:50827/uta/uta_20171026
schema_version: 1.1
data_version: uta_20171026
sequences source: SeqRepo (/usr/local/share/seqrepo/2018-08-21)

The following variables are defined:
* global_config
* hp, parser, hgvs_parser -- Parser instance
* hdp, hgvs_data_provider -- UTA data provider instance
* vm, variant_mapper, hgvs_variant_mapper -- VariantMapper instance
* am37, hgvs_assembly_mapper_37 -- GRCh37 Assembly Mapper instance
* am38, projector, hgvs_assembly_mapper_38 -- GRCh38 Assembly Mapper instances
* hn, normalizer, hgvs_normalizer -- Normalizer instance
* hv, validator, hgvs_validator) -- Validator instance

The following functions are available:
  * parse, normalize, validate
  * g_to_c, g_to_n, g_to_t,
  * c_to_g, c_to_n, c_to_p,
  * n_to_c, n_to_g,
  * t_to_g,
  * get_relevant_transcripts

When submitting bug reports, include the version header shown above
and use these variables/variable names whenever possible.

hgvs-shellを利用して
"NM_033089.6:c.571C>G"からhg38上のゲノム上のポジションを取得する

v = hp.parse_hgvs_variant("NM_033089.6:c.571C>G")
am38.c_to_g(v)
を実行しexitで終了する

In [1]:  v = hp.parse_hgvs_variant("NM_033089.6:c.571C>G")

In [2]: am38.c_to_g(v)
Out[2]: SequenceVariant(ac=NC_000020.11, type=g, posedit=298157C>G, gene=None)

In [3]: exit

今回はここまで:smile:

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0