LoginSignup
0
0

More than 3 years have passed since last update.

uta_20180821をローカルで利用できるようにする

Posted at

uta_20180821をローカルで利用できるようにする

変異のHGVS表記の変換ツールpython hgvsをローカルリソースのみで実行するでは、uta_20180821を利用できずにuta_0171026を利用したので改めてuta_20180821環境の構築を行う

発生していた問題は下記に関連するもの
Local UTA w/Postgres url throws exception: Generator didn't stop after throw #537

下記でviewをリフレッシュする必要がある事がわかった

refresh materialized view ${UTA_VERSION}.exon_set_exons_fp_mv;
refresh materialized view ${UTA_VERSION}.tx_exon_set_summary_mv;
refresh materialized view ${UTA_VERSION}.tx_def_summary_mv;

という事でこの手順をpostgresの処理の最後に追加する

uta_20180821 のDockerをBuildする

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

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

ソースコードの取得

$ git clone https://github.com/biocommons/uta.git
$ pushd uta/misc/docker/

postgresのDBを改変する
現在のディレクトリのload-uta.shを下記で置き換える

load-uta.sh
#!/bin/bash -x
# This file creates a password-less read-only instance of UTA
# (https://bitbucket.org/biocommons/uta/) based on the postgres docker
# image.

# TODO:
# * consider how/whether to cache downloaded dump
# * fetch sha1 and check before loading

# Overwrite pg_hba.conf, including whatever edits might have been made
# by the postgres image
cat <<EOF >"$PGDATA/pg_hba.conf" 
# allow the anonymous user to access uta without password
# These lines must occur before more stringent authentication methods
host   all   anonymous     0.0.0.0/0      trust
host   all   PUBLIC        0.0.0.0/0      trust
local  all   all                          trust
host   all   all         127.0.0.1/32     trust
host   all   all               ::1/128    trust
EOF


# Create required users
createuser --username "$POSTGRES_USER" uta_admin
createuser --username "$POSTGRES_USER" anonymous
createuser --username "$POSTGRES_USER" PUBLIC
createdb   --username "$POSTGRES_USER" -O uta_admin uta

# Stream db dump into psql
# When the image is first run, the output from curl and psql are
# comingled.  This is intentional so that the user can see curl
# progress and pg restore progress.

UTA_BASENAME=${UTA_VERSION}${UTA_SCHEMA_ONLY:+-schema}.pgd.gz
UTA_PGD_URL=http://dl.biocommons.org/uta/${UTA_BASENAME}
UTA_PGD_FN=/tmp/${UTA_BASENAME}

if ! [ -e "${UTA_PGD_FN}" ]; then
    curl -o "${UTA_PGD_FN}.tmp" "$UTA_PGD_URL"
    mv "${UTA_PGD_FN}.tmp" "${UTA_PGD_FN}"
fi

gzip -cdq < "${UTA_PGD_FN}" \
    | psql -1e -U uta_admin -d uta -v ON_ERROR_STOP=1

echo "\
refresh materialized view ${UTA_VERSION}.exon_set_exons_fp_mv;
refresh materialized view ${UTA_VERSION}.tx_exon_set_summary_mv;
refresh materialized view ${UTA_VERSION}.tx_def_summary_mv;" | psql -1e -U uta_admin -d uta -v ON_ERROR_STOP=1

cat <<EOF
=======================================================================
=======================================================================
== 
== $UTA_VERSION installed from
== $UTA_PGD_URL
== 
== You may now connect to uta like this:
== 
== $  psql -h localhost -p <port> -U anonymous -d uta
== 
== No password is required.
== 
=======================================================================
=======================================================================

EOF


date >/tmp/uta-ready

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

$ docker build -f uta.dockerfile --build-arg uta_version=uta_20180821 --rm=true -t uta:uta_20180821 .

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

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

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

$ docker logs -f uta_20180821

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

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でログ参照を終了する

動作の確認には下記のようにしてコンテナを起動する

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_20180821" --name hgvs_20180821 --volumes-from seqrepo --rm hgvs hgvs-shell

実行の確認については
動作の確認のhgvs-shellのプロンプトが表示される以降と同様

今回はここまで:smile:

どのようなエラーが発生していたのか

改変を加えずに実行したutaに接続してhgvsを利用すると下記のようなエラーが発生する

ObjectNotInPrerequisiteState: materialized view "tx_def_summary_mv" has not been populated

In [2]: am38.c_to_g(v)
WARNING:hgvs.dataproviders.uta:Lost connection to postgresql://anonymous:anonymous@172.17.0.1:50827/uta/uta_20180821; attempting reconnect
WARNING:hgvs.dataproviders.uta:Reconnected to postgresql://anonymous:anonymous@172.17.0.1:50827/uta/uta_20180821
---------------------------------------------------------------------------
ObjectNotInPrerequisiteState              Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/hgvs/dataproviders/uta.py in _get_cursor(self, n_retries)
    568 
--> 569                 yield cur
    570 

/usr/local/lib/python3.7/site-packages/hgvs/dataproviders/uta.py in _fetchall(self, sql, *args)
    219         with self._get_cursor() as cur:
--> 220             cur.execute(sql, *args)
    221             return cur.fetchall()

/usr/local/lib/python3.7/site-packages/psycopg2/extras.py in execute(self, query, vars)
    141         self._query_executed = True
--> 142         return super(DictCursor, self).execute(query, vars)
    143 

ObjectNotInPrerequisiteState: materialized view "tx_def_summary_mv" has not been populated
HINT:  Use the REFRESH MATERIALIZED VIEW command.
0
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
0
0