寻求帮助呢!根据一个文件每行的部分内容提取另一个文件的序列!!!!
时间:2011-02-10
来源:互联网


实现功能:
file1中fips1PMG_6 若和file2中ACS_ake_6 中的数字相同,则提取序列并保存。file2中剩下未匹配的序列也保存在另一个文件中。
即两个文件_后面的数字若相同,序列保存在一个文件,其余序列保存在另一个文件!
谢谢!
perl应该可以实现,但由于刚刚接触perl,思路不清晰,寻求帮助!
作者: Learnperl 发布时间: 2011-02-10
去看看正则吧。
作者: liuqiao007 发布时间: 2011-02-10
今天看了一天
#!/usr/bin/perl -w
# Program name: Cutseq.pl
#===============================================================================================================
open(OUTPUT,">test") or die "can not output";
$/= ">" ;
open(INPUT1,"file2") or die "can not find the file";
while(<INPUT1>) {
our($title,$seqence)= split(/\n/,$_,2);
$title=~/_(\d)+/g;
$match1=$&;
$hash{$match1}=$sequence;}
open(INPUT2,"file1") or die "can not find the file";
while(<INPUT2>) { our($name1,$name2,$name3)=split(/(\s)+/,$_)
$name3=~/_(\d)+/g;
$match2=$&;
if ($match2=$match1) {print OUTPUT "$match1\n$sequence";
}
}
}
只能想到这 可是run不出来 也觉得有些不对,但不知道怎么改
#!/usr/bin/perl -w
# Program name: Cutseq.pl
#===============================================================================================================
open(OUTPUT,">test") or die "can not output";
$/= ">" ;
open(INPUT1,"file2") or die "can not find the file";
while(<INPUT1>) {
our($title,$seqence)= split(/\n/,$_,2);
$title=~/_(\d)+/g;
$match1=$&;
$hash{$match1}=$sequence;}
open(INPUT2,"file1") or die "can not find the file";
while(<INPUT2>) { our($name1,$name2,$name3)=split(/(\s)+/,$_)
$name3=~/_(\d)+/g;
$match2=$&;
if ($match2=$match1) {print OUTPUT "$match1\n$sequence";
}
}
}
只能想到这 可是run不出来 也觉得有些不对,但不知道怎么改
作者: Learnperl 发布时间: 2011-02-10
- #!/usr/bin/perl -w
- use strict;
- open CON, "file1";
- my $line;
-
-
- while($line = <CON>){
- if($line =~ /fips1PMG_(\d+)\s/){
- #print "$1\n"
- push(@nums,$1);
- }
- }
- close CON;
-
- #print "@nums\n";
- open CON, "file2";
- open FILE, ">>same.txt" or die "Open file: same.txt failed";
- open FILE2, ">>diff.txt" or die "Open file: diff.txt failed";
- my $line2;
- my @nums;
- my $count = 0;
- my $flag = 0;
- while($line2 = <CON>){
- if($count > 0){
- print FILE ("$line2");
- $count --;
- }
- if($flag > 0){
- print FILE2 ("$line2");
- $flag --;
- }
- if($line2 =~ /ACS_ake_(\d+)\s/){
- if(grep {/$1/} @nums){
- $count = 4;
- }else {
- $flag = 4;
- }
- }
- }
- close CON;
- close FILE;
- close FILE2;
作者: 工藤*新一 发布时间: 2011-02-10
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28