• Perl FASTA文件拆分合并


    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."
    ";
        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]
    "; 
    	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 "
    ";
    }
     
    # 调用函数
    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);
    
  • 相关阅读:
    用代理IP进行简单的爬虫——爬高匿代理网站
    python利用django实现简单的登录和注册,并利用session实现了链接数据库
    python基础知识——基于python3.6
    笔记2_列表、元组、字典
    wpf Command
    可枚举对象操作
    2019寒假训练营寒假作业(二) 程序题部分
    2019-01-23 寒假作业(一)
    2019寒假训练营第二次作业
    网络空间安全概论 学习笔记(二)
  • 原文地址:https://www.cnblogs.com/liulele/p/9951111.html
Copyright © 2020-2023  润新知