Counting DNA Nucleotid
バイオインフォマティクスの学習に必要な情報や、問題を提供するサイト
ROSALIND
rosalind.infoで、Pythonを用いたバイオインフォマティクス技能の学習を行う。
5つコンテンツがあるが、問題形式で学習するスタイルが好きなので、上段真ん中の"Bioinformatics Stronghold"を選択。
まずは一番上のCounting DNA Nucleotidesから。
回答はJupyter Notebook (python 3.7.6)で作成する。
Problem
A string is simply an ordered collection of symbols selected from some alphabet and formed into a word; the length of a string is the number of symbols that it contains.
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', and 'T') is "ATGCTTCAGAAAGGTCTTACG."
Given: A DNA string s
of length at most 1000 nt.
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in s
.
Sample Dataset
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
Sample Output
20 12 17 21
与えられた1,000 nt以下の長さのDNA配列のうち、'A','C', 'G', 'T'の下図をそれぞれカウントし、出力せよ。という課題。
"Download dataset"をクリックするとデータのダウンロードが実行され、カウントダウン(5 min)が始まる。
file_name=('./rosalind_dna.txt') #ファイル名の読み込み
file=open(file_name) #データを開く
data=file.read() #読み込み
print(len(data)) #データの文字数
a=data.count('A') #各塩基の出現数を.count()メソッドでカウント
t=data.count('T')
g=data.count('G')
c=data.count('C')
print(a, c, g, t) #出力
992
233 256 261 241
参考
【Python】 特定の文字や文字列の出現回数を数える(count) | Hbk project
メソッドとかもよくわかっておらず、参考にしたコードのほぼ丸パクリをしたが、使っているとメソッドとはなんぞやとか関数の使い方とかいろいろわかってきそう。
環境設定で問題が発生することもなかったし、1日目にしては上出来。