| Line | |
|---|
| 1 | #! /usr/bin/perl -w |
|---|
| 2 | # Copyright (2005) Reed A. Cartwright. All rights reserved. |
|---|
| 3 | # |
|---|
| 4 | # converts nexus sequences to fasta |
|---|
| 5 | # |
|---|
| 6 | # usage: perl nexus2fasta.pl < infile > outfile |
|---|
| 7 | # |
|---|
| 8 | # Distributed under the same license as DAWG |
|---|
| 9 | # |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | my $state = 0; |
|---|
| 13 | |
|---|
| 14 | my %seqs = (); |
|---|
| 15 | |
|---|
| 16 | local $/; |
|---|
| 17 | my $text = <>; |
|---|
| 18 | |
|---|
| 19 | my ($data) = $text =~ /begin\s+data;.+?matrix\s*(.*?);\s*end;/is; |
|---|
| 20 | my @lines = split(/\n/, $data); |
|---|
| 21 | |
|---|
| 22 | foreach(@lines) |
|---|
| 23 | { |
|---|
| 24 | s/^\s+//; |
|---|
| 25 | s/\s+$//; |
|---|
| 26 | next unless(/\w/); |
|---|
| 27 | my @sec = split(/\s+/, $_); |
|---|
| 28 | my $name = shift(@sec); |
|---|
| 29 | $seqs{$name} |= ''; |
|---|
| 30 | $seqs{$name} .= join('', @sec); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | print ">$_\n$seqs{$_}\n\n" foreach(sort(keys(%seqs))); |
|---|
| 34 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.