免费注册 查看新帖 |

Chinaunix

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

弱弱求助perl代码提取信息!谢谢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-08 11:20 |只看该作者 |倒序浏览
本帖最后由 tempo8 于 2013-04-09 08:53 编辑

1.关键词[Query: | Description:]这两行任一行中含有关键词(如BTB)
2.提取[Query:]直至 [Domain annotation for each sequence (and alignments):]之间的信息
3. 一个关键词可能有多条记录,想实现多个关键词查找(一个一个来)

Query:       BACK  [M=103]
Accession:   PF07707.10
Description: BTB And C-terminal Kelch
    E-value  score  bias    E-value  score  bias    exp  N  Sequence                         Description
    ------- ------ -----    ------- ------ -----   ---- --  --------                         -----------
    1.4e-11   46.1   0.1    3.5e-11   44.8   0.1    1.7  1  GRMZM2G397948_T03|PACid:20828641
                                        这里有N行
Domain annotation for each sequence (and alignments):

Query:       1-cysPrx_C  [M=40]
Accession:   PF10417.4
Description: C-terminal domain of 1-Cys peroxiredoxin
Scores for complete sequences (score includes all domains):
   --- full sequence ---   --- best 1 domain ---    -#dom-
    E-value  score  bias    E-value  score  bias    exp  N  Sequence                         Description
    ------- ------ -----    ------- ------ -----   ---- --  --------                         -----------
    4.6e-10   41.0   0.1    9.5e-10   40.0   0.1    1.6  1  GRMZM5G864335_T01|PACid:20879992
    4.9e-10   40.9   0.1    9.5e-10   40.0   0.1    1.5  1  GRMZM2G139680_T01|PACid:20860278
    1.3e-09   39.5   0.1    2.7e-09   38.5   0.1    1.6  1  GRMZM2G129761_T02|PACid:20832824
      2e-09   38.9   0.1    4.2e-09   37.9   0.1    1.6  1  GRMZM2G129761_T01|PACid:20832823
Domain annotation for each sequence (and alignments):

Query:       BTB  [M=111]
Accession:   PF00651.26
Description: BTB/POZ domain
    E-value  score  bias    E-value  score  bias    exp  N  Sequence                         Description
    ------- ------ -----    ------- ------ -----   ---- --  --------                         -----------
    9.8e-38  130.6   2.1    2.5e-22   81.0   0.1    4.4  3  GRMZM2G077951_T01|PACid:20873384
                                        这里有N行
Domain annotation for each sequence (and alignments):

Query:       DUF1751  [M=99]
Accession:   PF08551.5
Description: Eukaryotic integral membrane protein (DUF1751)
Scores for complete sequences (score includes all domains):
   --- full sequence ---   --- best 1 domain ---    -#dom-
    E-value  score  bias    E-value  score  bias    exp  N  Sequence                         Description
    ------- ------ -----    ------- ------ -----   ---- --  --------                         -----------
    6.8e-31  108.5   3.7    6.8e-31  108.5   2.6    2.7  3  GRMZM2G057652_T02|PACid:20864676
      5e-30  105.7   2.6      5e-30  105.7   1.8    2.0  2  GRMZM2G172138_T01|PACid:20843621
    1.6e-29  104.1   3.8    1.6e-29  104.1   2.6    2.4  2  GRMZM2G157749_T02|PACid:20839701
      2e-29  103.8   3.8      2e-29  103.8   2.6    2.3  2  GRMZM2G157749_T01|PACid:20839700
  Domain annotation for each sequence (and alignments):

论坛徽章:
0
2 [报告]
发表于 2013-04-08 14:40 |只看该作者
  1. #!/usr/bin/perl -w
  2. open $fh,'<','test.txt' or die "Cannot open file raw.txt:$!\n";
  3. my $old=$/;
  4. die "Usage:./test.pl keyword\n" unless(defined($ARGV[0]));
  5. my $key=$ARGV[0];
  6. $/="Domain annotation for each sequence (and alignments):";
  7. while(<$fh>){
  8.         chomp;
  9.         if(/Query:\s+($key)/ or /Description: $key/){
  10.                 s/Query:\s+(.*)/$1/;
  11.                 print;
  12.         }
  13. }
  14. close $fh;
复制代码
test.txt是存数据的文件,在命令行指定关键字./test.pl BTB,代码虽丑陋。。但貌似可以工作,新手

论坛徽章:
0
3 [报告]
发表于 2013-04-08 18:20 |只看该作者
没搞懂你到底要提取什么信息。那么多行都要原始输出?

论坛徽章:
0
4 [报告]
发表于 2013-04-08 18:56 |只看该作者
本帖最后由 tempo8 于 2013-04-09 08:56 编辑

谢谢二位的帮助!
实际上只要每一条记录的前3行和竖杠“|”前的ID号“GRMZM2G397948_T03”
还有就是:关键词除了BTB,还有 ATB, BTD, …… 【几百个关键词都放在一个TXT中,每一行1个】

结果是这样子的:
Query:       1-cysPrx_C  [M=40]
Accession:   PF10417.4
Description: C-terminal domain of 1-Cys peroxiredoxin
GRMZM5G864335_T01
GRMZM2G139680_T01
GRMZM2G129761_T02
GRMZM2G129761_T01

Query:       BACK  [M=103]
Accession:   PF07707.10
Description: BTB And C-terminal Kelch
GRMZM2G397948_T03
GRMZM2G045257_T04
……还有N个ID

Query:       BTB_2  [M=94]
Accession:   PF02214.17
Description: BTB/POZ domain
GRMZM2G077951_T01
GRMZM2G033651_T01
……还有N个ID

Query:       DUF1751  [M=99]
Accession:   PF08551.5
Description: Eukaryotic integral membrane protein (DUF1751)
GRMZM2G057652_T02
 GRMZM2G157749_T02
GRMZM2G157749_T01
 
Query:       BTD  [M=76]
Accession:   PF01186
Description: BTB/POZ domain
GRMZM2G06524_T01
GRMZM2G07890_T01
……还有N个ID

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
5 [报告]
发表于 2013-04-09 06:44 |只看该作者
Bu 懂{:3_188:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP