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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
CREDIT splitstree
SplitsTree4 is the leading application for computing evolutionary networks from molecular sequence data.
Copyright by Daniel Huson and David Bryant.
http://www.splitstree.org/
package SplitsTree::Viewer;
# path to SplitsTree
custom $splitstree;
CONFIGURE {
find_program($splitstree, "SplitsTree");
}
###########################################################################################
#
# Object type to visualize with SplitsTree
#
package Visual::FiniteMetricSpace;
use Polymake::Struct (
[ '@ISA' => 'Object' ],
[ '$metric' => '#%' ],
[ '$taxa' => 'unify_labels(#%)', default => 'undef' ],
);
###########################################################################################
#
# Static (file-based) implementation of the Viewer interface
#
package SplitsTree::Viewer;
use SplitsTree;
use BackgroundViewer;
use Polymake::Struct [ '@ISA' => 'SimpleViewer' ];
sub file_suffix { ".nex" }
sub command {
my ($self, $filename)=@_;
"$splitstree -i $filename";
}
# @category Visualization
# Use [[wiki:external_software#SplitsTree]] to show planar images of tight spans.
label splitstree
global_method splitstree.tight_span: draw(Visual::FiniteMetricSpace) {
my ($self, $M)=@_;
$self->graphics->metric=$M->metric;
$self->graphics->taxa=$M->taxa;
}
package SplitsTree::File::Writer;
import Visual::FileWriter;
package application;
# @category Visualization
# Visualize the splits of a finite metric space (that is, a planar image of a tight span). Calls SplitsTree.
# @param Matrix<Rational> M Matrix defining a metric
# @option Array<String> taxa Labels for the taxa
# @option String name Name of the drawing
# @return Visual::Object
user_function visual_splitstree ($;{taxa=>undef, name=>undef}) {
my ($m, $options) = @_;
my $mat = new Matrix($m);
my $label = $options->{taxa} // [0..$mat->rows-1];
my $name = $options->{name} // 'polymake_splitstree';
visualize(new Visual::FiniteMetricSpace(Name => $name,
metric => convert_to<Float>($mat),
taxa => $label));
}
# @category Visualization
# Call [[wiki:external_software#SplitsTree]] with the given visual objects.
#
# @param Visual::Object vis_obj ... objects to display
#
# @option [complete file] String File "filename" or "AUTO"
# Only create a NEXUS format file, don't start the GUI.
#
# The ''.nex'' suffix is automatically added to the file name.
#
# Specify //AUTO// if you want the filename be automatically derived from the drawing title.
#
# You can also use any expression allowed for the ''open'' function,
# including "-" for terminal output, "&HANDLE" for an already opened file handle,
# or "| program" for a pipe.
user_function splitstree(Visual::Object+, { File => undef }) {
visualize_explicit(@_, "SplitsTree");
}
# Local Variables:
# cperl-indent-level:3
# mode: perl
# End:
|