-
Notifications
You must be signed in to change notification settings - Fork 0
/
2nd-diary.html
193 lines (179 loc) · 20.9 KB
/
2nd-diary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<title>2nd Diary</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/theme/css/main.css" type="text/css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/ie.css"/>
<script src="/js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/ie6.css"/><![endif]-->
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="/index.html">Codon Alignment GSoC Homepage </a></h1>
<nav><ul>
<li class="active"><a href="/category/gsoc.html">GSoC</a></li>
<li ><a href="/category/me.html">Me</a></li>
<li ><a href="/category/timeline.html">Timeline</a></li>
</ul></nav>
</header><!-- /#banner -->
<section id="content" class="body">
<article>
<header>
<h1 class="entry-title">
<a href="2nd-diary.html" rel="bookmark"
title="Permalink to 2nd Diary">2nd Diary</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<abbr class="published" title="2013-06-28T16:19:00">
Fri 28 June 2013
</abbr>
<address class="vcard author">
By <a class="url fn" href="/author/zheng-ruan.html">Zheng Ruan</a>
</address>
<p>In <a href="/category/gsoc.html">GSoC</a>. </p>
<p>tags: <a href="/tag/codon-alignment.html">Codon Alignment</a><a href="/tag/gsoc.html">GSoC</a></p></footer><!-- /.post-info --> <div class="section" id="things-have-been-done">
<h2>Things have been done</h2>
<p>This week I finished the mismatch support for codon alignment
construction. The underlying algorithms is very similar to that
implemented in <a class="reference external" href="http://www.ncbi.nlm.nih.gov/pubmed/16845082">pal2nal</a>.
Specifically, if the whole protein translated codon re failed to find a hit
in the nucleotide sequence, small 10 amino acids anchor is used to
scan it individually. Unmatched anchors are represented as
<tt class="docutils literal"><span class="pre">'...'</span> * anchor_len</tt> in the re. The program then use the concatenated
anchor expression to scan the whole nucleotide sequence. If this time,
a match is found, it will read through the nucleotide sequence according
to the match span and figure out which positions are not matched. Warning
will raise up for unmatched positions. Another thing I've done is adding
the <tt class="docutils literal">corr_dict</tt> option for <tt class="docutils literal">AlignIO.build</tt> method. This optional
argument will accept a <cite>dict</cite> object that tells the id correspondance
between protein sequence records and nucleotide records. For the IO
support, because of the codon slice in <tt class="docutils literal">CodonSeq</tt>, <tt class="docutils literal">CodonAlignment</tt>
will not be correctly written using normal <tt class="docutils literal"><span class="pre">AlignIO.writ()e</span></tt>. Therefore,
I wrote a <tt class="docutils literal">toMultipleSeqAlignment()</tt> method in <tt class="docutils literal">CodonAlignment</tt>. As its
name indicated, it will return a <tt class="docutils literal">MultipleSeqAlignment</tt> object with
<tt class="docutils literal">Seq</tt> to store sequences. The user can the write out their codon
alignment into any format supported by <tt class="docutils literal">AlignIO</tt>. Finally, I also set
up a test for <tt class="docutils literal">CodonAlign</tt> module. It is named <tt class="docutils literal">test_CodonAlignment</tt>
in <tt class="docutils literal">Tests</tt> directory. Some warnings will raise up because the example
sequences contain mismatches.</p>
</div>
<div class="section" id="some-examples">
<h2>Some Examples</h2>
<p>I will still write some examples here to illustrate the function I've
implemented. I assume <tt class="docutils literal">__init__.py</tt> and <tt class="docutils literal">test_data</tt> are in your
current python directory:</p>
<p>1. Build a <tt class="docutils literal">CodonAlignment</tt> from Protein Alignment and Nucleotide
Sequences when some of the sites are incompatible.</p>
<div class="highlight"><pre><span class="o">>>></span> <span class="kn">from</span> <span class="nn">Bio</span> <span class="kn">import</span> <span class="n">SeqIO</span><span class="p">,</span> <span class="n">AlignIO</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">Bio.Alphabet</span> <span class="kn">import</span> <span class="n">IUPAC</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">__init__</span> <span class="kn">import</span> <span class="n">build</span><span class="p">,</span> <span class="n">default_codon_alphabet</span>
<span class="o">>>></span> <span class="n">nucls5</span> <span class="o">=</span> <span class="n">SeqIO</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">'test_data/nucl5.fa'</span><span class="p">,</span> <span class="s">'fasta'</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">IUPAC</span><span class="o">.</span><span class="n">IUPACUnambiguousDNA</span><span class="p">())</span>
<span class="o">>>></span> <span class="n">pro_alignr5</span> <span class="o">=</span> <span class="n">AlignIO</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">'test_data/pro5.aln'</span><span class="p">,</span> <span class="s">'clustal'</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">IUPAC</span><span class="o">.</span><span class="n">protein</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">aln</span> <span class="o">=</span> <span class="n">build</span><span class="p">(</span><span class="n">pro_align5</span><span class="p">,</span> <span class="n">nucls5</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">default_codon_alphabet</span><span class="p">)</span>
<span class="n">__init__</span><span class="o">.</span><span class="n">py</span><span class="p">:</span><span class="mi">352</span><span class="p">:</span> <span class="ne">UserWarning</span><span class="p">:</span> <span class="n">isotig69710</span> <span class="p">(</span><span class="n">R</span> <span class="mi">0</span><span class="p">)</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">correspond</span> <span class="n">to</span> <span class="n">isotig69710</span> <span class="p">(</span><span class="n">TGA</span><span class="p">)</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s">"</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s"> </span><span class="si">%d</span><span class="s">) does not correspond to </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)"</span> <span class="o">%</span> <span class="p">(</span><span class="n">pro</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">aa</span><span class="p">,</span> <span class="n">aa_num</span><span class="p">,</span> <span class="n">nucl</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">this_codon</span><span class="p">))</span>
<span class="o">>>></span> <span class="k">print</span> <span class="n">aln5</span>
<span class="n">CodonAlphabet</span><span class="p">()</span> <span class="n">CodonAlignment</span> <span class="k">with</span> <span class="mi">3</span> <span class="n">rows</span> <span class="ow">and</span> <span class="mi">555</span> <span class="n">columns</span> <span class="p">(</span><span class="mi">185</span> <span class="n">codons</span><span class="p">)</span>
<span class="n">TGAGGCGATCAACGCAGCAACTTCCAGCTGTCTCCCTCCACCATGCAGATC</span><span class="o">...</span><span class="n">GCATGC</span> <span class="n">isotig69710</span>
<span class="o">------------------------------------------</span><span class="n">ATGAAAGTC</span><span class="o">...------</span> <span class="n">ENSG00000108691</span><span class="p">:</span><span class="n">ENST00000580907</span>
<span class="o">------------------------------------------</span><span class="n">ATGAAAGTC</span><span class="o">...------</span> <span class="n">ENSG00000108691</span><span class="p">:</span><span class="n">ENST00000225831</span>
</pre></div>
<ol class="arabic simple" start="2">
<li>I will then illustrate how to use <tt class="docutils literal">id</tt> option to set up the
correspondance between nucleotide records and protein records.</li>
</ol>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">nucls</span> <span class="o">=</span> <span class="n">SeqIO</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">'test_data/egfr_nucl.fa'</span><span class="p">,</span> <span class="s">'fasta'</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">IUPAC</span><span class="o">.</span><span class="n">IUPACUnambiguousDNA</span><span class="p">())</span>
<span class="o">>>></span> <span class="n">pro_align</span> <span class="o">=</span> <span class="n">AlignIO</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s">'test_data/egfr_pro.aln'</span><span class="p">,</span> <span class="s">'clustal'</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">IUPAC</span><span class="o">.</span><span class="n">protein</span><span class="p">)</span>
<span class="o">>>></span> <span class="nb">id</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]:</span> <span class="n">i</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="s">'test_data/egfr_id'</span><span class="p">)</span><span class="o">.</span><span class="n">readlines</span><span class="p">()}</span>
<span class="o">>>></span> <span class="n">codonaln</span> <span class="o">=</span> <span class="n">build</span><span class="p">(</span><span class="n">pro_align</span><span class="p">,</span> <span class="n">nucls</span><span class="p">,</span> <span class="n">corr_dict</span><span class="o">=</span><span class="nb">id</span><span class="p">,</span> <span class="n">alphabet</span><span class="o">=</span><span class="n">default_codon_alphabet</span><span class="p">,</span> <span class="n">complete_protein</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">__init__</span><span class="o">.</span><span class="n">py</span><span class="p">:</span><span class="mi">352</span><span class="p">:</span> <span class="ne">UserWarning</span><span class="p">:</span> <span class="n">gi</span><span class="o">|</span><span class="mi">47522840</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NP_999172</span><span class="o">.</span><span class="mi">1</span><span class="o">|</span> <span class="p">(</span><span class="n">L</span> <span class="mi">449</span><span class="p">)</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">correspond</span> <span class="n">to</span> <span class="n">gi</span><span class="o">|</span><span class="mi">47522839</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NM_214007</span><span class="o">.</span><span class="mi">1</span><span class="o">|</span> <span class="p">(</span><span class="n">ATG</span><span class="p">)</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s">"</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s"> </span><span class="si">%d</span><span class="s">) does not correspond to </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)"</span> <span class="o">%</span> <span class="p">(</span><span class="n">pro</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">aa</span><span class="p">,</span> <span class="n">aa_num</span><span class="p">,</span> <span class="n">nucl</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">this_codon</span><span class="p">))</span>
<span class="o">>>></span> <span class="k">print</span> <span class="n">codonaln</span>
<span class="n">CodonAlphabet</span><span class="p">()</span> <span class="n">CodonAlignment</span> <span class="k">with</span> <span class="mi">6</span> <span class="n">rows</span> <span class="ow">and</span> <span class="mi">4446</span> <span class="n">columns</span> <span class="p">(</span><span class="mi">1482</span> <span class="n">codons</span><span class="p">)</span>
<span class="n">ATGATGATTATCAGCATGTGGATGAGCATATCGCGAGGATTGTGGGACAGC</span><span class="o">...</span><span class="n">AGGGTG</span> <span class="n">gi</span><span class="o">|</span><span class="mi">24657088</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NM_057410</span><span class="o">.</span><span class="mi">3</span><span class="o">|</span>
<span class="o">---------------------</span><span class="n">ATGCTGCTGCGACGGCGCAACGGCCCCTGC</span><span class="o">...</span><span class="n">AGGGTG</span> <span class="n">gi</span><span class="o">|</span><span class="mi">24657104</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NM_057411</span><span class="o">.</span><span class="mi">3</span><span class="o">|</span>
<span class="o">------------------------------</span><span class="n">ATGAAAAAGCACGAG</span><span class="o">------...</span><span class="n">GGGGCC</span> <span class="n">gi</span><span class="o">|</span><span class="mi">302179500</span><span class="o">|</span><span class="n">gb</span><span class="o">|</span><span class="n">HM749883</span><span class="o">.</span><span class="mi">1</span><span class="o">|</span>
<span class="o">------------------------------</span><span class="n">ATGCGACGCTCCTGGGCGGGC</span><span class="o">...</span><span class="n">GGGGCA</span> <span class="n">gi</span><span class="o">|</span><span class="mi">47522839</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NM_214007</span><span class="o">.</span><span class="mi">1</span><span class="o">|</span>
<span class="o">------------------------------</span><span class="n">ATGCGACCCTCCGGGACGGCC</span><span class="o">...</span><span class="n">GGAGCA</span> <span class="n">gi</span><span class="o">|</span><span class="mi">41327737</span><span class="o">|</span><span class="n">ref</span><span class="o">|</span><span class="n">NM_005228</span><span class="o">.</span><span class="mi">3</span><span class="o">|</span>
<span class="o">------------------------------</span><span class="n">ATGCGACCCTCAGGGACTGCG</span><span class="o">...</span><span class="n">GGAGCA</span> <span class="n">gi</span><span class="o">|</span><span class="mi">6478867</span><span class="o">|</span><span class="n">gb</span><span class="o">|</span><span class="n">M37394</span><span class="o">.</span><span class="mi">2</span><span class="o">|</span><span class="n">RATEGFR</span>
</pre></div>
<ol class="arabic simple" start="3">
<li>To write out a constructed codon alignment, you need to first
convert it into a <tt class="docutils literal">MultipleSeqAlignment</tt> object and then use
the functions in <tt class="docutils literal">AlignIO</tt> to write out. Here is an example:</li>
</ol>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">AlignIO</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">codonaln</span><span class="p">,</span> <span class="s">'ex.clw'</span><span class="p">,</span> <span class="s">'clustal'</span><span class="p">)</span>
<span class="c"># If you open the ex.clw file, it is not properly formated.</span>
<span class="c"># This is caused by the codon slice of CodonSeq objects.</span>
<span class="c"># Here is the correct way to write it out.</span>
<span class="o">>>></span> <span class="n">aln</span> <span class="o">=</span> <span class="n">codonaln</span><span class="o">.</span><span class="n">toMultipleSeqAlignment</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">AlignIO</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">aln</span><span class="p">,</span> <span class="s">'ex1.clw'</span><span class="p">,</span> <span class="s">'clustal'</span><span class="p">)</span>
<span class="c"># This time it will look much better</span>
</pre></div>
<p>If you have any suggestions or request some features that are useful for codon
alignment please let me know.</p>
</div>
<div class="section" id="future-plan">
<h2>Future Plan</h2>
<ol class="arabic simple">
<li>Allow frameshift in the <tt class="docutils literal">AlignIO.build</tt> method.</li>
<li>Reorganize the code into different files.</li>
</ol>
<p>For more info, please visit my
[CodonAlign github repo](<a class="reference external" href="https://github.com/zruan/biopython/tree/master/Bio/CodonAlign">https://github.com/zruan/biopython/tree/master/Bio/CodonAlign</a>)</p>
</div>
</div><!-- /.entry-content -->
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_identifier = "2nd-diary.html";
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://zruansblog.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
</article>
</section>
<section id="extras" class="body">
<div class="blogroll">
<h2>blogroll</h2>
<ul>
<li><a href="http://informatics.nescent.org/wiki/Phyloinformatics_Summer_of_Code_2013#Codon_Alignment_and_Analysis_in_Biopython">NESCent GSoC Project wiki</a></li>
<li><a href="http://biopython.org/wiki/Main_Page">Biopython</a></li>
<li><a href="http://iob.uga.edu/">UGA Bioinformatics</a></li>
<li><a href="http://getpelican.com/">Pelican</a></li>
<li><a href="http://python.org/">Python.org</a></li>
<li><a href="http://jinja.pocoo.org/">Jinja2</a></li>
</ul>
</div><!-- /.blogroll -->
<div class="social">
<h2>social</h2>
<ul>
<li><a href="https://www.facebook.com/ruan.zheng.7">Facebook</a></li>
<li><a href="http://zr1991.blogspot.com/">Google Blogger</a></li>
<li><a href="http://user.qzone.qq.com/8390905">Qzone</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
</footer><!-- /#contentinfo -->
<script type="text/javascript">
var disqus_shortname = 'zruansblog';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
</body>
</html>