Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Computing GC Content: Parsing FASTA and Analyzi...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
nkimoto
January 29, 2022
Programming
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Computing GC Content: Parsing FASTA and Analyzing Sequences
2022/01/14 (金) 【第7回】ゼロから始めるゲノム解析(Python編) 資料
nkimoto
January 29, 2022
Transcript
20 slides
【第7回】ゼロから始めるゲノム解析 (Python編) Computing GC Content: Parsing FASTA and Analyzing Sequences
@kimoton
本勉強会の概要・目的 書籍名 対象者/目的 Mastering Python for Bioinformatics Python・バイオインフォ知識ほぼゼロの人 を対象に、正しいPythonのコーディング手 法について学ぶ
頻度 毎週〜隔週開催予定 登壇者 募集中!
Rosalindとは • 問題解決を通じてバイオインフォマティク ス、プログラミング、およびアルゴリズムを 学習するためのプラットフォーム • 大学やハッカソン、就職の面接にも 600回 以上の採用実績あり 参考:https://qiita.com/_kimoton/items/d534d0fa9b83dd7dc412
概要
環境構築 - 必要パッケージ群のインストール # 公開されているレポジトリからファイル群を取得 $ 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
本日のお題 塩基配列を翻訳せよ https://rosalind.info/problems/prot/
本日学ぶこと • 文字列スライスを使って、コドン/k-merを抽出する方法 • 辞書型をテーブルの検索に使用する方法 • forループをリスト内包表記やmap()関数で置き換える方法 • takewhile() や
partial() 関数の使用方法 • Bio.Seqモジュールを用いたmRNA→アミノ酸配列への変換
前提知識編
K-merとコドン https://ja.wikipedia.org/wiki/%E3%82%B3%E3%83%89%E3%83%B3 RNAのコドン表 翻訳は3-merごとに行われる
文字列スライスを使った3-merごとの抽出 文字列スライスでインデックスを3飛ばしずつ読むことで3-merの抽出ができる >>> rna = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA' >>> rna[0:3] 'AUG' >>>
rna[3:6] 'GCC' >>> rna[6:9] 'AUG'
文字列スライスを使った3-merごとの抽出 リスト内包表記を使うことで全配列に渡って3-merごとに抽出することができる >>> rna = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA' # STEP1. スライスstartの取得 >>>
list(range(0, len(rna), 3)) [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] # STEP2. スライス(start, end)の取得 >>> [(n, n + 3) for n in range(0, len(rna), 3)][:5] [(0, 3), (3, 6), (6, 9), (9, 12), (12, 15)] # STEP2. スライス結果の取得 >>> [rna[n:n + 3] for n in range(0, len(rna), 3)][:5] ['AUG', 'GCC', 'AUG', 'GCG', 'CCC']
(参考)K-merの抽出 同様の処理でK-mer全てを抽出することができる >>> rna = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA' >>> [rna[n:n + 3]
for n in range(0, len(rna)-2)] ['AUG', 'UGG', 'GGC', 'GCC', 'CCA', 'CAU', 'AUG', 'UGG', 'GGC', 'GCG', 'CGC', 'GCC', 'CCC', 'CCA', 'CAG', 'AGA', 'GAA', 'AAC', 'ACU', 'CUG', 'UGA', 'GAG', 'AGA', 'GAU', 'AUC', 'UCA', 'CAA', 'AAU', 'AUA', 'UAG', 'AGU', 'GUA', 'UAC', 'ACC', 'CCC', 'CCG', 'CGU', 'GUA', 'UAU', 'AUU', 'UUA', 'UAA', 'AAC', 'ACG', 'CGG', 'GGG', 'GGU', 'GUG', 'UGA']
辞書型を用いたコドン→アミノ酸への変換 コドン→アミノ酸への変換は辞書型で実装できる。 終止コドンは「*」で示すことが多い。 >>> rna = 'AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA' >>> aa =
[] >>> for codon in [rna[n:n + 3] for n in range(0, len(rna), 3)]: ... aa.append(codon_to_aa[codon]) ... >>> aa ['M', 'A', 'M', 'A', 'P', 'R', 'T', 'E', 'I', 'N', 'S', 'T', 'R', 'I', 'N', 'G', '*']
解法編
解法1forループを使用した実装 1 入力されたRNA文字列を大文字に変換 2 コドン表を辞書型で定義 3 大文字/小文字の塩基に該当すれば相補 的な塩基をrevc変数に追加 1 2
3 4 4 コドン表を使って3-merの塩基配列を 置換(存在しない場合、「-」) 5 5 終止コドンの場合、翻訳終了
解法2処理の関数化&単体テストを追加 1 コドンに分割する処理をcodon関数と して定義 2 codon関数の単体テストを実装 1 2
解法3処理の関数化&単体テストを追加 1 RNA配列を翻訳する処理をtranslate関数 として定義 3 終止コドンの位置までの配列にスライス 1 4 2 翻訳部分をリスト内包表記で実装
2 4 translate関数の単体テストを実装 3
解法3処理の関数化&単体テストを追加 1 RNA配列を翻訳する処理をtranslate関数 として定義 3 終止コドンの位置までの配列にスライス 1 4 2 翻訳部分をリスト内包表記で実装
2 4 translate関数の単体テストを実装 3
解法4map(), partial(), takewhile()を用いた関数型プログラミング
解法5Bio.Seq.translateモジュールを使用 参考:https://biopython.org/docs/1.76/api/Bio.Seq.html#Bio.Seq.Seq.translate (著者の意見) ドキュメント化され、テストされ、広く利用されている Bio.Seq.translateモジュールを使 用すべき
追加課題 デフォルト値が0かつ0-2の値を取り得る --frame-shift 引数を追加して、 指定した数値分ずれた開始地点から翻訳を開始するように実装 demo
More Decks by nkimoto
See All by nkimoto
Location Restriction Sites: Using, Testing, and Sharing Code
nkimoto
0
390
Finding a Protein Motif: Fetching Data and Using Regular Expressions
nkimoto
0
370
Overlap Graphs: Sequence Assembly Using Shared K-mers
nkimoto
0
250
【第5回】ゼロから始めるゲノム解析(Python編)
nkimoto
0
780
【第3回】ゼロから始めるゲノム解析(Python編)
nkimoto
0
490
【第1回】ゼロから始めるゲノム解析(Python編).pdf
nkimoto
0
960
【第7回】ゼロから始めるゲノム解析.pdf
nkimoto
0
500
【第5回】ゼロから始めるゲノム解析(R編)
nkimoto
0
600
【第3回】ゼロから始めるゲノム解析(R編)
nkimoto
0
1.6k
Other Decks in Programming
See All in Programming
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
250
Performance Optimization With LLMs
xleitix
0
250
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
420
Crash Auto Pipelines
veronikapj
1
410
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
590
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
100
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.2k
Spec-driven Development with AI
simas
PRO
0
2.3k
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
170
Seven New Principles of Software Engineering
yegor256
0
480
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
320
オーケストレーション記述言語 Katari
yukikurage
0
250
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
6
920
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Un-Boring Meetings
codingconduct
0
490
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.2k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
660
Odyssey Design
rkendrick25
PRO
3
940
Product Roadmaps are Hard
iamctodd
55
13k
From π to Pie charts
rasagy
1
440
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Designing Experiences People Love
moore
143
24k