LoginSignup
0
0

python と JupyterLab でボルケーノ

Last updated at Posted at 2023-07-22

はじめに

ボルケーノプロットを作成することになり、Pythonで作るVolcano plot を参考にさせてもらい、無事描画できたのだが、途中ライブラリのバージョンアップ等のため苦戦したのでメモっておく。

試した環境

インストールすることができたバージョンの組み合わせは、こんな感じ。

  • Ubuntu 20.X
  • miniconda
  • python 3.11
  • jupyterlab 4.0.3
  • bioifonkit 1.0.8
  • matpltolib 3.7
  • pandas 2.0.3
  • seaborn 0.12.2
  • matplotlib-venn 0.11
  • adjustText 0.7.3
  • tabulate 0.9.0
  • scikit-learn 1.3.0
  • textwrap3 0.9.2

構築手順

こんな感じ。

conda create -n jupyter
conda activate jupyter
conda install -c conda-forge jupyterlab
conda install -c bioconda bioinfokit
conda install -c conda-forge pandas
conda install -c conda-forge seaborn
conda install -c conda-forge matplotlib-venn
conda install -c conda-forge adjustText
conda install -c conda-forge tabulate 
conda install -c conda-forge scikit-learn
conda install -c conda-forge textwrap3

Jupyter lab は様々なライブラリに依存しており、インストール可能なバージョンが見つからないことも多々あるので一番最初入れているのがポイント。

バージョンを指定していないので、実施時期によっては本記事のバージョンと異なるものがインストールされる可能性がある。うまくいかない場合はバージョンを指定するなど試行錯誤してほしい。

ボルケーノプロットの描画

早速、ボルケーノプロットを描画していこう。

まずコマンドラインからjupyterLabを起動しておこう

jupyter lab --ip 0.0.0.0

続いてJupyterLabでNoteBookを作成し、コマンドを打ち込んでいく。

まず必要なライブラリを読み込もう。

import pandas as pd
from bioinfokit import analys, visuz
import bioinfokit
import logging
import matplotlib.pyplot as plt
%matplotlib inline
logging.getLogger("matplotlib.font_manager").setLevel(logging.ERROR)

続いてテストデータを読み込もう。テストデータは、ここ からダウンロードして、JupyterLabにアップロードしている。

df = pd.read_csv('./test_data.csv')

中身はこんな感じだ(最初の5行のみ表示)。
image.png

早速グラフを描画しよう。lfcに遺伝子発現データの列名、pvにP値の列名をそれぞれ指定しよう。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', sign_line=True, show=True)

こんな風にサクッと描画される。
image.png

続いて色を代えてみよう。colorに色の組み合わせを指定すればよい。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', color=('red', 'grey', 'blue'))

image.png

味気ないので閾値ラインを入れてみよう。sign_line=Trueを指定するとよい。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', color=('red', 'grey', 'blue'), sign_line=True, show=True)

image.png

閾値を変更してみよう。lfc_thr, pv_thrにそれぞれ下限、上限のタップルを指定すればよい。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', color=('red', 'grey', 'blue'), sign_line=True, lfc_thr=(2, 2), pv_thr=(0.005, 0.005), show=True)

図は省略する。

続いて凡例を入れてみよう。plotlegend=Trueを指定すればよい。凡例の文字列も変更可能だ。
詳しくはドキュメントを見てほしい。

image.png

続いて閾値を超えた遺伝子にラベルを付けてみよう。geneidに遺伝子の名前のある列名を指定し、genenames="deg"を指定すればよい。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', color=('red', 'grey', 'blue'), sign_line=True, lfc_thr=(2, 2), pv_thr=(0.005, 0.005), plotlegend=True, geneid="ID", genenames="deg", show=True)

image.png

ちょっと数が多いので、特定の遺伝子に絞ってラベルをつけてみよう。genenames列にラベルを付けたい遺伝子名をタップルで指定すればよい。

bioinfokit.visuz.gene_exp.volcano(df=df, lfc='logFC', pv='Pvalue', color=('red', 'grey', 'blue'), sign_line=True, lfc_thr=(2, 2), pv_thr=(0.005, 0.005), plotlegend=True, geneid="ID", genenames=("WARS", "GBP1"), show=True)

image.png

おわりに

bioinfokitでは、他にもフォントや軸など色々カスタマイズできるようなので、ドキュメントを見て試行錯誤し、こだわりのボルケーノを描き上げてほしい!

参考文献

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