今回の記事内容、果たして意味があるのか不要ですが、
あえてgoogle colaboratoryを使用して、Rでballgownを実行してみます。
下準備
Google colaboratoryでRを使えるようにする
まずは、google colaboratoryでRを使えるようにするコマンドです。
Bash
%load_ext rpy2.ipython以降、%%Rと入れることで、そのブロックではRのコマンドが打てるようになります。
ライブラリのインストール
必要なライブラリをインストールします。
Bash
%%R
install.packages("BiocManager")
BiocManager::install("ballgown", dependencies = TRUE)
install.packages("tidyverse", dependencies = TRUE)
install.packages('metaMA', dependencies = TRUE)結構時間がかかります。
ライブラリの読み込み
Bash
%%R
library(ballgown)
library(tidyverse)
library(metaMA)作業ディレクトリの移動
作業ディレクトリを前回作成したballgownフォルダにします。
Bash
cd /content/drive/MyDrive/colab_RNA-seq/ballgownBash
%%R
#ids列
ids <- c('SRR1571967', 'SRR1571968', 'SRR1571969', 'SRR1571970', 'SRR1571971', 'SRR1571972')
#type列
type <- c('Control', 'Control', 'Control', 'Hif1 mutant', 'Hif1 mutant', 'Hif1 mutant')
#DataFrameの作成
data <- data.frame('ids'=ids, 'type'=type)
#csvファイルとして保存
write.csv(data, 'data_info.csv', row.names = FALSE)/content/drive/MyDrive/colab_RNA-seq/ballgownにdata_info.csvが作成されました。
Ballgownの実行
まずは、ballgownフォルダの親フォルダ`/content/drive/MyDrive/colab_RNA-seqに移動します。
Bash
cd ..その後、先ほど作成したdata_info.csvを読み込み、
Ballgownを以下のように実行します。
Bash
%%R
data_info <- read.csv("ballgown/data_info.csv")
bg <- ballgown(dataDir = "ballgown", pData=data_info, samplePattern = "SRR")
bg低発現遺伝子の削除
低発現の遺伝子を削除します。
Bash
%%R
bg_cut <- subset(bg,"rowVars(texpr(bg)) >1",genomesubset=TRUE)
bg_cutデータテーブルの作成
Bash
%%R
transcript_data <- stattest(bg_cut,
feature = 'transcript',
covariate = 'type',
getFC = 'TRUE',
meas = 'FPKM')
transcript_table <- data.frame(gene = geneNames(bg_cut),
gene_id = geneIDs(bg_cut),
transcript_data)
gene_data <- stattest(bg_cut,
feature = 'gene',
covariate = 'type',
getFC = 'TRUE',
meas = 'FPKM')データの保存
Bash
%%R
write.csv(transcript_table, "transcript_results.csv", row.names=FALSE)
write.csv(gene_data, "gene_results.csv", row.names=FALSE)以上でGoogle colaboratoryでのballgownは終了です。




コメント