kuroの覚え書き

96の個人的覚え書き

systemctlでvncserver起動

$ sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
$ sudo nano /etc/systemd/system/vncserver@:1.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper <User> %i   #<User>のところを起動するユーザ名に置き換える。
#ExecStart=/usr/sbin/runuser -l ?USER? -c "/usr/bin/vncserver %i -geometry 1366x768 -depth 24"
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

これで取り合えず

$ sudo systemctl daemon-reload
$ sudo systemctl start vncserver@:1.service
$ sudo systemctl enable vncserver@:1.service

とすればvncサーバが起動する。ただしこのままでは1024x768で起動する。
geometryやdepthを変えたければ
/usr/bin/vncserverを書き換えてやる。
(これをするとすべてのユーザの初期設定が変わるので、ユーザごとに変えるには他のやり方が必要なはずだが、知らない。)

#$geometry = "1024x768";
$geometry = "1366x768";
#$depth = 16;
$depth = 24;

SiGN-SSMをソースからコンパイル

Linux版バイナリとして配布されているSiGN-SSMはrel 1.0.2. Multi-thread supported, MPI support not enabledだった。
だからMPIを指定するとマルチスレッドも働かず激遅になったんだな。
あと
You can also use signssm to do this (rel 1.10.0 or later):

$ ~tamada/sign/signssm --ssmperm prefix=perm/result,ssm=result.D008.S001.A.dat,ed=1000,th=0.05 -o final.txt sample.tsv

となっていて1.0.2ではこのコマンドが使えない。まあここはあっという間に終わるのでMacに持っていってからでいいっちゃあいい。
(ところで1.10.0ってそんなバージョンないけど。1.1.0の間違いなんじゃないのかな。1.0.0の可能性もあるけど。)

とにかくコンパイルしてみる。
環境としてBLASLAPACKというライブラリが必要らしい。

$ wget https://github.com/Reference-LAPACK/lapack/archive/v3.9.0.tar.gz

LAPACKをダウンロードする。BLASLAPACKに含まれているらしい。
解凍したらディレクトリに入り

$ cp make.inc.example make.inc
$ make blaslib

そして

$ make lapacklib

でmakeして、出来上がったら

$ sudo cp librefblas.a /usr/lib/libblas.a
$ sudo cp liblapack.a /usr/lib/liblapack.a

とコピーしておく。

一方SiGN-SSMの方は
Makefile

# Prepare "make.inc" for your own environment,
# or comment-out below and uncomment one of the followings.
#include make.inc #ここをコメントアウト

# Linux gcc + Netlib LAPACK. (Set the location of LAPACK in make.inc.gcc_lapack)
include make.inc.gcc_lapack #ここのコメントを外す。

と手を入れ、
make.inc.gcc_lapackの方は

# Netlib LAPACK DIRECTORY
LAPACK=/usr/lib #書き換え
 
# Platform specified in make.inc of LAPACK
#PLAT=_LINUX #コメントアウト

USE_MPI=1 #コメント外し

#########################################################
# NOT NEED TO EDIT BELOW
LAPACK_LIB=$(LAPACK)/liblapack$(PLAT).a  #lapackをliblapackに書き換えた
LAPACK_LIB+=$(LAPACK)/libblas$(PLAT).a #blasをlibblasに書き換えた

としてやって

make

するとsignssmというバイナリが出来上がるので適当な場所にコピーしてやる。
とりあえず

$ bin/signssm -o result1 --threads 8 sample.tsv 
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
========================================
= Start the loop for dim=4
Set 1...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (2)...
1: Loops=5503, Likelihood=1829.617679
2: Loops=2723, Likelihood=1829.093921
Estimation failed.  Retrying (1)...
3: Loops=4497, Likelihood=1829.805601
4: Loops=2908, Likelihood=1830.622691
5: Loops=28717, Likelihood=1829.705602
6: Loops=14724, Likelihood=1829.985808
・・・・・
95: Loops=2908, Likelihood=1829.762141
96: Loops=4126, Likelihood=1830.554303
97: Loops=4996, Likelihood=1830.595209
98: Loops=2147, Likelihood=1829.749469
Estimation failed.  Retrying (1)...
99: Loops=4746, Likelihood=1829.645741
100: Loops=3037, Likelihood=1829.483204
Finished: dim=4, likelihood=1831.571195
0 day 00 hour 02 min 43 sec
X-SINGLE-TIME:	163.107068

おや?MPIが効いてないどころかマルチスレッドすら動いてない?

ちなみに1.0.2のバイナリで同じ作業をやると

$ bin/signssm0 -o result0 --threads 8 sample.tsv 
SiGN-SSM  version 1.0.2 (Wed Feb 23 11:44:59 2011 JST)
  Copyright (C) 2010  HGC, IMS, The University of Tokyo.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Thread Execution Mode   **
*******************************
Number of threads = 8
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimemsion = 4
Total single tasks = 100
{4} set=1, dim=4, likelihood=1830.679933, loops=198, finished=1
Best likelihood updated for set id = 1.
{6} set=1, dim=4, likelihood=1829.956352, loops=2757, finished=2
{3} set=1, dim=4, likelihood=1830.440368, loops=2997, finished=3
{1} set=1, dim=4, likelihood=1831.018207, loops=3138, finished=4
Best likelihood updated for set id = 1.
{5} set=1, dim=4, likelihood=1829.589914, loops=3391, finished=5
・・・・・
{6} set=1, dim=4, likelihood=1830.725075, loops=4010, finished=96
{0} set=1, dim=4, likelihood=1829.636737, loops=6723, finished=97
{2} set=1, dim=4, likelihood=1829.531546, loops=8539, finished=98
{3} set=1, dim=4, likelihood=1829.669849, loops=33276, finished=99
{5} set=1, dim=4, likelihood=1829.672068, loops=20355, finished=100
Outputting the calculated state variables: result0.D004.S001.K.dat
Outputting the result into a single file: result0.D004.S001.A.dat
Outputting the summary file: result0.D004.S001.B.dat
All time: 0 day 00 hour 01 min 04 sec
X-ALL-TIME:	63.882370

MPIはないけどマルチスレッドが働いていてマアマアの速度。


じゃあと、MPIを外してコンパイルし直してみると

$ bin/signssm2 -o result2 --threads 8 sample.tsv 
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
========================================
= Start the loop for dim=4
Set 1...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (2)...
1: Loops=5503, Likelihood=1829.617679
2: Loops=2723, Likelihood=1829.093921
Estimation failed.  Retrying (1)...
3: Loops=4497, Likelihood=1829.805601
4: Loops=2908, Likelihood=1830.622691
5: Loops=28717, Likelihood=1829.705602
・・・・・

95: Loops=2908, Likelihood=1829.762141
96: Loops=4126, Likelihood=1830.554303
97: Loops=4996, Likelihood=1830.595209
98: Loops=2147, Likelihood=1829.749469
Estimation failed.  Retrying (1)...
99: Loops=4746, Likelihood=1829.645741
100: Loops=3037, Likelihood=1829.483204
Finished: dim=4, likelihood=1831.571195
0 day 00 hour 02 min 45 sec
X-SINGLE-TIME:	164.772890
Outputting the calculated state variables: result2.D004.S001.K.dat
Outputting the p-values: result2.D004.S001.P.dat
Outputting the meta-analysis of p-values: result2.D004.S001.m.dat
Outputting the result into a single file: result2.D004.S001.A.dat
Outputting the summary file: result2.D004.S001.B.dat
Going to exit.
All time: 0 day 00 hour 02 min 45 sec
X-ALL-TIME:	164.900692

と、やはりマルチスレッドでは動かず、速度も変わらない。
どういうこと?

MPIで走らせるコマンドを忘れていた。

$ mpirun ./bin/signssm1 -o result1 sample.tsv 
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
========================================
= Start the loop for dim=4
Set 1...
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
========================================
= Start the loop for dim=4
Set 1...
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data file: sample.tsv
========================================
= Start the loop for dim=4
Set 1...
Applying mean shift for the input data set.
*******************************
**   Single Execution Mode   **
*******************************
--- INPUT DATA ---------
 observed samples = 21
 objects = 100
 time points = 48
 replicates = 3
------------------------
Max dimension = 4
========================================
= Start the loop for dim=4
Set 1...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (1)...
Estimation failed.  Retrying (2)...
Estimation failed.  Retrying (2)...
・・・・・

95: Loops=2908, Likelihood=1829.762141
96: Loops=4126, Likelihood=1830.554303
97: Loops=4996, Likelihood=1830.595209
98: Loops=2147, Likelihood=1829.749469
Estimation failed.  Retrying (1)...
99: Loops=4746, Likelihood=1829.645741
100: Loops=3037, Likelihood=1829.483204
Finished: dim=4, likelihood=1831.571195
0 day 00 hour 03 min 47 sec
X-SINGLE-TIME:	226.878186
Outputting the calculated state variables: result1.D004.S001.K.dat
Outputting the p-values: result1.D004.S001.P.dat
Outputting the meta-analysis of p-values: result1.D004.S001.m.dat
Outputting the result into a single file: result1.D004.S001.A.dat
Outputting the summary file: result1.D004.S001.B.dat
Going to exit.
All time: 0 day 00 hour 03 min 47 sec
X-ALL-TIME:	227.000185

いや確かにMPIで走ってはいるが全然速くなってないし。むしろ遅い。

やっぱりこれはMPIで走らせるべきではないソフトウェアなんだろうか。だからバイナリもマルチスレッド対応のみで配布されているのか。自前コンパイルだとそれすらできてないからまるで意味がないな。

しかし1.0.2ではやはり2ステップ目以降の

    • perm
    • ssmperm

オプションはやはり使えないのでLinuxだけで完結しないのでもうちょっとここは頑張ってみるか。

SiGN-SSM

ネットワーク解析がしたいと思い環境構築。結構手こずったので(いつもながら)メモ。

まずはHGCからダウンロード。
MacOSバイナリーとLinuxバイナリーを両方ダウンロードしてみる。

Linux版は解凍して

$ make INSTALLDIR=適当な場所 install

でインストール。ただコピーしてるだけっぽいけど。

$ signssm --threads 8 -n 10 -d 4-12 -o results sample.tsv

というふうにサンプルデータをランしてみる。
チュートリアルにあるようにd=8くらいでBICの値が最小となったので

$ signssm --threads 8 -n 100 -d 8 -o result1 sample.tsv

とやって、できた3つのファイルから次のステップへ進む。

$ sh bin/signssm_plot.sh 3 result1.D008.S001.K.dat sample.tsv output.pdf

とやろうとしたところ、

$ bin/signssm_plot.sh: \u884c 109: gnuplot: コマンドが見つかりません。

と出たので

$ brew install gnuplot
・・・・・・
==> Installing gnuplot dependency: harfbuzz
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
==> Patching
==> Applying 7c61caa7384e9c3afa0d9237bf6cd303eb5ef3a1.patch
patching file src/meson.build
Hunk #1 succeeded at 397 with fuzz 1 (offset -8 lines).
Hunk #2 succeeded at 406 (offset -8 lines).
Hunk #3 succeeded at 430 (offset -8 lines).
Hunk #4 succeeded at 532 (offset -8 lines).
Hunk #5 succeeded at 618 (offset -8 lines).
==> meson --prefix=/home/linuxbrew/.linuxbrew/Cellar/harfbuzz/2.7.0 --libdir=/home/linuxbrew/.linuxbrew
==> ninja
Last 15 lines from /home/rnaseq/.cache/Homebrew/Logs/harfbuzz/02.ninja:
       ^
cc1plus: some warnings being treated as errors
[147/289] Compiling C++ object src/test-bimap.p/test-bimap.cc.o
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
[148/289] Compiling C object test/api/test-buffer.p/test-buffer.c.o
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
[149/289] Compiling C++ object src/libharfbuzz-subset.so.0.20700.0.p/hb-subset-plan.cc.o
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
[150/289] Compiling C++ object src/libharfbuzz-subset.so.0.20700.0.p/hb-subset.cc.o
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
ninja: build stopped: subcommand failed.
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)

READ THIS: https://docs.brew.sh/Troubleshooting

These open issues may also help:
Harfbuzz fails to build on Ubuntu 20.04 (WSL 2) https://github.com/Homebrew/linuxbrew-core/issues/20888

とエラーが大量に出てインストールできないし。
この件についていろいろ試してみたが結局解決せず。

ということで一旦Linuxでの作業を諦め、Macに移る。

$ sh signssm_plot.sh 3 best.D008.S001.K.dat sample.tsv output.pdf
signssm_plot.sh: line 109: gnuplot: command not found

またか。結局おなじなのか?

$ brew install gnuplot
Updating Homebrew...
・・・・
==> Installing gnuplot dependency: python@3.8
==> Pouring python@3.8-3.8.5.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite python@3.8

To list all files that would be deleted:
  brew link --overwrite --dry-run python@3.8

Possible conflicting files are:
/usr/local/bin/2to3 -> /Library/Frameworks/Python.framework/Versions/2.7/bin/2to3
/usr/local/bin/idle3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/idle3
/usr/local/bin/pydoc3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/pydoc3
/usr/local/bin/python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/usr/local/bin/python3-config -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

またか。その2
エラーメッセージに従って

$ rm '/usr/local/bin/2to3'

としてやると、今度はすんなりとgnuplotがインストールできた。
これでようやく

$ sh signssm_plot.sh 3 result1.D008.S001.K.dat sample.tsv output.pdf

無事完了してPDFファイルが出来上がる。今回100遺伝子のプロファイルなので100枚のPDFなんだけど、これ全ゲノムでやると3万枚のPDFになるんだろうな。見てらんないよ。

で、続いてやることは

then let's try permutation test on the HGC supercomputer system

て、え?ここからはスパコンじゃないとだめなの?


なお、signssmコマンドをMacで走らせようと思ったら

$ ./signssm
dyld: Library not loaded: /usr/local/lib/libmpi.1.dylib
  Referenced from: /Volumes/SSD/kkuro/local/bin/./signssm
  Reason: image not found
Abort trap: 6

とやはりそのままでは動かない。
まずlibmpiがいるということでopen-mpiを入れる。

$ brew install openmpi
$ ./signssm
dyld: Library not loaded: /usr/local/lib/libmpi.1.dylib
  Referenced from: /Volumes/SSD/kkuro/local/bin/./signssm
  Reason: image not found
Abort trap: 6

変わらんし。
強引だけど

$ ln -s /usr/local/Cellar/open-mpi/4.0.4_1/lib/libmpi.40.dylib /usr/local/lib/libmpi.1.dylib
$ ./signssm
dyld: Library not loaded: /usr/local/lib/gcc/x86_64-apple-darwin13.3.0/4.9.0/libgomp.1.dylib
  Referenced from: /Volumes/SSD/kkuro/local/bin/./signssm
  Reason: image not found
Abort trap: 6

なんだとー。

$ mkdir /usr/local/lib/gcc/x86_64-apple-darwin13.3.0
$ mkdir /usr/local/lib/gcc/x86_64-apple-darwin13.3.0/4.9.0/
$ ln -s /usr/local/opt/gcc/lib/gcc/10/libgomp.dylib /usr/local/lib/gcc/x86_64-apple-darwin13.3.0/4.9.0/libgomp.1.dylib

これでどうだ。

o$ ./signssm
SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

Single process mode.
Reading input data from the standard input.

signssm(43237,0x10e02b5c0) malloc: can't allocate region
*** mach_vm_map(size=18446603546223603712) failed (error code=3)
signssm(43237,0x10e02b5c0) malloc: *** set a breakpoint in malloc_error_break to debug
[kkuro-Mac-mini-2018:43237] *** Process received signal ***
[kkuro-Mac-mini-2018:43237] Signal: Segmentation fault: 11 (11)
[kkuro-Mac-mini-2018:43237] Signal code: Address not mapped (1)
[kkuro-Mac-mini-2018:43237] Failing at address: 0x0
[kkuro-Mac-mini-2018:43237] [ 0] 0   libsystem_platform.dylib            0x00007fff5cca3b5d _sigtramp + 29
[kkuro-Mac-mini-2018:43237] [ 1] 0   ???                                 0x0000000000000000 0x0 + 0
[kkuro-Mac-mini-2018:43237] [ 2] 0   signssm                             0x0000000103351e26 SSMData_read_fp + 438
[kkuro-Mac-mini-2018:43237] *** End of error message ***
Segmentation fault: 11

とりあえず走るようにはなったみたい。

open-MPIもインストールしたことだし試しにMacで最初からやってみる。

$ mpirun ./signssm -d 8 -n 100 -o result sample.tsv

おっ、結構速いよ。

SiGN-SSM  version 1.2.1 (Fri Dec 19 17:15:38 2014 JST)
  Copyright (C) 2010-2014  SiGN Project Members.

! ABSOLUTELY NO WARRANTY.  SEE LICENSE FOR DETAILS.  Visit http://sign.hgc.jp/

MPI mode: This is the root process.
Reading input data file: sample.tsv
Applying mean shift for the input data set.
Broadcasting the input data.
  Done.
THIS IS THE ROOT PROCESS [SERVER]
In total, 1 (set) x 100 (iteration) x 1 (dimension) = 100 jobs will be dispatched.
Total sets = 1
proc_first_dispatch: rank=1, set_id=1
proc_first_dispatch: rank=2, set_id=1
proc_first_dispatch: rank=3, set_id=1
proc_first_dispatch: rank=4, set_id=1
proc_first_dispatch: rank=5, set_id=1
After the first dispatch: iter=5, set=0, dim_idx=0, set_id=1.
Waiting a job request...
Request received: rank=3, likelihood=1272.128966 (set ID=1)
  Best likelihood updated for set ID=1: 1272.128966 count: 5
Job Dispatched: rank=3, setID1=0, setID2=1, dim=8
  iteration=5, set=0
  6/100

・・・・・

Waiting a job request...
Request received: rank=3, likelihood=2529.649199 (set ID=1)
Job Dispatched: rank=3, setID1=0, setID2=0, dim=-2
  iteration=0, set=0
Waiting a job request...
Request received: rank=4, likelihood=1243.279744 (set ID=1)
------------------------
 Set finished. setID=1.
------------------------
  |set_ranks[recv_id]|=5
  Best likelihood: 1633206613492228683064330596324346188692632137464403681452508477558896480390805133713951290953826731815033386049280101816652249859497132032.000000 @ rank: 2  count: 100
Job Dispatched: rank=4, setID1=-1, setID2=0, dim=-2
  iteration=0, set=0
All jobs finished.  Sending the final order.
For Client:1, num = 0
For Client:2, num = 1
For Client:3, num = 0
For Client:4, num = 0
For Client:5, num = 0
All time: 0 day 00 hour 01 min 49 sec
X-ALL-TIME:	109.028624

ちなみにLinuxXEON E3-1330v6)で7スレッドでやると

All time: 0 day 00 hour 05 min 58 sec
X-ALL-TIME:	357.768202

だったので i7 3.2GHz 6コアのMPIのほうが3倍ほど速いという結果。

$ ./signssm --perm result.D008.S001.A.dat -o perm/result sample.tsv
$ ./signssm --ssmperm prefix=perm/result,ssm=result.D008.S001.A.dat,ed=1000,th=0.05 -o final.txt sample.tsv

と最後までいけた。
signssm --perm
All time: 0 day 00 hour 12 min 26 sec
X-ALL-TIME: 746.334618

signssm --ssmperm
All time: 0 day 00 hour 00 min 00 sec
X-ALL-TIME: 0.267522

かかる時間はこんな感じ。この2ステップはMPIに対応してないっぽく、mpirunでは正しい処理ができなかった。
実際に全ゲノムでやるとなるとこの2番めのステップがボトルネックだろうな。ここはやはりクラスタで並列処理をかましたいところ。

となんかイケてそうな気がしてたけど出来上がったデータを見てみるとどうもMPIはうまく走っていない。うーむ。

なおLinuxのほうでMPIでやってみたらマルチスレッドでやったのと全く同じ結果を得られた。こちらはうまく走っている。
しかしタイムは
All time: 0 day 00 hour 34 min 28 sec
X-ALL-TIME: 2067.862958
とめちゃめちゃかかってる。どういうこと?

カテゴリープロット、ボックスプロット、バイオリンプロット

最近Nature系の論文は投稿時に平均値+エラーバーだけでなく、全データ点をプロットしたグラフを要求するようになった。
投稿サイトでもそういうグラフをオンラインで作ってくれるサイトが紹介されているのでそれを使えばいいのだが、みんなそのサイトを使ってグラフを書き直しているためか、どれもこれもみんな似たようなグラフになっていてキモい。
ということで、自前で描画できるアプリを作ろうということでいつものようにPythonでプログラムを書く。
と言ってもmatplotlibとseabornで描かせるだけなので自作というのもおこがましいのだが。

f:id:k-kuro:20200804233920p:plain

サクサクっと完成。これをexcelで作ったグラフに重ねてしまえばOK。

ついでに、最近良く見るようになったバイオリンプロットも描けるようにしてみた。
f:id:k-kuro:20200804234038p:plain

Flaskのプログラムにいつものように継ぎ足しているので、ライブラリのインポートやformとかの定義は省略しているが、ソースは以下のような感じ。

@app.route('/cat_graph', methods=['GET', 'POST'])
def cat_graph_index():
    user = g.user.name
    form=StatForm()
    dir = "./user/" + user + "/graph"
    if os.path.exists(dir):
        shutil.rmtree(dir)
    if not os.path.exists(dir):
        os.makedirs(dir)
    input = dir + "/input.txt"
    output = dir + "/output.txt"


    if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        if file.filename == '':
            if form.samp1.data:
                samp = form.samp1.data.strip()
                f = open(input, 'w')
                f.write(samp)
                f.close()
            else:
                flash('No data input')
                return redirect(request.url)
        if file and allowed_file(file.filename):
            file.save(input)

    if os.path.exists(input):
        if form.fig_x.data:
            fig_x=form.fig_x.data
        if form.fig_y.data:
            fig_y=form.fig_y.data

        if form.data_f.data=='csv':
            df = pd.read_csv(input)
        if form.data_f.data=='tsv':
            df = pd.read_table(input)

        graph_figa = dir + "/graph_" + str(time.time()) + ".eps"
        graph_fig = dir + "/graph_" + str(time.time()) + ".png"

        # X = df.iloc[:, 1:].apply(lambda x: (x-x.mean())/x.std(), axis=0)

        if form.graph_type.data == "cat":
            if form.jitter.data:
                sns.catplot(x=df.columns.values[0],y=df.columns.values[1], data=df)
            else:
                sns.catplot(x=df.columns.values[0],y=df.columns.values[1], data=df, jitter=False)

            plt.savefig(graph_figa)
            plt.savefig(graph_fig)

            img_url = "../../static/" + graph_fig

            return render_template('/tools/cat_graph.html', form=form, img_url=img_url)

        if form.graph_type.data == "box":
            sns.catplot(x=df.columns.values[0],y=df.columns.values[1], data=df, kind='box')
            plt.savefig(graph_fig)
            plt.savefig(graph_figa)

            img_url = "../../static/" + graph_fig

            return render_template('/tools/cat_graph.html', form=form, img_url=img_url)

        if form.graph_type.data == "violin":
            sns.catplot(x=df.columns.values[0],y=df.columns.values[1], data=df, kind='violin')
            plt.savefig(graph_fig)
            plt.savefig(graph_figa)

            img_url = "../../static/" + graph_fig

            return render_template('/tools/cat_graph.html', form=form, img_url=img_url)

    return render_template('/tools/cat_graph.html', form=form)

@app.route('/graph/dl/')
def dl_graph_index():
    user = g.user.name
    dir = "./user/" + user + "/graph"
    file = "./user/" + user + "/graph_figs"
    if os.path.exists(dir):
        shutil.make_archive(file, 'zip', dir)

    downloadFileName = 'figs' + str(time.time()) + '.zip'
    downloadFile = "./static/user/" + user + '/graph_figs.zip'

    return send_file(downloadFile, as_attachment = True, attachment_filename = downloadFileName)

werkzeugの使い方が変わった件

$ python3 manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from app import app, manager
  File "/Users/kuro/database/app/__init__.py", line 11, in <module>
    from app.models import *
  File "/Users/kuro/database/app/models.py", line 4, in <module>
    from werkzeug import check_password_hash, generate_password_hash
ImportError: cannot import name 'check_password_hash' from 'werkzeug' (/usr/local/lib/python3.7/site-packages/werkzeug/__init__.py)

となってFlaskが動かない。

以前はmodels.pyの中で

from werkzeug import check_password_hash, generate_password_hash

としておけばよかったのだが、werkzeugの構成に変更があったらしく

from werkzeug.security import check_password_hash, generate_password_hash

このように書くようになった。

CentOS7のKVMにUbuntuを乗せる

$ sudo virt-install --name kvm3_ubuntu --memory 8192 --disk /home/kvm/images/kvm3,size=100  --location /tmp/ubuntu-20.04-desktop-amd64.iso --network default --vcpu 8 
WARNING  オペレーティングシステムを検出できません。仮想マシンのパフォーマンスが低下する可能性があります。最適なパフォーマンスを得るには、--os-variant で OS を指定する必要があります。

インストールの開始中...
ファイル .treeinfo を読出中...                      |    0 B  00:00     
ファイル content を読出中...                        |    0 B  00:00     
ファイル info を読出中...                           |   57 B  00:00     
ファイル info を読出中...                           |   57 B  00:00     
ファイル info を読出中...                           |   57 B  00:00     
ERROR    Ubuntu ツリーに対する hvm カーネルが見つかりませんでした。
仮想マシンのインストールが成功したように見えません。
成功していれば、次を実行すると、仮想マシンを再起動できます:
  virsh --connect qemu:///system start kvm3_ubuntu
そうでなければ、インストールをやり直してください。

およよ。

どういうわけかダウンロードしたisoイメージからインストールができない。

$ sudo virt-install --name kvm3_ubuntu --memory 8192 --disk /home/kvm/images/kvm3,size=100  --location http://ftp.jaist.ac.jp/pub/Linux/ubuntu/dists/bionic/main/installer-amd64/ --network default

これでいけた。

追記
ローカルに置いたisoイメージでインストールするときは--locationでなく--cdromとする。

KVM環境をホストの電源オンオフと連動

ホストの電源を入れたら自動で起動させるには

$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     centos7                        running
 -     centos8                        shut off

$ sudo virsh autostart centos7

ホストをシャットダウンするとき自動的にゲストもシャットダウンする。
Ubuntuの場合

$ sudo nano /etc/default/libvirt-guests 
# URIs to check for running guests
# example: URIS='default xen:/// vbox+tcp://host/system lxc:///'
#URIS=default

# action taken on host boot
# - start   all guests which were running on shutdown are started on boot
#           regardless on their autostart settings
# - ignore  libvirt-guests init script won't start any guest on boot, however,
#           guests marked as autostart will still be automatically started by
#           libvirtd
ON_BOOT=ignore

# Number of seconds to wait between each guest start. Set to 0 to allow
# parallel startup.
#START_DELAY=0

# action taken on host shutdown
# - suspend   all running guests are suspended using virsh managedsave
# - shutdown  all running guests are asked to shutdown. Please be careful with
#             this settings since there is no way to distinguish between a
#             guest which is stuck or ignores shutdown requests and a guest
#             which just needs a long time to shutdown. When setting
#             ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
#             value suitable for your guests.
ON_SHUTDOWN=shutdown

# Number of guests will be shutdown concurrently, taking effect when
# "ON_SHUTDOWN" is set to "shutdown". If Set to 0, guests will be shutdown one
# after another. Number of guests on shutdown at any time will not exceed number
# set in this variable.
PARALLEL_SHUTDOWN=10

# Number of seconds we're willing to wait for a guest to shut down. If parallel
# shutdown is enabled, this timeout applies as a timeout for shutting down all
# guests on a single URI defined in the variable URIS. If this is 0, then there
# is no time out (use with caution, as guests might not respond to a shutdown
# request). The default value is 300 seconds (5 minutes).
SHUTDOWN_TIMEOUT=120

# If non-zero, try to bypass the file system cache when saving and
# restoring guests, even though this may give slower operation for
# some file systems.
#BYPASS_CACHE=0

# If non-zero, try to sync guest time on domain resume. Be aware, that
# this requires guest agent with support for time synchronization
# running in the guest. For instance, qemu-ga doesn't support guest time
# synchronization on Windows guests, but Linux ones. By default, this
# functionality is turned off.
#SYNC_TIME=1

CentOS7の場合

$ sudo nano /etc/sysconfig/libvirt-guests

Linuxbrew + python3でglibcのバージョンが足りない件(解決)

新規構築したCentOS7環境にLinuxbrewでpython3.7をインストールするとmatplotlibがインポートできない現象が出て、どうにかpython3.6を入れてお茶を濁そうとしていたわけだ。
Mac OSXのHomebrewではgit checkoutで古いバージョンのインストールができるようなことがあちこちにかかれていたのだけれど、Linuxbrewでは結局成功しなかった。

途方に暮れかけ、ネットを検索していて、これは!という記事があった、とおもったらなんと自分の書き込み(つまりこのサイト)だったw

$ brew install glibc

たったこれだけのことで解決してしまった。

CentOS7はGLIBC1.17までしか対応せず、1.18はインストールのしようがないということだったけど、brewでは2.23がインストールできちゃうのね。

SRAToolkit

公開されているSRAファイルをダウンロードして再解析がしたいとき、データのダウンロードが結構面倒なので(サイトの構造が複雑すぎてなかなかファイル本体にたどり着けない)専用のツールを利用したい。
とおもってインストールをbrewからやってみた。

$ brew install sratoolkit

ところがだ。

$ fastq-dump --gzip --split-files SRRxxxxxxxx

localeがおかしいとかのwarningはまあいいとして、どうもperlのライブラリがぶつかって動かないらしい。


というわけで、バイナリを手動でインストールしてみた。

$ wget https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/current/sratoolkit.current-centos_linux64.tar.gz
$ tar xvzf sratoolkit.current-centos_linux64.tar.gz
$ mv sratoolkit.2.10.7-centos_linux64 ~/src/
$ ln -s ~/src/sratoolkit.2.10.7-centos_linux64/bin/* ~/bin