免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3840 | 回复: 12
打印 上一主题 下一主题

循环不执行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-08-14 20:16 |只看该作者 |倒序浏览
open FILE, "<e:/hg19.txt" or die "can not open the file!";
open OUT,">e:/newout.txt" or die "can not open the file!";

my $i;
my $count;
my $zone;
while(my $line1=<FILE>){
        my ($chr1,$pos1)=split(/\t/,$line1,2);
        my $num = 10;
        my $newpot = $pos1/$num ;
       
        for($zone= 0,$zone<$num,$zone++){
                $count=0;
               
                for ( $i=1,$i<$chr1,$i++){
                        open OBJ, "e:/obj.txt" or die "can not open the file!";
                        while(my $line=<OBJ>){
                                s/\n//;
                                my ($chr2,$pos2)=split(/\s+/,$line,2);
                                if(($chr1 eq $chr2) and ($pos2 < ($zone*$newpot+$newpot)) and ($pos2 > ($zone*$newpot))){
                                $count++;
                                }
                        }
                print OUT "$chr1\t$zone\t$count\n";
                close OBJ;
                close FILE;
                close OUT;
                }
        }
}
谁能帮我看看这个程序问题出在哪?最后打印值只有一行?

论坛徽章:
0
2 [报告]
发表于 2014-08-14 21:03 |只看该作者
程序修改了一下,把close FILE,closeOUT,放到了循环外面。可是打印的$count值依然不对,变成了三个一循环。。。

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2014-08-14 21:07 |只看该作者
回复 1# 明瞳狐狸

1. use ";" not "," in for loop
   for($zone= 0,$zone<$num,$zone++)
   for($zone= 0; $zone<$num; $zone++)
   
2. There is easy way to do the same things
   for($zone= 0; $zone<$num; $zone++)
   foreach my $zone ( 0 .. $num)
               
  for ( $i=1; $i<$chr1; $i++)
  foreach ( 1 .. $chr1)
Note: you didn't use $i in your loop

论坛徽章:
0
4 [报告]
发表于 2014-08-14 22:10 |只看该作者
回复 3# jason680
谢谢你的回复。


   

论坛徽章:
0
5 [报告]
发表于 2014-08-15 10:32 |只看该作者
回复 3# jason680
open FILE, "<e:/hg19.txt" or die "can not open the file!";
open OUT,">e:/newout.txt" or die "can not open the file!";

my $i;
my $count;
my $zone;

while(my $line1=<FILE>){
        my ($chr1,$pos1)=split(/\t/,$line1,2);
        my $num = 10;
        my $newpot = $pos1/$num ;
        for($zone=1;$zone<=$num;$zone++){
                $count=0;
                        open OBJ, "e:/obj.txt" or die "can not open the file!";
                        while(my $line=<OBJ>){
                                $line=~s/\n//;
                                my ($chr2,$pos2)=split(/\s+/,$line,2);
                                for ( $i=1;$i<=$chr1;$i++){
                                if(($i eq $chr2) and ($pos2 < ($zone)*$newpot)and ($pos2 > ($zone-1)*$newpot)){
                                $count++;
                                }
                        }
                }print OUT "$chr1\t$zone\t$count\n";
        }
}
close FILE;
close OUT;
这是我修改之后的程序,可是我的$count值每次都会叠加,你能帮我看看吗?

   

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
6 [报告]
发表于 2014-08-15 10:41 |只看该作者
回复 5# 明瞳狐狸

1. Would you please let's know what you want?

2. information
  input data
  procedure rule
  output data
  error message or issue

论坛徽章:
0
7 [报告]
发表于 2014-08-15 10:48 |只看该作者
回复 6# jason680
我的input data有两个,一个是24条染色体每条的总长度,如下所示:
1        249250621
2        243199373
3        198022430
4        191154276
5        180915260
第二个是每条染色体某个位置存在的突变点,如下所示:
3        164193293
8        131827193
4        150601746
3        60069490
11        117717720
4        90303285
7        158266757
1        198995747
3        70159509
10        47008697
15        47698522
11        59774819
17        19346851
11        119634359
1        88317527
2        135702162
我要做的是:把染色体长度均分成n个等份,看每个等份区间里共有多少个突变点存在。我知道我写的这个程序会很麻烦,计算时间也很长,不过现在只能写成这样,我想过用哈希做,不过具体的脚本想不出来,如果你能指点一二,不吝感激~

   

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2014-08-15 10:49 |只看该作者
就不能花点时间学学语法麽?
你这样大家累你也很累啊。

好歹都是高级知识分子,让学点儿东西就这么痛苦麽?
还不如我们这些农民工用功。

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
9 [报告]
发表于 2014-08-15 10:51 |只看该作者
回复 7# 明瞳狐狸

I'm sorry how to do can get the answer that you want
   

论坛徽章:
0
10 [报告]
发表于 2014-08-15 10:55 |只看该作者
回复 9# jason680

??是我描述的不清楚吗?我好像忘了贴出来我的运行结果:

1        1        73
1        2        88
1        3        100
1        4        94
1        5        84
1        6        8
1        7        101
1        8        101
1        9        108
1        10        79
2        1        187
2        2        170
2        3        200
2        4        159
2        5        207
2        6        99
2        7        205
2        8        195
2        9        220
2        10        191
我的结果是这样的,就是2-1那个值是在1-1的基础上叠加的,没有清零,我想知道为什么。我就是想先把这个程序的错误搞清楚,哈希的用法我之后会自己研究,不是说让你帮我想程序。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP