<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ed&#039;s Big Plans</title>
	<atom:link href="http://eddiema.ca/feed/" rel="self" type="application/rss+xml" />
	<link>http://eddiema.ca</link>
	<description>Science, Technology, Adventure</description>
	<lastBuildDate>Mon, 26 Jul 2010 02:48:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Bioinformatics: Edit Strings (Ruby, JavaScript)</title>
		<link>http://eddiema.ca/2010/07/24/bioinformatics-edit-strings-ruby-javascript/</link>
		<comments>http://eddiema.ca/2010/07/24/bioinformatics-edit-strings-ruby-javascript/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 20:34:35 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Alignment Strings]]></category>
		<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Edit Strings]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Multiple Sequence Alignment]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1585</guid>
		<description><![CDATA[&#62;&#62;&#62; Attached: ( editStringAdder.rb &#8212; in Ruby &#124; editStrings.js &#8212; in JavaScript ) &#60;&#60;&#60; I wanted to share something neat that I&#8217;ve been using in the phylogeny analyzing software I&#8217;ve been developing. In the MUSCLE3 BMC Bioinformatics paper (Robert Edgar, 2004), Edgar describes a way to describe all the changes required to get from one [...]]]></description>
			<content:encoded><![CDATA[<p>&gt;&gt;&gt; <span style="text-decoration: underline;">Attached</span>: ( <a href="http://eddiema.ca/wp-content/uploads/2010/07/editStringAdder.rb">editStringAdder.rb</a> &#8212; in Ruby | <a href="http://eddiema.ca/wp-content/uploads/2010/07/editStrings.js">editStrings.js</a> &#8212; in JavaScript ) &lt;&lt;&lt;</p>
<p>I wanted to share something neat that I&#8217;ve been using in the phylogeny analyzing software I&#8217;ve been developing. In the <a href="http://www.biomedcentral.com/1471-2105/5/113">MUSCLE3 BMC Bioinformatics paper (Robert Edgar, 2004)</a>, <a href="http://robertedgar.wordpress.com/">Edgar</a> describes a way to describe all the changes required to get from one raw sequence to how it appears somewhere in an internal node, riddled with gaps. He calls the data structures <em>Edit Strings</em> (e-strings).</p>
<p>I started using these things in my visualizer because it is a convenient way to describe how to render a profile of sequences at internal nodes of my phylogenetic trees. Rather than storing a copy of the sequence with gaps at each of its ancestors, e-strings allow you to store a discrete pathway of the changes your alignment algorithm made to a sequence at each node.</p>
<p>You can chain e-strings together with a <em>multiply</em> operation so that the profile of any node in the tree can be created out of just the original primary sequences of the dataset (the taxa) and the set of corresponding e-strings for the given tree. You can choose to store the alphabet-distribution profiles this way at each node too, but I decided to use the e-strings only for my visualizer (where <em>seeing</em> each sequence within a profile is important).</p>
<p>Edit strings take the form of a sequence of alternating positive and negative integers; positive integers mean &#8220;retain a substring of this length&#8221; while negative integers mean &#8220;insert gaps of this length&#8221; &#8212; here&#8217;s a few example applications of edit strings on the sequence &#8220;<span style="font-family: courier new,courier;">ABCDEFGHI</span>&#8220;:</p>
<pre>&lt;10&gt;("ABCDEFGHIJ") = "ABCDEFGHIJ"
&lt;10 -3&gt;("ABCDEFGHIJ") = "ABCDEFGHIJ---"
&lt;4, -2, 6&gt;("ABCDEFGHIJ") = "ABCD--EFGHIJ"
&lt;2, -1, 5, -4, 3&gt;("ABCDEFGHIJ") = "AB-CDEFG----HIJ"</pre>
<p>A few particulars should be mentioned. An application of an e-string onto a sequence is only defined when the sum of the positive integers equals the length of the sequence. The total number of negative integers is arbitrary, and refers to any number of inserted gaps. Finally, a digit zero is meaningless. Edit strings can be <em>multiplied</em> together. If you apply two edit strings in succession onto a sequence, the result is the same as if you had applied the product of two edit strings onto that same sequence. Here are some examples of edit strings multipled together.</p>
<pre>&lt;10&gt; * &lt;10&gt; = &lt;10&gt;
&lt;10&gt; * &lt;7, -1, 2&gt; = &lt;7, -1, 2&gt;
&lt;6, -1, 4&gt; * &lt;7, -1, 3, -2, 1&gt; = &lt;6, -2, 3, -2, 1&gt;
&lt;6, -1, 4&gt; * &lt;3, -1, 3, -1, 3, -1, 2&gt; = &lt;3, -1, 3, -2, 2, -1, 2&gt;
&lt;6, -1, 4&gt; * &lt;2, -1, 6, -5, 3&gt; = &lt;2, -1, 4, -1, 1, -5, 3&gt;</pre>
<p>The multiply function is a bit tricky to implement at first, but one can work backward from the result to get the intermediate step that&#8217;s performed mentally. The last two examples above can manually calculated if we imagine an intermediate step as follows. We convert the first e-string to its application on a sequence of &#8216;+&#8217; symbols&#8211; in both the below cases, this results in ten &#8216;+&#8217; symbols with one &#8216;-&#8217; (gap) inserted after the sixth position. We then apply the second edit string to the result of the first application. Finally, we write out the total changes as an e-string on the original sequence of ten &#8216;+&#8217; symbols. Don&#8217;t worry, we don&#8217;t really do this in real life software &#8212; it&#8217;s just a good way for human brains to comprehend the overall operation.</p>
<p>Second last example above &#8212; expanded out&#8230;</p>
<pre>&lt;6, -1, 4&gt; * &lt;3, -1, 3, -1, 3, -1, 2&gt; = ...
++++++-++++ * &lt;3, -1, 3, -1, 3, -1, 2&gt; = ...
+++-+++--++-++ = &lt;3, -1, 3, -2, 2, -1, 2&gt;</pre>
<p>Last example above &#8212; expanded out&#8230;</p>
<pre>&lt;6, -1, 4&gt; * &lt;2, -1, 6, -5, 3&gt; = ...
++++++-++++ * &lt;2, -1, 6, -5, 3&gt; = ...
++-++++-+-----+++ = &lt;2, -1, 4, -1, 1, -5, 3&gt;</pre>
<p>Here&#8217;s the code in Ruby for my take on the multiply function. I derived my version of the function based on the examples from Edgar&#8217;s BMC paper (mentioned before). When you think about it, the runtime is the sum of the number of elements of the two e-strings being multiplied. This becomes obvious when you realize that the only computation that really occurs is when a positive integer is encountered in the second e-string. The function is called estring_product(), it takes two e-strings as arguments (u, v) and returns a single e-string (w). This function internally calls an estring_collapse() function because we intermediately create an e-string that may have several positive integers or several negative integers in a row (when this happens, it&#8217;s usually just two in a row). Consecutive same-signed integers of an e-string are added together.</p>
<pre class="brush: ruby;">
def estring_product(u, v)
    w = []
    uu_replacement = nil
    ui = 0
    vi = 0
    v.each do |vv|
        if vv &lt; 0
            w &lt;&lt; vv
        elsif vv &gt; 0
            vv_left = vv
            uu = uu_replacement != nil ? uu_replacement : u[ui]
            uu_replacement = nil
            until vv_left == 0
                if vv_left &gt;= uu.abs
                    w &lt;&lt; uu
                    vv_left -= uu.abs
                    ui += 1
                    uu = u[ui]
                else
                    if uu &gt; 0
                        w &lt;&lt; vv_left
                        uu -= vv_left
                    elsif uu &lt; 0
                        w &lt;&lt; -vv_left
                        uu += vv_left
                    end
                    vv_left = 0
                    uu_replacement = uu
                end
            end
        end
        vi += 1
    end
    return estring_collapse(w)
end
</pre>
<p>If you aren&#8217;t familiar with Ruby, the &#8220;&lt;&lt;&#8221; operator means &#8220;append the right value to the left collection&#8221;. Everything else should be pretty self-explanatory (leave a comment if it&#8217;s not).</p>
<pre class="brush: ruby;">
def estring_collapse(u)
    v = []
    u.each do |uu|
        if v[-1] == nil
            v &lt;&lt; uu
        elsif (v[-1] &lt;=&gt; 0) == (uu &lt;=&gt; 0)
            v[-1] += uu
        else
            v &lt;&lt; uu
        end
    end
    return v
end
</pre>
<p>The &#8220;&lt;=&gt;&#8221; lovingly referred to as the spaceship operator compares the right value to the left value; if the right value is greater, then the result is 1.0; if the left value is greater, then the result is -1.0; if the left and right values are the same, then the result is 0.0.</p>
<p><strong>A Few Notes on the Attached Files (Ruby, Javascript)</strong></p>
<p>The Ruby source has a lot of comments in it that should help you understand when and where to use the included two functions. The Javascript is actually used in a visualizer I&#8217;ve deployed now so it has a few more practical functions in it. A function called sequence_estring() is included that takes a $sequence and applies an $estring, then returns a new gapped sequence. A utility signum() function is included which takes the place of the spaceship operator in the Ruby version. A diagnostic function, p_uvw() is included that just uses document.write() to print out whatever you give as (estring) $u, (estring) $v and (estring) $w. Finally, the JavaScript functions sequence_estring() and estring_product() will print out error messages with document.write() when the total sequence length specified in the first argument is not the same as the total sequence length implied by the second argument. Remember, the sum of the <em>absolute values</em> of the first argument describes the total length of the sequence&#8211; each of these tokens must be accounted for by the <em>positive values</em> of the second argument, the estring that will operate on it.</p>
<p><em><strong>Updates to this post:</strong></em></p>
<ol>
<li>Two hyphens in a row were displayed as a single dash &#8212; this has been fixed.</li>
<li>Code listing plug-in uses literal &#8220;&lt;&#8221; and &#8220;&gt;&#8221; instead of the entity codes &#8220;&amp;lt;&#8221; and &#8220;&amp;gt;&#8221; &#8212; fixed.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/07/24/bioinformatics-edit-strings-ruby-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first TA Evaluations!</title>
		<link>http://eddiema.ca/2010/07/18/my-first-ta-evaluations/</link>
		<comments>http://eddiema.ca/2010/07/18/my-first-ta-evaluations/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 17:19:58 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[People]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Ariana Marcassa]]></category>
		<category><![CDATA[BIOL 208]]></category>
		<category><![CDATA[Evaluations]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Teacher Assistant]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1910</guid>
		<description><![CDATA[Brief: I got my TA evaluations from BIOL 208 back last week (which I taught with Ariana in fall 2009) and it looks the students liked my instruction. The overall positive response is encouraging but I&#8217;m concerned that they&#8217;ve actually been too kind. The whole thing was something of a learning experience for me as [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Brief: </strong></em>I got my TA evaluations from BIOL 208 back last week (which I taught with Ariana in fall 2009) and it looks the students liked my instruction. The overall positive response is encouraging but I&#8217;m concerned that they&#8217;ve actually been too kind. The whole thing was something of a learning experience for me as I&#8217;ve never given tutorials before. The written remarks were very informative too. There are two big things the students wanted more of: first, I should increase the depth of my background in the course; second, I should ensure there&#8217;s time to take up quiz and workbook questions. The first item is a bit difficult to do actively mostly because it&#8217;s hard to proactively decide on what kinds of questions a student will have cooked up based on the readings available for a given week. It looks like it&#8217;s a self-repairing problem however &#8212; I simply have to TA more in and around the same topic area until the background information is second hand (or at least until all the keywords are loaded into my brain along with hints toward appropriate literature). The second point is important. The amount of time needed to take up questions can be built into the lesson plan &#8212; I think the best way to approach this is to <em>reduce </em>the amount that we try to cover in the tutorial slide show. Besides, there&#8217;s little advantage to repeating all of the same things as the instructor (particularly if <em>we might say it differently</em>, or <em>explain it in a way that&#8217;s even more confusing</em> or worse, <em>disagree with the instructor</em>). It&#8217;s thus better to focus on giving the background for the workbook questions. I figure that an average of 25% to 33% less material covered will enable us to focus in on the workbook and allow us to discuss quiz questions (and spurious questions) etc. with sufficient time.</p>
<p>Overall, this was a very enjoyable and instructional experience <img src='http://eddiema.ca/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/07/18/my-first-ta-evaluations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Null Coalescing Operator (C#, Ruby, JS, Python)</title>
		<link>http://eddiema.ca/2010/07/07/the-null-coalescing-operator-c-ruby-js-python/</link>
		<comments>http://eddiema.ca/2010/07/07/the-null-coalescing-operator-c-ruby-js-python/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 15:00:37 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Null Coalescence]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1610</guid>
		<description><![CDATA[Null coalescence allows you to specify what a statement should evaluate to instead of evaluating to null. It is useful because it allows you to specify that an expression should be substituted with some semantic default instead of defaulting on some semantic null (such as null, None or nil). Here is the syntax and behaviour [...]]]></description>
			<content:encoded><![CDATA[<p>Null coalescence allows you to specify what a statement should evaluate to instead of evaluating to null. It is useful because it allows you to specify that an expression should be substituted with some semantic default instead of defaulting on some semantic null (such as null, None or nil). Here is the syntax and behaviour in four languages I use often &#8212; C#, Ruby, JavaScript and Python.</p>
<h3><strong>C#</strong></h3>
<p>Null coalescencing in C# is very straight forward since it will only ever accept first class objects of the same type (or null) as its operator&#8217;s arguments. This restriction is one that exists at compile time; it will refuse to compile if it is asked to compare primitives, or objects of differing types (unless they&#8217;re properly cast).</p>
<p><em>Syntax:</em></p>
<pre>&lt;expression&gt; <strong>??</strong> &lt;expression&gt;</pre>
<p>(The usual rules apply regarding nesting expressions, the use of semi-colons in complete statements etc..)</p>
<p><em>A few examples:</em></p>
<pre>DummyNode a = null;
DummyNode b = new DummyNode();
DummyNode c = new DummyNode();

return a ?? b; // returns b
return b ?? a; // still returns b
DummyNode z = a ?? b; // z gets b
return a ?? new DummyNode(); // returns a new dummy node
return null ?? a ?? null; // this code has no choice but to return null
return a ?? b ?? c; // returns b -- the first item in the chain that wasn't null</pre>
<p>No, you&#8217;d never really have a bunch of return statements in a row like that &#8212; they&#8217;re only there to demonstrate what you should expect.</p>
<h3><strong>Ruby, Python and Javascript<br />
</strong></h3>
<p>These languages are less straight forward (i.e. possess picky nuances) since they are happy to evaluate any objects of any class with their coalescing operators (including emulated primitives). These languages however disagree about what the notion of null should be when it comes to numbers, strings, booleans and empty collections; adding to the importance of testing your code!</p>
<p><em>Syntax for Ruby, Javascript:</em></p>
<pre>&lt;expression&gt; <strong>||</strong> &lt;expression&gt;</pre>
<p><em>Syntax for Ruby, Python:</em></p>
<pre>&lt;expression&gt; <strong>or</strong> &lt;expression&gt;</pre>
<p>(Ruby is operator greedy <img src='http://eddiema.ca/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .)</p>
<p>The use of null coalescence in these languages are the same as they are in C# in that you may nest coalescing expressions as function arguments, use them in return statements, you may chain them together, put in an object constructor as a right-operand expression etc.; the difference is in what Ruby, Python or Javascript will coalesce given a left-expression operand. The below table summarizes what left-expression operand will cause the statement to coalesce into the right-expression operand (i.e. what the language considers to be &#8216;null&#8217;-ish in this use).</p>
<table border="0">
<tbody>
<tr style="background-color: #e9967a;" align="center" valign="middle">
<td style="text-align: center;"><span style="font-size: small;">Expression as a left-operand</span></td>
<td style="text-align: center;"><span style="font-size: small;">Does this coalesce in Ruby?</span></td>
<td style="text-align: center;"><span style="font-size: small;">Does this coalesce in Python?</span></td>
<td style="text-align: center;"><span style="font-size: small;">Does this coalesce in JavaScript?</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">nil / None / null</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">[]<br />
</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">{}</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">n/a*<br />
</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">0</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">0.0</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">&#8220;&#8221;</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">&#8221;</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">No</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
<tr>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">false / False / false<br />
</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
<td style="text-align: center;"><span style="font-size: small; font-family: andale mono,times;">Yes</span></td>
</tr>
</tbody>
</table>
<p>*Note that in JavaScript, you&#8217;d probably want to use an Object instance as an associative array (hash) so that the field names are the keys and the field values are the associated values &#8212; doing so means that you can never have a null associative array.</p>
<p>Contrast the above table to what C# will coalesce: strictly &#8220;null&#8221; objects only.</p>
<p>The null coalescing operator makes me happy. Hopefully it&#8217;ll make you happy too.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/07/07/the-null-coalescing-operator-c-ruby-js-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Borrowing Ruby ideas: Returning an object instance</title>
		<link>http://eddiema.ca/2010/06/27/borrowing-ruby-ideas-returning-an-object-instance/</link>
		<comments>http://eddiema.ca/2010/06/27/borrowing-ruby-ideas-returning-an-object-instance/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 07:00:36 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1623</guid>
		<description><![CDATA[Brief: Ruby conventions were designed to be particularly satisfying and intuitive for the developer. One convention that Ruby adds to the object oriented world is for mutators (setters) to return the object instance &#8212; that is, calling an object&#8217;s mutators will not only alter the object, but will also return the object (not the mutated [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Brief: </strong></em>Ruby conventions were designed to be particularly satisfying and intuitive for the developer. One convention that Ruby adds to the object oriented world is for mutators (setters) to return the object instance &#8212; that is, calling an object&#8217;s mutators will not only alter the object, but will also return the object (not the mutated property). This is especially useful if you want to chain a bunch of mutators together for code legibility or developer convenience.</p>
<p>This would be a welcome shorthand for developers of C-derived object oriented languages such as Java and C#. The following chain&#8230;</p>
<pre>a.setMass(17);
a.setName("cube");
a.setFace(null);
</pre>
<p>&#8230;would become&#8230;</p>
<pre>a.setMass(17).setName("cube").setFace(null);
</pre>
<p>&#8230;a much more compact and what I feel is a more intuitive chain.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/27/borrowing-ruby-ideas-returning-an-object-instance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Parsing a Newick Tree with recursive descent</title>
		<link>http://eddiema.ca/2010/06/25/parsing-a-newick-tree-with-recursive-descent/</link>
		<comments>http://eddiema.ca/2010/06/25/parsing-a-newick-tree-with-recursive-descent/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 02:00:25 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Andre Masella]]></category>
		<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[Newick Format]]></category>
		<category><![CDATA[parse_newick.js]]></category>
		<category><![CDATA[Phylogeny]]></category>
		<category><![CDATA[Recursive Descent Parser]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1622</guid>
		<description><![CDATA[&#62;&#62;&#62; Attached: ( parse_newick.js &#8211; implementation in JS &#124; index.html &#8211; example use ) &#60;&#60;&#60; This method of parsing works for any language that allows recursive functions &#8212; basically any of the curly bracket languages (C#, C, Java) and the fast-development languages (Ruby, JavaScript, Python) can do this. This particular example will include JavaScript code [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: tahoma,arial,helvetica,sans-serif;">&gt;&gt;&gt; <span style="text-decoration: underline;">Attached</span>: ( <a href="http://eddiema.ca/wp-content/uploads/2010/05/parse_newick.js">parse_newick.js</a> &#8211; implementation in JS | <a href="http://eddiema.ca/wp-content/uploads/2010/05/index.html">index.html</a> &#8211; example use ) &lt;&lt;&lt;<br />
</span></p>
<p>This method of parsing works for any language that allows recursive functions &#8212; basically any of the curly bracket languages (C#, C, Java) and the fast-development languages (Ruby, JavaScript, Python) can do this. This particular example will include JavaScript code which you can take and do whatever you want with &#8212; recursive descent parsing is a well-known and solved problem, so it&#8217;s no skin off my back. Before we begin, I should probably explain what a tree in Newick format is.</p>
<p><strong>What exactly <em>is</em> the Newick format?</strong></p>
<p>Remember back in second year CS when your data structures / abstract data types / algorithms instructor said you can represent any tree as a traversal? Well, if not &#8212; don&#8217;t fret, it&#8217;s not hard to get the hang of.</p>
<p>A traversal is a finite, deterministic representation of a tree which can be thought of as a road map of how to visit each node of the tree exactly once. The phylogeny / bioinformatics people will know each of these nodes as either taxa / sequences (the leaves) or profiles (the internal nodes &#8212; i.e. not the leaves). A tree in Newick format is exactly that &#8212; a traversal. More specifically, it is a depth-first post-order traversal. When traversing a tree, we have a few options about how we want to visit the nodes &#8212; depth-first post-order means we want to start at the left-most, deepest leaf, and recursively visit all of the nodes before we end at the root.</p>
<p>A tree expressed in Newick format describes a tree as an observer has seen it having visited each node in a depth-first post-order traversal.</p>
<p>A node in the Newick format can be&#8230;</p>
<ul>
<li>A leaf in the form: &#8220;&lt;<em>name</em>&gt;:&lt;<em>branch_length</em>&gt;&#8221;
<ul>
<li>e.g. &#8220;<span style="font-family: andale mono,times;">lcl|86165:-0</span>&#8220;</li>
<li>e.g. &#8220;<span style="font-family: andale mono,times;">gi|15072471:0.00759886</span>&#8220;</li>
<li>e.g. &#8220;<span style="font-family: andale mono,times;">gi|221105210:0.00759886</span>&#8220;</li>
</ul>
</li>
<li>Or a node in the form &#8220;(&lt;<em>node</em>&gt;,&lt;<em>node</em>&gt;):&lt;<em>branch_length</em>&gt;&#8221;
<ul>
<li>This is where it gets tricky and recursive &#8212; the &#8220;node&#8221; item above can be another node, or a leaf &#8212; when a node is composed of at least another node, we call that a recursive case; when a node is composed of only leaves, we call that a base case. We make this clearer in the next section.</li>
</ul>
</li>
<li>Or a node in the form &#8220;(&lt;<em>node</em>&gt;,&lt;<em>node</em>&gt;);&#8221;
<ul>
<li>The semi-colon at the end means that we have finished describing the tree. There is no branch length as the root of the tree is not connected to a parent.</li>
</ul>
</li>
</ul>
<p><strong>Understanding recursion in a Newick Tree</strong></p>
<p><em>Base case e.g.: The below node is composed of two leaves.<br />
</em></p>
<p>&#8220;<span style="font-family: andale mono,times;">(lcl|86165:-0,gi|87118305:-0):0.321158</span>&#8221;</p>
<p><em>Recursive case e.g.: The below node is composed of a <span style="background-color: #ff99cc;">leaf on the left</span>, and another <span style="background-color: #ccffff;">node on the right</span>; this right-node is composed of two leaves.<br />
</em></p>
<p><span style="font-size: x-small;"><span style="font-family: andale mono,times;">&#8220;(<span style="background-color: #ff99cc;">gi|71388322:0.0345038</span>,<span style="background-color: #ccffff;">(gi|221107809:0.00952396,gi|221101741:0.00952396):0.0249798)</span>:0.0111081</span>&#8220;</span></p>
<p>If the names look a bit funny, that&#8217;s because these are sequences pulled  out of a <em><strong>blastp</strong></em> search.</p>
<p>The Newick tree itself may have any number of nodes, the base case being a single node. The only restriction is that any node either is a leaf (has zero children) or must have two children (never a single child). These two children again are allowed to be either leaves or other nodes.</p>
<p>We would visualize the above <em>Recursive case e.g.</em> as follows.:</p>
<p><img class="aligncenter size-full wp-image-1757" title="blog_newick_subtree_recurs_case_eg" src="http://eddiema.ca/wp-content/uploads/2010/05/blog_newick_subtree_recurs_case_eg.png" alt="" width="341" height="191" /></p>
<p>Where the numbers beside the edges are edge length and the names of the named taxa are indicated inside the circles (leaves). The unnamed internal nodes are the profiles that have been calculated with alignments. You&#8217;ll notice that there&#8217;s a score leading out of the root of this <em>subtree</em> into the rest of the tree (not shown). If this was a complete tree on its own, the root would have no score there and no arrow coming out of it.</p>
<p><strong>Finally, Parsing!</strong></p>
<p>Now that we have reviewed the depth-first post-order traversal, the Newick format and how to interpret it; we can move onto parsing these things. In parsing, we hope to create an in-memory structure that represents the tree. The parser I discuss assumes that the Newick format string already has had all newlines stripped, as it uses regular expressions. If your trees aren&#8217;t stored that way, just make sure that newlines are stripped before feeding it into my function. The in-memory object that&#8217;s created will have the following fields as a minimum.</p>
<ul>
<li><em>node_type</em> <strong>left</strong> &#8211; the left child of a node</li>
<li><em>node_type</em> <strong>right</strong> &#8211; the right child of a node</li>
<li><em>string_type</em> <strong>name</strong> &#8211; the name of a node (if it is a leaf)</li>
<li><em>float_type</em> <strong>score</strong> &#8211; the length of the branch coming out of the top of a given node</li>
</ul>
<p>I also use the following two fields to keep track of a few house keeping items and to make life pleasant for future tasks with this in-memory structure.</p>
<ul>
<li><em>node_type</em> <strong>parent</strong> &#8211; the parent of a node</li>
<li><em>integer_type</em> <strong>serial</strong> &#8211; the order in which this node occurs when parsed</li>
</ul>
<p>Note that in future, a depth-first post-order traversal will yield the nodes in the exact order that they were read &#8212; so in reality &#8220;this.serial&#8221; isn&#8217;t really needed, but it&#8217;s nice to have for future functions you might write as a shorthand. Have you understood why these nodes would occur in the same order?</p>
<p>Each language has its own quirks. Python and JavaScript have the advantage that you can define a class and define its properties (fields) on the fly &#8212; meaning there&#8217;s less code to download and to write, which is particularly good for blogs <img src='http://eddiema.ca/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Here&#8217;s pseudo-code for the recursive descent parsing function &#8220;tree_builder(&lt;<em>newick_string</em>&gt;)&#8221; &#8212; I don&#8217;t indicate where to strip away newlines because I assume they&#8217;re gone. I also don&#8217;t indicate where to strip away whitespace (I did previously, but that took up like half the pseudocode.) So if there&#8217;s a place where you suspect whitespace can occur, strip it away and increment the cursor by the length of that whitespace.</p>
<pre style="font-size: small;">new variable: count = 0  // can be either a global variable or given to the function as a reference
                         // keeps track of how many nodes we've seen
new variable: cursor = 0 // also either a global or a reference
                         // keeps track of where in the string we are

tree_builder(newick_string) {
    *** Look for things relating to the left child of this node ***
    if $newick_string at $cursor is '(' {
        * increment the $cursor to account for the open parenthesis
        if newick_string at cursor is '(' {
            *** Then the $left node is an internal node: requires recursion ***
            * recursive call to get node on $left side: this.left = tree_builder(newick_string)
            * doubly link the child and $parent: this.left.parent = this
        }
        * try to find a valid $name next at the current cursor position
        if a name is found {
            *** Then the $left node is a leaf node: parse the leaf data ***
            * create a new $left node
            * provide it with the discovered $name
            * assign $count to left.$serial and increment the $count
            * doubly link it with its left.$parent: this.left.parent = this
            * increment the $cursor up by the $length of the $name
        }
    }
    if $newick_string at $cursor == ':' {
        *** Always expect left branch length after descending into the left child ***
        * increment the $cursor to account for the colon
        * try to find a valid $branch_length_string (which is a floating point value)
        * this.$left.$score = branch_length_string
        * increment the $cursor up by the $length of the $branch_length_string (expressed as a string!)
    }
    *** Look for things related to the right node ***
    if $newick_string at $cursor == ',' {
        * increment the $cursor to account for the comma
        if newick_string at cursor is '(' {
            *** Then the $right node is an internal node: requires recursion ***
            * recursive call to get node on $right side: this.right = tree_builder(newick_string)
            * doubly link the child and $parent: this.rightparent = this
        }
        * try to find a valid $name next at the current cursor position
        if a name is found {
            *** Then the $right node is a leaf node: parse the leaf data ***
            * create a new $right node
            * provide it with the discovered $name
            * assign $count to right.$serial and increment the $count
            * doubly link it with its right.$parent: this.right.parent = this
            * increment the $cursor up by the $length of the $name
        }
    }
    if $newick_string at $cursor == ':' {
        *** Always expect the right branch length after descending into right child ***
        * increment the $cursor to account for the colon
        * try to find a valid $branch_length_string (which is a floating point value)
        * this.$right.$score = branch_length_string
        * increment the $cursor up by the $length of the $branch_length_string (expressed as a string!)
    }
    if $newick_string at $cursor == ')' {
        * increment the $cursor to account for the close parenthesis
    }
    *** Always expect the branch length of this very node after analyzing both its children ***
    if $newick_string at $cursor == ':') {
        * increment the $cursor to account for the colon
        * try to find a valid $branch_length_string (which is a floating point value)
        * this.$score = branch_length_string
        * increment the $cursor up by the $length of the $branch_length_string (expressed as a string!)
    }
    if $newick_string at $cursor == ';') {
        *** This case only executes for the root node-- the very last node to finish parsing ***
        * increment the $cursor to account for the semicolon (optional, keeps it consistent)
        * assign $count to this.$serial (no need to increment $count here)
    }
    *** Return node to complete an instance in recursion (internal) or a base case (leaf) ***
    * return this (not needed if you've been using JavaScript with the "new" operator all along)
}</pre>
<p>The implementation that&#8217;s included in the attached JavaScript does two things differently than the above. First, I don&#8217;t force the user to break encapsulation by declaring globals. Instead, I use an object called &#8220;ref&#8221; which has two fields, &#8220;ref.count&#8221; and &#8220;ref.cursor&#8221;. The name &#8220;ref&#8221; is chosen to remind us that <em>its fields are passed by reference</em>. This is possible because the object &#8220;ref&#8221; itself is passed by reference (I could have called it anything, but I chose a name that suited its purpose). Imagine trying to pass &#8220;count&#8221; and &#8220;cursor&#8221; in this recursive function without an enclosing object &#8212; what would happen instead is that the value wouldn&#8217;t be updated, instead the integer values would be copied and modified locally in the span of single function instances. The &#8220;ref&#8221; object is passed as an argument to the &#8220;_tree_builder(&lt;<em>ref</em>&gt;, &lt;<em>newick_string</em>&gt;)&#8221; function internally where it is instantiated if &#8220;null&#8221; is passed in the place of &#8220;ref&#8221;. The calling user doesn&#8217;t even need to know about it, as it&#8217;s all wrapped together in a pretty package and the user just calls &#8220;tree_builder(&lt;<em>newick_string</em>&gt;)&#8221; as before &#8212; without the need for globals.</p>
<p>Finally, there is a traversal function, and an expose function. The traversal function returns the node objects in an array following in the natural depth-first post-order described previously. The expose function is a debugging function which writes the output using &#8220;thoughts_write(&lt;<em>message</em>&gt;)&#8221; which wraps &#8220;document.write(&lt;<em>message</em>&gt;)&#8221;. You can change &#8220;thoughts_write(&lt;<em>message</em>&gt;)&#8221; to print output elsewhere using &#8220;document.getElementById(&lt;<em>some_identity</em>&gt;).innerHTML += (&lt;<em>message</em>&gt;)&#8221; where &#8220;some_identity&#8221; is the &#8220;id&#8221; of some element in your HTML. Without going into detail, the traversal function also uses an internal &#8220;ref&#8221; object which refers to the array as it is filled.</p>
<p><strong>Some other things you can try&#8230;</strong></p>
<p>The JavaScript recursive descent parser is actually a simplified version of something that I threw together earlier. The major difference is that I tag leaf nodes with <em><strong>fasta</strong></em> protein sequences by passing a reference to an associative array (or hash) as an argument to &#8220;tree_builder(&lt;<em>newick_string</em>&gt;, &lt;<em>fasta_hash</em>&gt;)&#8221;. Remember, in JavaScript, an associative array is an instance of an Object, not an instance of an Array. <em>Using non-integer field names in an Array is actually not well defined</em> but kind of sort of works semi-consistently between browsers (i.e. don&#8217;t try!), but that&#8217;s a story for another day. Whenever the name of a leaf is parsed, I would look it up in the hash and put it in a field either &#8220;this.left.fasta&#8221; or &#8220;this.right.fasta&#8221; thereby conferring to the leaf nodes of the in-memory structure the appropriate fasta protein sequence.</p>
<p><strong>Lessons Learned</strong></p>
<p>In putting this thing together, I managed to relearn JS, recursive descent parsing and making JS pass things by reference up and down a recursive stack of function calls. <a href="http://www.masella.name/">Andre Masella</a> helpfully reminded me that I didn&#8217;t need to use any kind of BNF or LALR(1) parser &#8212; just an easy single-function parser would do. This is actually a port of a C# parser which does the same thing that I wrote in an earlier step for phylogenetic analysis &#8212; the difference being that C# offers a &#8220;ref&#8221; keyword that allows one to specify arguments in a function&#8217;s parameter list as emulated references (functionally equivalent to using C&#8217;s asterisk and ampersand convention though not operationally equivalent).</p>
<p>Happy parsing! The code presented should be easy enough to understand for you to port it into the language of your choice for whatever purposes you design.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/25/parsing-a-newick-tree-with-recursive-descent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL mangling for HTML forms (a better Mediawiki search box)</title>
		<link>http://eddiema.ca/2010/06/04/url-mangling-for-html-forms-a-better-mediawiki-search-box/</link>
		<comments>http://eddiema.ca/2010/06/04/url-mangling-for-html-forms-a-better-mediawiki-search-box/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 12:39:45 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[hidden type input]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[mediawiki]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1674</guid>
		<description><![CDATA[Followup: This is better than my previous Mediawiki search box solution because it doesn&#8217;t require an extra PHP file (search-redirect.php) to deploy. It relies completely on URL mangling inside the HTML form on the page you are putting the search box. Previous post here. A valid HTML form input type is &#8220;hidden&#8221;. What this means [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Followup: </strong></em>This is better than my previous Mediawiki search box solution because it doesn&#8217;t require an extra PHP file (search-redirect.php) to deploy. It relies completely on URL mangling inside the HTML form on the page you are putting the search box. <a href="http://eddiema.ca/2010/06/03/add-an-arbitrary-mediawiki-search-box-anywhere/">Previous post here</a>.</p>
<p>A valid HTML form input type is &#8220;hidden&#8221;. What this means is that a variable can be set without a control displayed for it in a form. Other input types for instance are &#8220;text&#8221; for a line of text and &#8220;submit&#8221; for the proverbial submit button &#8212; both of these input types are displayed. Variables set by the &#8220;hidden&#8221; input type are treated as normal and are shipped off via the GET or POST method that you&#8217;ve chosen for the whole html form&#8230;</p>
<p>So, to create the following mangled URL&#8230;</p>
<pre>http://eddiema.ca/wiki/index.php?title=Special%3ASearch&amp;search=<span style="text-decoration: underline;">searchterms</span>&amp;go=Go</pre>
<p>There are the following variables &#8230; with the following values:</p>
<ul>
<li><span style="font-family: courier new,courier;">title &#8230; &#8220;Special%3ASearch&#8221; (%3A is the HTML entity &#8220;:&#8221;)<br />
</span></li>
<li><span style="font-family: courier new,courier;">search &#8230; &#8220;<span style="text-decoration: underline;">searchterms</span>&#8221; (the only variable requiring user input)<br />
</span></li>
<li><span style="font-family: courier new,courier;">go &#8230; &#8220;Go&#8221;<br />
</span></li>
</ul>
<p>The only variable that needs to be assigned from the form is &#8220;search&#8221; to which I&#8217;ve assigned the placeholder &#8220;searchterms&#8221; in the above URL.</p>
<p>The form thus needs only to take input for the variable &#8220;search&#8221; with a &#8220;text&#8221; type input, while &#8220;title&#8221; and &#8220;go&#8221; are already assigned&#8211; a job for the &#8220;hidden&#8221; type input.</p>
<p>Here&#8217;s what the simplest form for this would look like&#8230;</p>
<pre>&lt;form action="http://eddiema.ca/wiki/index.php" method="get"&gt;
Search Ed's Wiki Notebook:
&lt;input name="title" type="hidden" value="Special:Search" /&gt;
&lt;input name="search" type="text" value="" /&gt;
&lt;input name="go" type="hidden" value="Go" /&gt;
&lt;input type="submit" value="Search" /&gt;
&lt;/form&gt;</pre>
<p>Again, replace the text &#8220;Search Ed&#8217;s Wiki Notebook&#8221; with your own description and replace &#8220;http://eddiema.ca/wiki/index.php&#8221; with the form handler that you&#8217;re using&#8211; it&#8217;ll either be a bare domain, subdomain or could end with index.php if it&#8217;s a Mediawiki installation.</p>
<p>And that&#8217;s it! A far simpler solution than last time with the use of the &#8220;hidden&#8221; type input to assist in URL mangling.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/04/url-mangling-for-html-forms-a-better-mediawiki-search-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add an arbitrary Mediawiki search box anywhere!</title>
		<link>http://eddiema.ca/2010/06/03/add-an-arbitrary-mediawiki-search-box-anywhere/</link>
		<comments>http://eddiema.ca/2010/06/03/add-an-arbitrary-mediawiki-search-box-anywhere/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 13:54:10 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[search box]]></category>
		<category><![CDATA[search-redirect.php]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1659</guid>
		<description><![CDATA[Update: A better solution that doesn&#8217;t require a separate &#8220;search-redirect.php&#8221; file has been posted here. I&#8217;ve been looking for this solution for a long time now and I&#8217;m happy to have finally found it. Following hints from Dave Taylor and Peter De Decker, I&#8217;ve glued together a solution that doesn&#8217;t take too much effort and [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong></em> A better solution that doesn&#8217;t require a separate &#8220;search-redirect.php&#8221; file <a href="http://eddiema.ca/2010/06/04/url-mangling-for-html-forms-a-better-mediawiki-search-box/">has been posted here</a>.</p>
<p>I&#8217;ve been looking for this solution for a long time now and I&#8217;m happy to have finally found it. Following hints from <a href="http://www.askdavetaylor.com/add_wikipedia_search_box_to_my_web_site_or_blog.html">Dave Taylor</a> and <a href="http://letconex.blogspot.com/2009/11/add-wikipedia-search-box-for-your-main.html">Peter De Decker</a>, I&#8217;ve glued together a solution that doesn&#8217;t take too much effort and doesn&#8217;t require any additional hacking around in SQL.</p>
<p>The objective was to add a search box on the right-column navigation of this blog that would search my wiki notebook. It wasn&#8217;t until I stumbled on the above two blogs that I realized I can just mangle URLs to conduct a search on mediawikis! The specific URL used to search my wiki looks a little like this&#8230;</p>
<pre>http://eddiema.ca/wiki/index.php?title=Special%3ASearch&amp;search=<span style="text-decoration: underline;">searchterms</span>&amp;go=Go</pre>
<p>It might be a bit different for your installation depending on the version that you installed and a few of your settings&#8211; to find out what it looks like, search for something and copy down the URL in the address bar.</p>
<p>The file &#8220;search-redirect.php&#8221; used by Wikipedia takes in your search terms, and mangles those terms into a URL conforming to the above example. It then redirects you to that constructed URL. You can find this used on the main page of Wikipedia as noted by Dave.</p>
<p>My search-redirect.php based on Peter&#8217;s work above is two lines long, and looks like this:</p>
<pre>&lt;php?
$redirect_url =
     "http://eddiema.ca/wiki/index.php?title=Special%3ASearch&amp;search=".
     $_GET['search'].
     "&amp;go=Go";
@header( "Location: ".$redirect_url );
?&gt;</pre>
<p>You probably want to place your own search-redirect.php in the root directory of your wiki installation&#8211; however, it looks to me like it doesn&#8217;t really matter since the whole URL is rewritten anyway. I bet you can put this file anywhere on the net that supports PHP. The final thing that&#8217;s missing is the search box&#8211; anything that uses this formula will work:</p>
<pre>&lt;form action="http://eddiema.ca/wiki/search-redirect.php" method="get"&gt;
Search Ed's Wiki:
&lt;input type="text" name="search" /&gt;
&lt;input type="submit" value="Search" /&gt;
&lt;/form&gt;</pre>
<p>Putting this code on a page with your own wiki URL as a stem instead of mine will allow you to search your own wiki from any other page.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/03/add-an-arbitrary-mediawiki-search-box-anywhere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DSL Infrastructure Problems?</title>
		<link>http://eddiema.ca/2010/06/03/dsl-infrastructure-problems/</link>
		<comments>http://eddiema.ca/2010/06/03/dsl-infrastructure-problems/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 11:44:52 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Bell]]></category>
		<category><![CDATA[Distributel]]></category>
		<category><![CDATA[DSL]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1652</guid>
		<description><![CDATA[My phone line was apparently struck with some kind of plague at 4am on June 2nd. Here&#8217;s a result from speedtest.net showing the speed before the problem and the speed now. Note that I had zero connectivity until last night. The Bell technician&#8217;s been called in and hopefully they can sort this all out. I [...]]]></description>
			<content:encoded><![CDATA[<p>My phone line was apparently struck with some kind of plague at 4am on June 2nd.</p>
<p>Here&#8217;s a result from <a href="http://speedtest.net">speedtest.net</a> showing the speed before the problem and the speed now.</p>
<p>Note that I had zero connectivity until last night. The Bell technician&#8217;s been called in and hopefully they can sort this all out. I do like Distributel after all (I&#8217;m totally looking forward to seeing a technician with my swollen wisdom detoothed face)&#8230;</p>
<table border="0">
<tbody>
<tr>
<td><img class="aligncenter size-full wp-image-1653" title="distributelBefore" src="http://eddiema.ca/wp-content/uploads/2010/06/distributelBefore.png" alt="" width="300" height="135" /></td>
<td><img class="aligncenter size-full wp-image-1654" title="distributelAfter" src="http://eddiema.ca/wp-content/uploads/2010/06/distributelAfter.png" alt="" width="300" height="135" /></td>
</tr>
</tbody>
</table>
<p>Note that the only difference is the download speed. It&#8217;s a whole new strange kind of asymmetrical DSL.</p>
<p><strong><em>Update: </em></strong>Not as great as before, but bearable&#8230; I suppose the DSL is officially &#8220;fixed&#8221;.</p>
<p style="text-align: center;"><img class="size-full wp-image-1668 aligncenter" title="835684474" src="http://eddiema.ca/wp-content/uploads/2010/06/835684474.png" alt="" width="300" height="135" /></p>
<p style="text-align: left;">I wonder if this neighbourhood will ever see ~1.5 Mb/s again.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/03/dsl-infrastructure-problems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Chess Post &#8211; S-Chess and Omega Chess</title>
		<link>http://eddiema.ca/2010/06/02/a-chess-post-s-chess-and-omega-chess/</link>
		<comments>http://eddiema.ca/2010/06/02/a-chess-post-s-chess-and-omega-chess/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 02:47:49 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Chess]]></category>
		<category><![CDATA[Chess Variants]]></category>
		<category><![CDATA[Omega Chess]]></category>
		<category><![CDATA[Seirawan Chess]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1535</guid>
		<description><![CDATA[Update: A link for Omega Chess, and a link for Seirawan Chess. This is the first of a few posts I&#8217;d like to make about chess. In particular, this post is about two chess variants. Seirawan Chess (S-Chess) and Omega Chess. These two variants feature the familiar FIDE chess pieces along with two new pieces [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong></em> A link for <a href="http://www.omegachess.com">Omega Chess</a>, and a link for <a href="http://www.seirawanchess.com/">Seirawan Chess</a>.</p>
<p>This is the first of a few posts I&#8217;d like to make about chess. In particular, this post is about two chess variants. Seirawan Chess (S-Chess) and Omega Chess. These two variants feature the familiar FIDE chess pieces along with two new pieces each. I&#8217;ll introduce each variant on their own first.</p>
<p>In Seirawan Chess, one starts with the familiar eight-by-eight board and opening array with the addition of two pieces set aside in reserve. These pieces are the Hawk and the Elephant. The Hawk is a Bishop and Knight compound while the Elephant is a Rook and Knight compound (a compound is a combination of pieces&#8211; a Queen is a Rook and Bishop compound). The two pieces that are set aside are placed onto the board when a player moves a piece from the back rank. The piece being dropped onto the board thus occupies the square in the back rank that has just been vacated. One can only place a single reserved piece in a given move. During a castle if the player so chooses, a reserved piece may be dropped on either the King&#8217;s or the Rook&#8217;s original square; it is not permitted to drop both reserved pieces during a castle.</p>
<p>In Omega Chess, one starts with a ten-by-ten board and an opening array that is flanked by the addition of a Champion and the Champion&#8217;s Pawn. The board is also extended diagonally by a single square in each of the four corners&#8211; these corner squares are occupied by a Wizard each. In the opening array, each piece is placed behind a Pawn with the exception of the Wizard. The Champion may move one step orthogonally, leap two steps orthogonally or leap two steps diagonally. The Wizard may move one step diagonally or leap (1, 3) &#8212; whereas a Knight leaps (1, 2). The Wizard is hence colour bound. The special corner Wizard squares are not actually special&#8211; they are just part of the board topology and can be used by all other pieces (except the Rook which cannot leap or slide diagonally into those spots).</p>
<p>For the fun of it, I have been playing Omega Chess with Seirawan Chess dropped pieces and it&#8217;s worked quite well so far. The size of the board accommodates well the Seirawan compounds. Additionally, I have been considering a house rule about dropping the Seirawan pieces&#8211; perhaps it shouldn&#8217;t be allowed that a dropped piece immediately defend the piece that dropped it. For instance, a Bishop dropping a Hawk makes for a very tough defense. A Wizard dropping a Hawk should be allowed however if the Wizard made its oblong (1, 3) leap.</p>
<p>If you see me walking around with a big black tube, I&#8217;m probably carrying this chess set. Challenge me to a game <img src='http://eddiema.ca/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I&#8217;ll post some photos and such soon. The design of all the pieces from both sets is remarkably soothing and fits very well into the Staunton style. I was very lucky to discover that the Seirawan pieces are each appropriately tall compared to the Queen of the Omega Chess set I purchased.</p>
<p>One final thing&#8211; I decided to score the pieces in this combined game based on the mobility of each of the pieces on the ten-by-ten board. Here are my findings&#8230;</p>
<table border="0">
<tbody>
<tr>
<td style="width: 80px; text-align: left;"><strong><span style="font-size: small;"><span style="font-family: courier new,courier;">Score</span></span></strong></td>
<td style="width: 80px;"><strong><span style="font-size: small;"><span style="font-family: courier new,courier;">Piece</span></span></strong></td>
<td style="width: 80px;"><strong><span style="font-size: small;"><span style="font-family: courier new,courier;">Remark</span></span></strong></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">29.40</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Queen</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">FIDE</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">23.76</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Elephant</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Seirawan</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">18.00</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Rook</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">FIDE</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">17.16</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Hawk</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Seirawan</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">11.40</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Bishop</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">FIDE</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">9.36</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Champion</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Omega</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">8.28</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Wizard</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Omega</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">6.84</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">King</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">FIDE</span></span></td>
</tr>
<tr>
<td style="text-align: left;"><span style="font-size: small;"><span style="font-family: courier new,courier;">5.76</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">Knight</span></span></td>
<td><span style="font-size: small;"><span style="font-family: courier new,courier;">FIDE</span></span></td>
</tr>
</tbody>
</table>
<p>The score is proportional to the total number of squares controlled by a piece calculated for every square it can occupy in the ten-by-ten grid. Aside from giving a general impression of how one would rank a piece against other pieces, there&#8217;s not really a lot that one can tell from this scheme. In this scheme, the Seirawan pieces rank high, and the Omega pieces rank low but only due to their finite ranges. Leapers&#8217; attacks have the distinct advantage of being immune to blocking.</p>
<p>That&#8217;s all for now, back to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/06/02/a-chess-post-s-chess-and-omega-chess/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Brief: Absent until May 17.</title>
		<link>http://eddiema.ca/2010/05/05/brief-absent-until-may-17/</link>
		<comments>http://eddiema.ca/2010/05/05/brief-absent-until-may-17/#comments</comments>
		<pubDate>Wed, 05 May 2010 12:33:28 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[People]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[iGEM Synthetic Bio]]></category>
		<category><![CDATA[Absence]]></category>

		<guid isPermaLink="false">http://eddiema.ca/?p=1599</guid>
		<description><![CDATA[Brief: I will be indisposed until May 17.]]></description>
			<content:encoded><![CDATA[<p><em><strong>Brief: </strong></em>I will be indisposed until May 17.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/2010/05/05/brief-absent-until-may-17/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
