Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Finding a Protein Motif: Fetching Data and Using Regular Expressions

nkimoto
February 18, 2022

Finding a Protein Motif: Fetching Data and Using Regular Expressions

2022/02/18 (金) 【第11回】ゼロから始めるゲノム解析(Python編) 資料

nkimoto

February 18, 2022
Tweet

More Decks by nkimoto

Other Decks in Programming

Transcript

  1. 環境構築 - 必要パッケージ群のインストール # 公開されているレポジトリからファイル群を取得 $ git clone https://github.com/kyclark/biofx_python $

    cd biofx_python # requirements.txt に記載のパッケージをインストール $ pip3 install -r requirements.txt # pylintの設定ファイルをホームディレクトリに移動 $ cp pylintrc ~/.pylintrc # mypyの設定ファイルをホームディレクトリに移動 $ cp mypy.ini ~/.mypy.ini
  2. UniProtについて https://www.uniprot.org/ SIB Swiss Institute of BioinformaticsとEuropean Bioinformatics Institute が運営するタンパク質のアミノ酸配列お

    よびその機能情報を提供する代表的なデータベース。タンパク質に関連するさまざまな情報を横断的・網羅的に調 べることができる世界で最も広範なタンパク質の情報カタログ
  3. IDを元にUniProtのURLを作成 UniProtでは、タンパク質にユニークなアクセッションIDが割り振られており、 URLも以下のように対応している。 def main() -> None: args = get_args()

    for prot_id in map(str.rstrip, args.file): print(f'http://www.uniprot.org/uniprot/{prot_id}') $ ./mprt.py tests/inputs/1.txt http://www.uniprot.org/uniprot/A2Z669 http://www.uniprot.org/uniprot/B5ZC00 http://www.uniprot.org/uniprot/P07204_TRBM_HUMAN http://www.uniprot.org/uniprot/P20840_SAG1_YEAST
  4. FASTAファイルのダウンロード(bash) bashスクリプトによりファイルのダウンロードを自動化 #!/usr/bin/env bash if [[ $# -ne 1 ]];

    then printf "usage: %s FILE\n" $(basename "$0") exit 1 fi OUT_DIR="fasta" [[ ! -d "$OUT_DIR" ]] && mkdir -p "$OUT_DIR" while read -r PROT_ID; do echo "$PROT_ID" URL="https://www.uniprot.org/uniprot/${PROT_ID}" OUT_FILE="$OUT_DIR/${PROT_ID}.fasta" wget -q -o "$OUT_FILE" "$URL" done < $1 1 1 PATH環境変数の通っている 場所からbashを使用 2 2 引数の数「$#」が1でなければ エラー終了 3 3 出力ディレクトリがなければ作 成 4 4 ファイルの各行をPROT_IDと して格納 5 5 wgetコマンドでファイルをダウ ンロード
  5. FASTAファイルのダウンロード(python) 1 2 4 1 出力ディレクトリがなければ作 成 2 ファイルからIDを読み取り 5

    3 requestsモジュールにより作 成したURLにGETリクエストを 投げる 3 4 ステータスコード200の場合、 レスポンスをファイルに格納 5 200以外の場合、エラーメッ セージを表示して継続
  6. 正規表現でN-glycosylationモチーフを表現 2つのN-glycosylationモチーフを持つ配列からN-glycosylationモチーフを取得 >>> seq = 'NNTSYS' >>> regex = re.compile('(?=(N[^P][ST][^P]))')

    >>> regex.findall(seq) ['NNTS', 'NTSY'] >>> [match.start() + 1 for match in regex.finditer(seq)] [1, 2] マッチしたポジションを出力
  7. 解法1正規表現を用いてモチーフ探索 1 ファイルに記載されているID のFASTAファイルを取得 1 2 正規表現を作成 2 3 FASTAファイルをSeqIOモ

    ジュールで読み込んでレコード があればrecに格納 3 4 その配列に正規表現のマッチ が存在すれば開始位置を出 力 4