• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PerlFASTA文件拆分合并

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、合并并转化一代测序seq纯文本为fasta格式文件

use strict;
use warnings;

my @dir;
my @filelist;
open OUT, ">result.fst";
opendir (DIR, "./") or die "can't open the directory!";
@dir = readdir DIR;
foreach my $file (@dir) {
    if ( $file =~ /[a-z]*\.seq/) {
        push @filelist,$file;
    } 
}
closedir(DIR);

foreach my $file (@filelist){
    open IN, "<".$file or die "cannot open $file";
    print OUT ">".$file."\n";
    print OUT <IN>;
    close(IN);
}

close (OUT);

 2、合并文件夹下的纯文本文件

use strict;
use warnings;

open T, ">T.fas";
open R, ">R.fas";

opendir (DIR_T, "./T/") or die "cannot open this dir $!";
opendir (DIR_R, "./R/") or die "cannot open this dir $!";
my @t = readdir DIR_T;
my @r = readdir DIR_R;

closedir(DIR_T);
closedir(DIR_R);

foreach my $file (@t){
    if($file ne "." && $file ne ".."){
        open IN, "<T/".$file or die "cannot open $file";
        print T <IN>;
        close (IN);
    }
}

foreach my $file (@r){
    if($file ne "." && $file ne ".."){
        open IN, "<R/".$file or die "cannot open $file";
        print R <IN>;
        close (IN);
    }
}

close(T);
close(R);

 3、批量序列拼接

use strict;
use warnings;

open T, "<T_a.fas";
open R, "<R_a.fas";
open H, ">Haplotypes.fas";
my @t = <T>;
my @r = <R>;
sub combine{

	print H ">$_[0]\n"; 
	my $tag = 0;
	foreach (@t){
		if(/>$_[1]\s/){
			$tag = 1;
		}elsif(/>\w+/){
			$tag = 0
		}elsif($tag){
			print H $_;
		}
	}
	$tag = 0;
	foreach (@r){
		if(/>$_[2]\s/){
			$tag = 1;
		}elsif(/>\w+/){
			$tag = 0
		}elsif($tag){
			print H $_;
		}
	}
	#print H "\n";
}
 
# 调用函数
combine("O","T7","R4");
combine("P","T1","R5");
combine("M","T1","R4");
combine("L","T5","R4");
combine("U","T1","R9");
combine("I","T1","R3");
combine("AT","T25","R5");
combine("AS","T1","R26");
combine("BF","T1","R36");
combine("BG","T36","R4");
combine("BH","T1","R37");
combine("BI","T37","R5");
combine("BJ","T38","R5");

close(T);
close(R);
close(H);

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
(转载)CSV文件处理PERL发布时间:2022-07-22
下一篇:
Can'tlocatefind.plin@INC(@INCcontains:/etc/perlxxxx)atperlpath.plline7.发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap