-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathFasta2Phylip.pl
executable file
·62 lines (56 loc) · 1.07 KB
/
Fasta2Phylip.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -w
# obtained from Yu-Wei's Bioinformatics playground
# http://yuweibioinfo.blogspot.com/2009/01/fasta-to-phylip-converter.html
use strict;
MFAtoPHYLIP($ARGV[0]);
sub MFAtoPHYLIP
{
my $inline;
my $outfile = "$_[0]\.phy";
my $count = 0;
my $len;
my $substate = 0;
my @subheader;
my @subcontent;
my $m;
my $n;
open (FILE, "<$_[0]");
while (defined($inline = <FILE>))
{
chomp($inline);
if ($inline =~ /^>([A-Za-z0-9.\-_:]+)/)
{
$subheader[$count] = $1;
$subcontent[$count] = "";
$count++;
}
else
{
$subcontent[$count - 1] = $subcontent[$count - 1] . " $inline";
}
}
close (FILE);
# Calculate the content length
$n = length($subcontent[0]);
$len = $n;
for ($m = 0; $m < $n; $m++)
{
if (substr($subcontent[0], $m, 1) eq " ")
{
$len--;
}
}
open (FILE, ">$outfile");
print FILE " $count $len\n";
for ($m = 0; $m < $count; $m++)
{
$len = 10 - length($subheader[$m]);
print FILE "$subheader[$m]";
for ($n = 0; $n < $len; $n++)
{
print FILE " ";
}
print FILE " $subcontent[$m]\n";
}
close (FILE);
}