<?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; 算法</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/%e7%ae%97%e6%b3%95/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>别人写的代码运行真快！！！</title>
		<link>http://www.bio-info-trainee.com/1311.html</link>
		<comments>http://www.bio-info-trainee.com/1311.html#comments</comments>
		<pubDate>Fri, 08 Jan 2016 12:54:51 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[杂谈-随笔]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=1311</guid>
		<description><![CDATA[最近需要做十几万个差异基因分析，每个分析都是对大约5万个探针，200个样本的数据 &#8230; <a href="http://www.bio-info-trainee.com/1311.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div><span style="font-family: Times New Roman;">最近需要做十几万个差异基因分析，每个分析都是对大约5万个探针，200个样本的数据量进行批量T检验计算P值</span></div>
<div><span style="font-family: Times New Roman;">然后发现自己无论怎么用R来写，每个分析都要耗时半分钟左右，因为我必须循环所有的探针，即使不用for，而用R推荐的apply系列函数，也快不到哪里去，但是我搜索时候发现有一个package里面自带了矩阵T检验，直接对5万个探针进行T检验，而不需要循环处理它们</span></div>
<div><span style="font-family: Times New Roman;">看下面代码！</span></div>
<div><span style="font-family: Times New Roman;">dat=matrix(rnorm(10000000),nrow = 50000) </span></div>
<div><span style="font-family: Times New Roman;">dim(dat) #50000   200 </span></div>
<div><span style="font-family: Times New Roman;">system.time( </span></div>
<div><span style="font-family: Times New Roman;">  apply(dat,1,function(x){ </span></div>
<div><span style="font-family: Times New Roman;">    t.test(x[1:100],x[101:200])$p.value </span></div>
<div><span style="font-family: Times New Roman;">  }) </span></div>
<div><span style="font-family: Times New Roman;">) </span></div>
<div><span style="font-family: Times New Roman;">#用户  系统  流逝 </span></div>
<div><span style="font-family: Times New Roman;">#29.29  0.04 30.64 </span></div>
<div><span style="font-family: Times New Roman;">library(pi0) </span></div>
<div><span style="font-family: Times New Roman;">system.time(matrix.t.test(dat,1,100,100)) </span></div>
<div><span style="font-family: Times New Roman;">#用户 系统 流逝 </span></div>
<div><span style="font-family: Times New Roman;">#0.48 0.03 0.53</span></div>
<div><span style="font-family: Times New Roman;">差距真的是非常的明显呀！！！</span></div>
<div><span style="font-family: Times New Roman;">然后，我解析了它的代码，发现里面调用了C写的代码，我想这就是问题所在咯，可是他们到底怎么写，才能把速度搞这么快？？？<br />
</span></div>
<div>
<div><b><span style="color: #ff0000;">  tmp = .C("tstatistic", dat = x, n1 = n1, n2 = n2, ntests = ntests, </span></b></div>
<div><b><span style="color: #ff0000;">        MARGIN = MARGIN, pool = pool, tstat = rep(0, ntests), </span></b></div>
<div><b><span style="color: #ff0000;">        df = rep(0, ntests), PACKAGE = "pi0")</span></b></div>
<p><span style="font-family: Times New Roman;">源码在这个package的github里面可以找到，有兴趣的童鞋可以研究一下</span></div>
<div><span style="font-family: Times New Roman;"> </span></div>
<div><span style="font-family: Times New Roman;"> </span></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/1311.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>perl多重循环生成全排列精简</title>
		<link>http://www.bio-info-trainee.com/913.html</link>
		<comments>http://www.bio-info-trainee.com/913.html#comments</comments>
		<pubDate>Fri, 24 Jul 2015 10:09:02 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[全排列]]></category>
		<category><![CDATA[循环]]></category>
		<category><![CDATA[算法]]></category>
		<category><![CDATA[递归]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=913</guid>
		<description><![CDATA[我想输出ATCG四个字符，组成一个12个字符长度字符串的全排列。共4^12=16 &#8230; <a href="http://www.bio-info-trainee.com/913.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>我想输出ATCG四个字符，组成一个12个字符长度字符串的全排列。共4^12=16777216种排列，</p>
<p>AAAAAAAAAAAA</p>
<p>AAAAAAAAAAAT</p>
<p>AAAAAAAAAAAC</p>
<p>AAAAAAAAAAAG</p>
<p>AAAAAAAAAATA</p>
<p>`````````````````````````</p>
<p>按照正常的想法是通过多重循环来生成全排列，所以我写下了下面这样的代码，但是有个问题，它不支持多扩展性，如果100个全排列，那么得写一百次循环嵌套。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/07/4.png"><img class="alignnone size-full wp-image-916" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/07/4.png" alt="4" width="914" height="451" /></a></p>
<p>所以我求助了perl-china群里的高手，其中一个给了一个结合二进制的巧妙解决方案。</p>
<p>perl -le '{$a{"00"}="A";$a{"01"}="T";$a{"10"}="C";$a{"11"}="G";for(0..100){print join"",map{$a{$_}} unpack("a2"x12,sprintf("%024b\n",$_))}}'</p>
<p>AAAAAAAAAAAA</p>
<p>AAAAAAAAAAAT</p>
<p>AAAAAAAAAAAC</p>
<p>AAAAAAAAAAAG</p>
<p>AAAAAAAAAATA</p>
<p>AAAAAAAAAATT</p>
<p>AAAAAAAAAATC</p>
<p>AAAAAAAAAATG</p>
<p>AAAAAAAAAACA</p>
<p>AAAAAAAAAACT</p>
<p>AAAAAAAAAACC</p>
<p>AAAAAAAAAACG</p>
<p>AAAAAAAAAAGA</p>
<p>AAAAAAAAAAGT</p>
<p>AAAAAAAAAAGC</p>
<p>AAAAAAAAAAGG</p>
<p>AAAAAAAAATAA</p>
<p>AAAAAAAAATAT</p>
<p>这里我简单解释一下这个代码</p>
<p>perl -le '{$a=sprintf("%024b\n",1);print $a}'</p>
<p>000000000000000000000001</p>
<p>这个sprintf是根据024b的格式把我们的十进制数字转为二级制，但是补全为24位。</p>
<p>perl -le '{@a=unpack("a2"x12,sprintf("%024b\n",100));print join":", @a}'</p>
<p>00:00:00:00:00:00:00:00:01:10:01:00</p>
<p>unpack这个函数很简单，就是把二进制的数值拆分成字符串数组，两个数字组成一个字符串。</p>
<p>最后通过map把$a{"00"}="A";$a{"01"}="T";$a{"10"}="C";$a{"11"}="G";对应成hash值并且输出即可！</p>
<p>然后这个大神又提成了一个递归的办法来解决</p>
<p>[perl]</p>
<p>#!/usr/bin/perl</p>
<p>my $arr = [];</p>
<p>$arr-&gt;[$_] = 0 for (0..11);<br />
my @b = (&quot;A&quot;,&quot;C&quot;,&quot;G&quot;,&quot;T&quot;);</p>
<p>while(1){<br />
print join &quot;&quot;, map {$b[$_]} @$arr;<br />
print &quot;\n&quot;;<br />
exit unless &amp;count($arr,11);<br />
}</p>
<p>sub count {<br />
my $arr = shift;<br />
my $x = shift;</p>
<p>return 0 if $x &lt; 0;</p>
<p>if ($arr-&gt;[$x] &lt; 3){<br />
$arr-&gt;[$x]++;<br />
return 1;<br />
}</p>
<p>else{<br />
$arr-&gt;[$x] = 0;<br />
return &amp;count($arr,$x - 1);<br />
}<br />
}</p>
<p>[/perl]</p>
<p>还有另外一个大神也提成了一个递归的算法解决，算法之道还是蛮有趣的</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/07/2.jpg"><img class="alignnone size-full wp-image-915" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/07/2.jpg" alt="2" width="401" height="466" /></a></p>
<p>最后还补充一个也是计算机技巧的解决方案，也是群里的朋友提出来的。</p>
<p>[perl]</p>
<p>#!/usr/bin/perl -w</p>
<p>my @A = qw(A T G C);<br />
my $N = 12;</p>
<p>foreach my $n (0..4**$N){<br />
foreach my $index (0..$N){<br />
print $A[$n%4];<br />
$n = $n &gt;&gt;2;<br />
}<br />
print &quot;\n&quot;;<br />
}</p>
<p>[/perl]</p>
<p>这个是位运算，如果C语言基础学的好的同学很快就能看懂的。</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/913.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自己动手写bowtie第三讲：序列查询。</title>
		<link>http://www.bio-info-trainee.com/511.html</link>
		<comments>http://www.bio-info-trainee.com/511.html#comments</comments>
		<pubDate>Sat, 28 Mar 2015 02:24:31 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[bowtie]]></category>
		<category><![CDATA[bwt]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=511</guid>
		<description><![CDATA[查询需要根据前面建立的索引来做。 这是一个比较复杂的过程，我也是看了bowtie &#8230; <a href="http://www.bio-info-trainee.com/511.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>查询需要根据前面建立的索引来做。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲532.png"><img class="alignnone size-full wp-image-506" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲532.png" alt="BWT算法第二讲532" width="554" height="427" /></a></p>
<p>这是一个比较复杂的过程，我也是看了bowtie的作者的ppt才慢慢弄懂的，感觉自己也不可能三言两语就说清楚，一般都是辅助图片，动画，再经过多方交流才能慢慢理解。</p>
<p>所以大家呢，就自己去看ppt，看懂那个查询算法。（ppt及代码在我的群里面有共享，欢迎大家加群交流）</p>
<p>这里我简单讲讲我的程序</p>
<p>首先读取索引文件，统计好A,C,G,T的总数</p>
<p>然后把查询序列从最后一个字符往前面回溯。</p>
<p>我创建了一个子函数，专门来处理回溯的问题</p>
<p>每次接受四个参数（左右两端的碱基，上下的阈值），并返回两个参数（新的上下两个阈值）</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询261.png"><img class="alignnone size-full wp-image-512" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询261.png" alt="自己动手写bowtie之三序列查询261" width="554" height="225" /></a></p>
<p>大家要看懂阈值是如何更新迭代，这样动态的一个个回溯字符串，一个个迭代阈值。</p>
<p>直到四种临界情况的出现。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询477.png"><img class="alignnone size-full wp-image-513" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询477.png" alt="自己动手写bowtie之三序列查询477" width="554" height="342" /></a></p>
<p>第一是上下阈值已经相等了，但是我们还没有回溯完全，那就说明字符串只能查找后几个字符，前面还有字符是无法匹配的</p>
<p>第二种情况是上下阈值已经相等了，正巧我们也回溯到了最后一个字符串，那么我们就找到了精确匹配。</p>
<p>第三种情况是已经进行到了最后一个字符串，但是上下阈值还有差值，那么就找到了多个精确匹配点。</p>
<p>最后一种情况是各种非法字符。</p>
<p>然后我简单的测序了一下在病毒的5K基因组里面的精确匹配情况，好像效果还挺好的</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询518.png"><img class="alignnone size-full wp-image-514" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/自己动手写bowtie之三序列查询518.png" alt="自己动手写bowtie之三序列查询518" width="554" height="391" /></a></p>
<p>但是在酵母里面还有一个问题没有解决，就是取前二十个字符串排序的问题，不够精确，需要重新审视排序结果进行局部优化，可能是需要用堆排序发，具体我还得考虑一个星期，只能等下周上课再看看了，平时太忙了，基本没时间码代码。</p>
<p>这里贴上我的代码给大家看看，</p>
<p>[perl]</p>
<p>$a='CGCTATGTACTGGATGCGCTGGCAAACGAGCCTGCCGTAAG';</p>
<p>while(&lt;&gt;){</p>
<p>chomp;</p>
<p>@F=split;</p>
<p>$hash_count_atcg{$F[0]}++;</p>
<p>$hash{$.}=$_;</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_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>foreach (reverse (0..$end_a)){</p>
<p>$after=substr($a,$_,1);</p>
<p>$before=substr($a,$_-1,1);</p>
<p>#对第一个字符进行找阈值的时候，我们需要人为的定义起始点！</p>
<p>if($_ == $end_a){</p>
<p>if ($after eq 'A') {</p>
<p>$start=1;</p>
<p>$end=$all_a;</p>
<p>}</p>
<p>elsif ($after eq 'C') {</p>
<p>$start=$all_a+1;</p>
<p>$end=$all_a+$all_c;</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;</p>
<p>}</p>
<p>elsif ($after eq 'T'){</p>
<p>$start=$all_a+$all_c+$all_g+1;</p>
<p>$end=$all_a+$all_c+$all_g+$all_t;</p>
<p>}</p>
<p>else {print &quot;error !!! we just need A T C G !!!\n&quot;;exit;}</p>
<p>}</p>
<p>#如果阈值已经无法继续分割，但是字符串还未查询完</p>
<p>if ($_  &gt; 0 &amp;&amp; $start == $end) {</p>
<p>$find_char=substr($a,$_);</p>
<p>$find_len=length $find_char;</p>
<p>#这里需要修改，但是不影响完全匹配了</p>
<p>print &quot;we can just find the last $find_len char ,and it is $find_char \n&quot;;</p>
<p>exit;</p>
<p>}</p>
<p>#如果进行到了最后一个字符</p>
<p>if ($_ == 0) {</p>
<p>if ($start == $end) {</p>
<p>print &quot;It is just one perfect match ! \n&quot;;</p>
<p>my @F_start=split/\s+/,$hash{$start};</p>
<p>print &quot;The index is $F_start[1]\n&quot;;</p>
<p>exit;</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..$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>exit;</p>
<p>}</p>
<p>}</p>
<p>($start,$end)=&amp;find_level($after,$before,$start,$end);</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],$F_end[2]);</p>
<p>}</p>
<p>elsif ($before eq 'C') {</p>
<p>return ($all_a+$F_start[3],$all_a+$F_end[3]);</p>
<p>}</p>
<p>elsif ($before eq 'G') {</p>
<p>return ($all_a+$all_c+$F_start[4],$all_a+$all_c+$F_end[4]);</p>
<p>}</p>
<p>elsif ($before eq 'T') {</p>
<p>return ($all_a+$all_c+$all_g+$F_start[5],$all_a+$all_c+$all_g+$F_end[5]);</p>
<p>}</p>
<p>else {print &quot;sorry , I can't find the right match!!!\n&quot;;}</p>
<p>}</p>
<p>#perl -alne '{next if /&gt;/;$all.=$_;}END{print substr($all,308,10)}'   lambda_virus.fa </p>
<p>[/perl]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/511.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自己动手写bowtie第二讲：优化索引</title>
		<link>http://www.bio-info-trainee.com/503.html</link>
		<comments>http://www.bio-info-trainee.com/503.html#comments</comments>
		<pubDate>Sat, 28 Mar 2015 01:56:55 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[bwt]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=503</guid>
		<description><![CDATA[其中第一讲我提到了一个简单的索引产生方式，因为是课堂就半个小时想的，很多细节没有 &#8230; <a href="http://www.bio-info-trainee.com/503.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲192.png"><img class="alignnone size-full wp-image-504" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲192.png" alt="BWT算法第二讲192" width="437" height="368" /></a></p>
<p>其中第一讲我提到了一个简单的索引产生方式，因为是课堂就半个小时想的，很多细节没有考虑到，对病毒那种几K大小的基因组来说是很简单的，速度也非常快，但是我测试了一下酵母，却发现好几个小时都没有结果，我只好kill掉重新改写算法，我发现之前的测序最大的问题在于没有立即substr函数的实现方式，把一个5M的字符串不停的截取首尾字符串好像是一个非常慢的方式。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲241.png"><img class="alignnone size-full wp-image-505" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲241.png" alt="BWT算法第二讲241" width="554" height="621" /></a></p>
<p>所以我优化了那个字符串的函数，虽然代码量变多了，实现过程也繁琐了一点，但是速度提升了几千倍。</p>
<p>&nbsp;</p>
<p>time perl bwt_new_index.pl e-coli.fa &gt;e-coli.index</p>
<p>测试了一下我的脚本，对酵母这样的5M的基因组，索引耗费时间是43秒</p>
<p>real 0m43.071s</p>
<p>user 0m41.277s</p>
<p>sys 0m1.779s</p>
<p>输出的index矩阵如下，我简单的截取头尾各10行给大家看，一点要看懂这个index。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲532.png"><img class="alignnone size-full wp-image-506" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/BWT算法第二讲532.png" alt="BWT算法第二讲532" width="554" height="427" /></a></p>
<p>首先第一列就是我们的BWT向量，也就是BWT变换后的尾字符</p>
<p>第二列是之前的顺序被BWT变换后的首字符排序后的打乱的顺序。</p>
<p>第三，四，五，六列分别是A,C,G,T的计数，就是在当行之前累积出现的A,C,G,T的数量，是对第一列的统计。</p>
<p>&nbsp;</p>
<p>这个索引文件将会用于下一步的查询，这里贴上我新的索引代码，查询见下一篇文章</p>
<p>[perl]</p>
<p>while (&lt;&gt;){</p>
<p>        next if /&gt;/;</p>
<p>        chomp;</p>
<p>        $a.=$_;</p>
<p>}</p>
<p>$len=length $a;</p>
<p>open FH_F,&quot;&gt;tmp_forward.txt&quot;;</p>
<p>open FH_R,&quot;&gt;tmp_reverse.txt&quot;;</p>
<p>for(my $i=0;$i&lt;=$len-1;$i+=20){</p>
<p>        print FH_F  substr($a,$i,20);</p>
<p>        print FH_F &quot;\n&quot;;</p>
<p>}</p>
<p>$rev_a=reverse $a;</p>
<p>for(my $i=0;$i&lt;=$len-1;$i+=20){</p>
<p>        print FH_R  substr($rev_a,$i,20);</p>
<p>        print FH_R &quot;\n&quot;;</p>
<p>}</p>
<p>close FH_F;</p>
<p>close FH_R;</p>
<p>$a='';</p>
<p>open FH_F,&quot;tmp_forward.txt&quot;;</p>
<p>open FH_R,&quot;tmp_reverse.txt&quot;;</p>
<p>#把前一行的所有20bp碱基当做后一行的头部信息</p>
<p>$residue_F=&lt;FH_F&gt;;</p>
<p>$residue_R=&lt;FH_R&gt;;</p>
<p>$i=0;</p>
<p>while  ($F_reads=&lt;FH_F&gt;){</p>
<p>        $R_reads=&lt;FH_R&gt;;</p>
<p>        $F_merge=$residue_F.$F_reads;</p>
<p>        $R_merge=$residue_R.$R_reads;</p>
<p>#这样每次就需要处理20个碱基</p>
<p>foreach  (0..19) {</p>
<p>$up  =substr($F_merge,$_,20);</p>
<p>                        $down=substr($R_merge,$_,1);</p>
<p>                        $hash{&quot;$up\t$down&quot;}=$i;</p>
<p>                        $i++;</p>
<p>}</p>
<p>#处理完毕之后再保存当行的20bp碱基做下一行的头部信息</p>
<p>$residue_F=$F_reads;</p>
<p>$residue_R=$R_reads;</p>
<p>}</p>
<p>#print &quot;then we sort it\n&quot;;</p>
<p>$count_a=0;</p>
<p>$count_c=0;</p>
<p>$count_g=0;</p>
<p>$count_t=0;</p>
<p>foreach  (sort keys  %hash){</p>
<p>$first=substr($_,0,1);</p>
<p>$len=length;</p>
<p>$last=substr($_,$len-1,1);</p>
<p>#print &quot;$first\t$last\t$hash{$_}\n&quot;;</p>
<p>$count_a++ if $last eq 'A';</p>
<p>$count_c++ if $last eq 'C';</p>
<p>$count_g++ if $last eq 'G';</p>
<p>$count_t++ if $last eq 'T';</p>
<p>print &quot;$last\t$hash{$_}\t$count_a\t$count_c\t$count_g\t$count_t\n&quot;;</p>
<p>}</p>
<p>unlink(&quot;tmp_forward.txt&quot;);</p>
<p>unlink(&quot;tmp_reverse.txt&quot;);</p>
<p>[/perl]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/503.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
