生物分子模拟论坛

 找回密码
 我想注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4340|回复: 1

[Centos] perl自动修改mol2中错误的N原子类型Nar-Npl3

[复制链接]
发表于 2013-1-26 14:49:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,下载更多分子模拟资源。

您需要 登录 才可以下载或查看,没有帐号?我想注册

x
#!/usr/bin/perl
#修改3处错误;
#默认可能有两个Nar,当时没有考虑有3个Nar
#我认为只有1个Nar需要修改,可能有两个Nar 需要修改
#在这里的时候要稍微注意下,经过修改让trueID返回数组
sub  atomtype2id{
$atomtype=$_[0];
  @text=@{$_[1]};
  #print "@text";
  foreach $line(@text){
  
   #print "$line";
   if($line=~/\s+(\d+)\s+\w+\s+\S+\s+\S+\s+\S+\s+$atomtype/)
   {
    #print "$1 \n";
   push @narid,$1;
   
   
   }
   
  }
   
     return @narid;
}

#指定定原子类型返回@ids;
sub  trueID{
    @nums=@_;
#print join(' ',@nums);
foreach $num(@nums)
{
  foreach $line(@text)
  {
   if($line=~/^\s+\d+\s+$num\s+(\d+)\s+(\S+)$/ || $line=~/^\s+\d+\s+(\d)+\s+$num\s+(\S+)$/ )
    {
     $tempid=$1;
     $bondtype=$2;
     if($bondtype=~/1/){
      
        push @trueids, $num;
     }
   }
  
   }
}

return @trueids;
}


$atomtype='N.ar';
open FH, "F:/task/test/segment1005.mol2";
@text=<FH>;
@narid=&atomtype2id("N.ar",\@text); ##获得所有Nar的类型原子的ID 编号
@trueids=&trueID(@narid);

while(@trueids!=0)
{
$getid=shift @trueids; #从里面依次取出id;

   foreach $line(@text)
       {
         if($line=~/(^\s+$getid\s+\w+\s+\S+\s+\S+\s+\S+\s+)($atomtype\s+)(.+$)/)   
         {
         
         print $1;
         printf("%-11s",'N.pl3');
         print $3;
         print "\n";
         }
         #    1     1     2 ar
        elsif ($line=~/(^\s+\d+\s+\d+\s+$getid\s+)(\S+)$/ || $line=~/(^\s+\d+\s+$getid\s+\d+\s+)(\S+.+)$/)
        {
         #    6     3     7 1
         print $1;
         printf("%-2d" ,"1");
         print "\n";
         
        }else{
          print $line;
         print $_;
        }
      }
      
}















sub  atomtype2id{
$atomtype=$_[0];
  @text=@{$_[1]};
  #print "@text";
  foreach $line(@text){
  
   #print "$line";
   if($line=~/\s+(\d+)\s+\w+\s+\S+\s+\S+\s+\S+\s+$atomtype/)
   {
    #print "$1 \n";
   push @narid,$1;
   
   
   }
   
  }
   
     return @narid;
}

批量处理,自己加个循环,或者联系我qq 1679088991

评分

参与人数 1金币 +10 收起 理由
川大-灰太狼 + 10 很给力!

查看全部评分

发表于 2013-1-28 21:57:08 | 显示全部楼层
呵呵 谢谢 数据挖掘的分享!
您需要登录后才可以回帖 登录 | 我想注册

本版积分规则

QQ|分迪科技|小黑屋|手机版|Archiver|生物分子模拟论坛 ( 蜀ICP备14009200号-3 )

GMT+8, 2024-4-26 00:03 , Processed in 0.054427 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表