source: release/1.2/nexus2fasta.pl @ 174

Revision 174, 638 bytes checked in by admin, 6 years ago (diff)
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
12my $state = 0;
13
14my %seqs = ();
15
16local $/;
17my $text = <>;
18
19my ($data) = $text =~ /begin\s+data;.+?matrix\s*(.*?);\s*end;/is;
20my @lines = split(/\n/, $data);
21
22foreach(@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
33print ">$_\n$seqs{$_}\n\n" foreach(sort(keys(%seqs)));
34
Note: See TracBrowser for help on using the repository browser.