<?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>生信菜鸟团 &#187; tally</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/tally/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>Bowtie算法第六讲-tally法对bwt索引进行搜索</title>
		<link>http://www.bio-info-trainee.com/650.html</link>
		<comments>http://www.bio-info-trainee.com/650.html#comments</comments>
		<pubDate>Sat, 18 Apr 2015 14:46:04 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[bowtie]]></category>
		<category><![CDATA[bwt]]></category>
		<category><![CDATA[tally]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=650</guid>
		<description><![CDATA[因为要讲搜索，所以我选择了一个长一点的字符串来演示多种情况的搜索 perl ro &#8230; <a href="http://www.bio-info-trainee.com/650.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>因为要讲搜索，所以我选择了一个长一点的字符串来演示多种情况的搜索</p>
<p>perl rotation_one_by_one.pl atgtgtcgtagctcgtnncgt</p>
<p>程序运行的结果如下</p>
<p>$ATGTGTCGTAGCTCGTNNCGT 21</p>
<p>AGCTCGTNNCGT$ATGTGTCGT 9</p>
<p>ATGTGTCGTAGCTCGTNNCGT$ 0</p>
<p>CGT$ATGTGTCGTAGCTCGTNN 18</p>
<p>CGTAGCTCGTNNCGT$ATGTGT 6</p>
<p>CGTNNCGT$ATGTGTCGTAGCT 13</p>
<p>CTCGTNNCGT$ATGTGTCGTAG 11</p>
<p>GCTCGTNNCGT$ATGTGTCGTA 10</p>
<p>GT$ATGTGTCGTAGCTCGTNNC 19</p>
<p>GTAGCTCGTNNCGT$ATGTGTC 7</p>
<p>GTCGTAGCTCGTNNCGT$ATGT 4</p>
<p>GTGTCGTAGCTCGTNNCGT$AT 2</p>
<p>GTNNCGT$ATGTGTCGTAGCTC 14</p>
<p>NCGT$ATGTGTCGTAGCTCGTN 17</p>
<p>NNCGT$ATGTGTCGTAGCTCGT 16</p>
<p>T$ATGTGTCGTAGCTCGTNNCG 20</p>
<p>TAGCTCGTNNCGT$ATGTGTCG 8</p>
<p>TCGTAGCTCGTNNCGT$ATGTG 5</p>
<p>TCGTNNCGT$ATGTGTCGTAGC 12</p>
<p>TGTCGTAGCTCGTNNCGT$ATG 3</p>
<p>TGTGTCGTAGCTCGTNNCGT$A 1</p>
<p>TNNCGT$ATGTGTCGTAGCTCG 15</p>
<p>它的BWT及索引是</p>
<p>T 21</p>
<p>T 9</p>
<p>$ 0</p>
<p>N 18</p>
<p>T 6</p>
<p>T 13</p>
<p>G 11</p>
<p>A 10</p>
<p>C 19</p>
<p>C 7</p>
<p>T 4</p>
<p>T 2</p>
<p>C 14</p>
<p>N 17</p>
<p>T 16</p>
<p>G 20</p>
<p>G 8</p>
<p>G 5</p>
<p>C 12</p>
<p>G 3</p>
<p>A 1</p>
<p>G 15</p>
<p>然后得到它的tally文件如下</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/04/图片1.png"><img class="alignnone size-full wp-image-651" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/04/图片1.png" alt="图片1" width="418" height="423" /></a></p>
<p>接下来用我们的perl程序在里面找字符串</p>
<p>第一次我测试 GTGTCG 这个字符串，程序可以很清楚的看到它的查找过程。</p>
<p>perl search_char.pl    GTGTCG   tm.tally</p>
<p>your last char is G</p>
<p>start is 7 ; and end is 13</p>
<p>now it is number 5 and the char is C</p>
<p>start is 3 ; and end is 6</p>
<p>now it is number 4 and the char is T</p>
<p>start is 17 ; and end is 19</p>
<p>now it is number 3 and the char is G</p>
<p>start is 10 ; and end is 11</p>
<p>now it is number 2 and the char is T</p>
<p>start is 19 ; and end is 20</p>
<p>now it is number 1 and the char is G</p>
<p>start is 11 ; and end is 12</p>
<p>It is just one perfect match !</p>
<p>The index is 2</p>
<p>第二次我测试一个多重匹配的字符串GT，在原字符串出现了五次的</p>
<p>perl search_char.pl  GT  tm.tally</p>
<p>your last char is T</p>
<p>start is 15 ; and end is 22</p>
<p>now it is number 1 and the char is G</p>
<p>start is 8 ; and end is 13</p>
<p>we find more than one perfect match!!!</p>
<p>8 13</p>
<p>One of the index is 11</p>
<p>One of the index is 10</p>
<p>One of the index is 19</p>
<p>One of the index is 7</p>
<p>One of the index is 4</p>
<p>One of the index is 2</p>
<p>One of the index is 14</p>
<p>惨了，这个是很严重的bug，不知道为什么，对于多个匹配总是会多出那么一点点的结果。</p>
<p>去转换矩阵里面查看，可知，前面两个结果11和10是错误的。</p>
<p>CTCGTNNCGT$ATGTGTCGTAG 11</p>
<p>GCTCGTNNCGT$ATGTGTCGTA 10</p>
<p>GT$ATGTGTCGTAGCTCGTNNC 19</p>
<p>GTAGCTCGTNNCGT$ATGTGTC 7</p>
<p>GTCGTAGCTCGTNNCGT$ATGT 4</p>
<p>GTGTCGTAGCTCGTNNCGT$AT 2</p>
<p>GTNNCGT$ATGTGTCGTAGCTC 14</p>
<p>最后我们测试未知字符串的查找。</p>
<p>perl search_char.pl ACATGTGT tm.tally</p>
<p>your last char is T</p>
<p>start is 15 ; and end is 22</p>
<p>now it is number 7 and the char is G</p>
<p>start is 8 ; and end is 13</p>
<p>now it is number 6 and the char is T</p>
<p>start is 19 ; and end is 21</p>
<p>now it is number 5 and the char is G</p>
<p>start is 11 ; and end is 12</p>
<p>now it is number 4 and the char is T</p>
<p>start is 20 ; and end is 21</p>
<p>now it is number 3 and the char is A</p>
<p>start is 2 ; and end is 3</p>
<p>now it is number 2 and the char is C</p>
<p>start is 3 ; and end is 3</p>
<p>we can just find the last 6 char ,and it is ATGTGT</p>
<p>原始字符串是ATGTGTCGTAGCTCGTNNCGT，所以查找的挺对的！！！</p>
<p>&nbsp;</p>
<p>[perl]</p>
<p>$a=$ARGV[0];</p>
<p>$a=uc $a;</p>
<p>open FH,&quot;&lt;$ARGV[1]&quot;;</p>
<p>while(&lt;FH&gt;){</p>
<p>chomp;</p>
<p>@F=split;</p>
<p>$hash_count_atcg{$F[0]}++;</p>
<p>$hash{$.}=$_;</p>
<p># the first line is $ and the last char and the last index !</p>
<p>}</p>
<p>$all_a=$hash_count_atcg{'A'};</p>
<p>$all_c=$hash_count_atcg{'C'};</p>
<p>$all_g=$hash_count_atcg{'G'};</p>
<p>$all_n=$hash_count_atcg{'N'};</p>
<p>$all_t=$hash_count_atcg{'T'};</p>
<p>#print &quot;$all_a\t$all_c\t$all_g\t$all_t\n&quot;;</p>
<p>$len_a=length $a;</p>
<p>$end_a=$len_a-1;</p>
<p>#print &quot;your query is $a\n&quot;;</p>
<p>#print &quot;and the length of your query is $len_a \n&quot;;</p>
<p>$after=substr($a,$end_a,1);</p>
<p>#we fill search your query from the last char !</p>
<p>if ($after eq 'A') {</p>
<p>$start=2;</p>
<p>$end=$all_a+1;</p>
<p>}</p>
<p>elsif ($after eq 'C') {</p>
<p>$start=$all_a+1;</p>
<p>$end=$all_a+$all_c+1;</p>
<p>}</p>
<p>elsif ($after eq 'G') {</p>
<p>$start=$all_a+$all_c+1;</p>
<p>$end=$all_a+$all_c+$all_g+1;</p>
<p>}</p>
<p>elsif ($after eq 'T'){</p>
<p>$start=$all_a+$all_c+$all_g+$all_n+1;</p>
<p>$end=$all_a+$all_c+$all_g+$all_t+$all_n+1;</p>
<p>}</p>
<p>else {die &quot;error !!! we just need A T C G !!!\n&quot;}</p>
<p>print &quot;your last char is $after\n &quot;;</p>
<p>print &quot;start is $start ; and end is $end \n&quot;;</p>
<p>foreach (reverse (1..$end_a)){</p>
<p>$after=substr($a,$_,1);</p>
<p>$before=substr($a,$_-1,1);</p>
<p>($start,$end)=&amp;find_level($after,$before,$start,$end);</p>
<p>print &quot;now it is number $_ and the char is $before \n &quot;;</p>
<p>print &quot;start is $start ; and end is $end \n&quot;;</p>
<p>if ($_  &gt; 1 &amp;&amp; $start == $end) {</p>
<p>$find_char=substr($a,$_);</p>
<p>$find_len=length $find_char;</p>
<p>print &quot;we can just find the last $find_len char ,and it is $find_char \n&quot;;</p>
<p>#return &quot;miss&quot;;</p>
<p>last;</p>
<p>}</p>
<p>if ($_ == 1) {</p>
<p>if (($end-$start)==1) {</p>
<p>print &quot;It is just one perfect match ! \n&quot;;</p>
<p>my @F_start=split/\s+/,$hash{$end};</p>
<p>print &quot;The index is $F_start[1]\n&quot;;</p>
<p>#return $F_start[1];</p>
<p>last;</p>
<p>}</p>
<p>else {</p>
<p>print &quot;we find more than one perfect match!!!\n&quot;;</p>
<p>print &quot;$start\t$end\n&quot;;</p>
<p>foreach  (($start-1)..$end) {</p>
<p>my @F_start=split/\s+/,$hash{$_};</p>
<p>print &quot;One of the index is $F_start[1]\n&quot;;</p>
<p>}</p>
<p>#return &quot;multiple&quot;;</p>
<p>last;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>sub find_level{</p>
<p>my($after,$before,$start,$end)=@_;</p>
<p>my @F_start=split/\s+/,$hash{$start};</p>
<p>my @F_end=split/\s+/,$hash{$end};</p>
<p>if ($before eq 'A') {</p>
<p>return ($F_start[2]+1,$F_end[2]+1);</p>
<p>}</p>
<p>elsif ($before eq 'C') {</p>
<p>return ($all_a+$F_start[3]+1,$all_a+$F_end[3]+1);</p>
<p>}</p>
<p>elsif ($before eq 'G') {</p>
<p>return ($all_a+$all_c+1+$F_start[4],$all_a+$all_c+1+$F_end[4]);</p>
<p>}</p>
<p>elsif ($before eq 'T') {</p>
<p>return ($all_a+$all_c+$all_g+$all_n+1+$F_start[5],$all_a+$all_c+$all_g+1+$all_n+$F_end[5]);</p>
<p>}</p>
<p>else {die &quot;error !!! we just need A T C G !!!\n&quot;}</p>
<p>}</p>
<p>[/perl]</p>
<p>&nbsp;</p>
<p>原始字符串是atgtgtcgtagctcgtnncgt</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/650.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bowtie算法第五讲-index2tally</title>
		<link>http://www.bio-info-trainee.com/648.html</link>
		<comments>http://www.bio-info-trainee.com/648.html#comments</comments>
		<pubDate>Sat, 18 Apr 2015 14:02:47 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[生信基础]]></category>
		<category><![CDATA[bwt]]></category>
		<category><![CDATA[tally]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=648</guid>
		<description><![CDATA[前面讲到了如何用笨方法进行字符串搜索，也讲了如何构建bwt索引，和把bwt索引还 &#8230; <a href="http://www.bio-info-trainee.com/648.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>前面讲到了如何用笨方法进行字符串搜索，也讲了如何构建bwt索引，和把bwt索引还原成字符串！</p>
<p>原始字符串是ATGCGTANNGTC</p>
<p>排序过程是下面的</p>
<p>$ATGCGTANNGTC 12</p>
<p>ANNGTC$ATGCGT 6</p>
<p>ATGCGTANNGTC$ 0</p>
<p>C$ATGCGTANNGT 11</p>
<p>CGTANNGTC$ATG 3</p>
<p>GCGTANNGTC$AT 2</p>
<p>GTANNGTC$ATGC 4</p>
<p>GTC$ATGCGTANN 9</p>
<p>NGTC$ATGCGTAN 8</p>
<p>NNGTC$ATGCGTA 7</p>
<p>TANNGTC$ATGCG 5</p>
<p>TC$ATGCGTANNG 10</p>
<p>TGCGTANNGTC$A 1</p>
<p>现在讲讲如何根据bwt索引构建tally，并且用tally搜索方法来搜索字符串！</p>
<p>首先是bwt索引转换为tally</p>
<p>C 12</p>
<p>T 6</p>
<p>$ 0</p>
<p>T 11</p>
<p>G 3</p>
<p>T 2</p>
<p>C 4</p>
<p>N 9</p>
<p>N 8</p>
<p>A 7</p>
<p>G 5</p>
<p>G 10</p>
<p>A 1</p>
<p>这个其实非常简单的，tally就是增加四列计数的列即可</p>
<p>[perl]</p>
<p>$hash_count{'A'}=0;</p>
<p>$hash_count{'C'}=0;</p>
<p>$hash_count{'G'}=0;</p>
<p>$hash_count{'T'}=0;</p>
<p>open FH ,&quot;&lt;$ARGV[0]&quot;;</p>
<p>while(&lt;FH&gt;){</p>
<p>        chomp;</p>
<p> @F=split;</p>
<p> $last=$F[0]; # 读取上面的tally文件，分列，判断第一列，并计数</p>
<p>        $hash_count{$last}++;</p>
<p>   print  &quot;$_\t$hash_count{'A'}\t$hash_count{'C'}\t$hash_count{'G'}\t$hash_count{'T'}\n&quot;;</p>
<p>}</p>
<p>[/perl]</p>
<p>输出的tally如下</p>
<p>C 12 0 1 0 0</p>
<p>T 6 0 1 0 1</p>
<p>$ 0 0 1 0 1</p>
<p>T 11 0 1 0 2</p>
<p>G 3 0 1 1 2</p>
<p>T 2 0 1 1 3</p>
<p>C 4 0 2 1 3</p>
<p>N 9 0 2 1 3</p>
<p>N 8 0 2 1 3</p>
<p>A 7 1 2 1 3</p>
<p>G 5 1 2 2 3</p>
<p>G 10 1 2 3 3</p>
<p>A 1 2 2 3 3</p>
<p>接下来就是针对这个tally的查询函数了</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/648.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
