0
0

More than 1 year has passed since last update.

Google colaboratoryでblast+を利用する

Posted at

blast+はローカル環境でblast検索を行うためのプログラムである。

自信のPCでも実施可能だが、Google Colabratoryでも勘弁に行うことができる。

まず、blast+をインストールする。
最初のセルで以下のコマンドを実行する。

#blast+のインストール
!sudo apt install ncbi-blast+

blast+の実際の動作は"!"を利用したコマンド入力でもいいが、コマンドをpythonで書き換えたい場合はsubprocess.Popenを利用する方が便利である。
そこでまず、これらをimportする。

import subprocess
from subprocess import Popen

さらに次のセルで、試しにblast +のhelpを呼び出してみる。

#blast -helpの呼び出し
#コマンドの文字列を作成

cmd = "blastp -help"

#コマンドの実行
test = subprocess.Popen(cmd, shell=True, text=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = test.communicate()

#結果の出力
print(outs)
print(errs)

これにより、helpが出力されればインストールは成功している。

データベースの作成

以下のコマンドでデータベースの作成が可能である。
#コマンドの文字列を作成
cmd = "makeblastdb "
cmd += "-dbtype prot " #
cmd += "-in file.fasta "
cmd += " -out file_db"

#コマンドの実行
test = subprocess.Popen(cmd, shell=True, text=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = test.communicate()

#結果の出力
print(outs)
print(errs)

実際の検索

queryとなるfastaファイルをアップロードし、以下のコマンドにより、blast検索を実行する。 outの形式は自分の目的に合ったものを選ぶと良い。
#コマンドの文字列を作成
cmd = "blastp " #blastpを実行する場合
cmd += "-query query.fasta " #queryファイル名の入力
cmd += "-db file_db " #データベースのファイル名
cmd += " -out result.txt" #結果のファイル名

#コマンドの実行
test = subprocess.Popen(cmd, shell=True, text=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = test.communicate()

#結果の出力
print(outs)
print(errs)
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