免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: yanglc2013
打印 上一主题 下一主题

20积分悬赏,求个perl程序,新手,写了好几个都无果。 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2013-03-29 18:28 |显示全部楼层
本帖最后由 picbhan 于 2013-03-29 18:29 编辑

回复 40# dahe_1984


    我只能说你太暴力,比inc中每一个region对ref中整个chr*的比较还要暴力。呵呵

论坛徽章:
0
12 [报告]
发表于 2013-03-29 18:49 |显示全部楼层
回复 39# yanglc2013


    不是因为少了,而是inc中每个region我都确保只输出到一个文件中,没有输出到多个文件中,如果某个region与ref中的gene存在完全包含关系,就不会输出到overlap中。比如你说overlap中少了 lnc-TAF12-1:4        chr2        9        15        - , 那是因为ref中 NM_001097613        chr2        11 13        -        1697完全落在了inc的区间内,所以那个region就只输出到了inc_include_ref这个文件中。你如果要想一个region输出到多个文件中(对每种情况都输出)的话,可以稍微改一下代码就行,把标量$result改为%result,然后用不同情况下的字符串作为key,最近依据key值输出到不同文件中就行。但是这种情况下不能在找到包含关系之后就立即last(就是我最后帮你加的那两个last语句)。

另外你说non_include 少了 lnc-HES5-1:2        chr3        14 100        - ,这是因为你说不需要考虑正负链,那么这个region与ref中 NM_016505        chr3        50 128        +        827 是overlap的,所以输出在overlap中。
你再好好检查下吧。

论坛徽章:
0
13 [报告]
发表于 2013-03-31 12:12 |显示全部楼层
回复 45# yanglc2013


    你觉得这样子输出有具体意义吗?inc中任何一个region都会被输出到non_include中去,只要你的refGene足够多。对于后面三种有交集的情况,如果要输出到多个文件中,你把下面的代码替换一下就行。
  1. my %result; # one of ref_include_inc, inc_include_ref, overlap or undef
  2.             while (@ref_data) {
  3.                 my @rd = @{+shift @ref_data};
  4.                 # igore genes on the left side of inc region
  5.                 next if $rd[3] < $id[2];
  6.                 push @store, [@rd];
  7.                 # stop when this gene is on the right side of inc region
  8.                 last if $rd[2] > $id[3];
  9.                 # this gene must overlap with this inc region
  10.                 if ($id[2] >= $rd[2] && $id[3] <= $rd[3]) {
  11.                     $result{ref_include_inc} = 1;
  12.                 }
  13.                 elsif ($rd[2] >= $id[2] && $rd[3] <= $id[3]) {
  14.                     $result{inc_include_ref} = 1;
  15.                 }
  16.                 else {
  17.                     $result{overlap} = 1;
  18.                 }
  19.             }
  20.             # output result
  21.             if (%result) {
  22.                 if ($result{ref_include_inc}) {
  23.                     print {$ref_include_inc} join("\t", @id), "\n";
  24.                 }
  25.                 if ($result{inc_include_ref}) {
  26.                     print {$inc_include_ref} join("\t", @id), "\n";
  27.                 }
  28.                 if ($result{overlap}) {
  29.                     print {$overlap} join("\t", @id), "\n";
  30.                 }
  31.             }
  32.             else { # if $result is undef, means no overlapped genes
  33.                 print {$non_include} join("\t", @id), "\n";
  34.             }
  35.             
  36.             # put this genes back into @ref_data, use to check next inc region
  37.             unshift @ref_data, @store;
  38.             @store = ();
  39.         }
复制代码

论坛徽章:
0
14 [报告]
发表于 2013-04-07 15:02 |显示全部楼层
回复 54# yanglc2013


    你在下面的代码中加入输出的信息(包括@rd和@id),并且把原来的三个赋值语句改为一个表示已经输出过的flag,这样在后面判断是否是non-overlap的时候就只需要看这个flag是不是真值了。

  1.                 if ($id[2] >= $rd[2] && $id[3] <= $rd[3]) {
  2.                     $result{ref_include_inc} = 1;
  3.                 }
  4.                 elsif ($rd[2] >= $id[2] && $rd[3] <= $id[3]) {
  5.                     $result{inc_include_ref} = 1;
  6.                 }
  7.                 else {
  8.                     $result{overlap} = 1;
  9.                 }
  10.                 if (%result) {
  11.                 if ($result{ref_include_inc}) {
  12.                     print {$ref_include_inc} join("\t", @id), "\n";
  13.                 }
  14.                 if ($result{inc_include_ref}) {
  15.                     print {$inc_include_ref} join("\t", @id), "\n";
  16.                 }
  17.                 if ($result{overlap}) {
  18.                     print {$overlap} join("\t", @id), "\n";
  19.                 }
  20.             }
  21.             else { # if $result is undef, means no overlapped genes
  22.                 print {$non_include} join("\t", @id), "\n";
  23.             }
复制代码

论坛徽章:
0
15 [报告]
发表于 2013-04-09 13:46 |显示全部楼层
yanglc2013 发表于 2013-04-08 19:17
回复 2# picbhan

谢谢啊,你的程序非常好用。还有个难题想请教你,我也写了几个,一塌糊涂啊。


首先,我没有看到你说的你也写了几个,我只看到你的问题。
其次,其实你的问题很简单,如果你真认真学了Perl并且自己动手写了,肯定是可以完成的,这根本不是什么难题,仅仅只是简单的格式转换而已。
最后,没有人可以一直帮你写代码,而且这种问题都等着别人给你写代码的话只会降低你自己的效率。好好学perl基础编程吧,足以在生物里用了。
  1. #!perl
  2. use List::MoreUtils 'pairwise';

  3. $fin = 'refGene.txt';
  4. open my $in, '<', $fin or die "Can't open $fin for reading. $!\n";
  5. $fout = 'result.txt';
  6. open my $to, '>', $fout or die "Can't create $fout for writing. $!\n";

  7. while (<$in>) {
  8.     chomp;
  9.     my @t = split;
  10.     @start = split /,/, $t[1];
  11.     @end = split /,/, $t[2];
  12.     pairwise { print {$to} "$t[0]\t$a\t$b\n" } @start, @end;
  13. }
  14. close $in;
  15. close $to;
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP