-
Notifications
You must be signed in to change notification settings - Fork 18
/
catAlign.pl
48 lines (41 loc) · 890 Bytes
/
catAlign.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
use strict;
use FileHandle;
use diagnostics;
my $dir= shift @ARGV;
my $output=shift @ARGV;
opendir (DIR, $dir);
my $file;
my %sequences;
my ($header,@seq);
foreach my $files(sort{$a cmp $b} readdir(DIR)){
next if ($files=~ /^..?$/);
if ($files=~ /\.cdn$/){
print "$files\n";
$file= $dir.'/'.$files;
}
if (!-z $file){read_file($file);}
}
open (OUT, ">$output");
for my $keys (sort keys %sequences) {
my $alignment= join '', @{$sequences{$keys}};
print OUT ">$keys\n$alignment\n";
}
sub read_file
{
my $alignment= shift;
my $name;
my $fh= FileHandle->new($alignment)|| die "$!";
if ($fh->open("< $alignment")){
$/= ">";
while (<$fh>){
$_=~ s/\>//g;
unless ($_){next};
($header,@seq) = split /\n/, $_;
my $line= join "",@seq;
push @{$sequences{$header}},$line;
}
$/="\n";
$fh->close;
}
}