use Graph::Reader::Dot;
use IPC::Run qw/ run binary /;
use Text::Tradition::Error;
-use Text::Tradition::StemmaUtil qw/ character_input phylip_pars parse_newick /;
use Moose;
=head1 NAME
=item * dot - A filehandle open to a DOT representation of the stemma graph.
+=item * graph - If no DOT specification is given, you can pass a Graph object
+instead. The vertices of the graph should have an attribute 'class' set to
+either of the values 'extant' or 'hypothetical'.
+
+=item * is_undirected - If the graph specification (or graph object) is for an
+undirected graph (e.g. a phylogenetic tree), this should be set.
+
=back
=begin testing
use_ok( 'Text::Tradition::Stemma' );
# Try to create a bad graph
+TODO: {
+ local $TODO = "cannot use stdout redirection trick with FastCGI";
my $baddotfh;
-open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
-try {
- my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
- ok( 0, "Created broken stemma from dotfile with syntax error" );
-} catch( Text::Tradition::Error $e ) {
- like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
+ open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
+ try {
+ my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
+ ok( 0, "Created broken stemma from dotfile with syntax error" );
+ } catch( Text::Tradition::Error $e ) {
+ like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
+ }
}
# Create a good graph
}
ok( $found_unicode_sigil, "Found a correctly encoded Unicode sigil" );
+# TODO Create stemma from graph, create stemma from undirected graph,
+# create stemma from incompletely-specified graph
+
=end testing
=cut
has collation => (
is => 'ro',
isa => 'Text::Tradition::Collation',
- clearer => 'clear_collation',
+ clearer => 'clear_collation', # interim measure to remove refs in DB
weak_ref => 1,
);
isa => 'Graph',
predicate => 'has_graph',
);
+
+has is_undirected => (
+ is => 'ro',
+ isa => 'Bool',
+ default => undef,
+ writer => 'set_undirected',
+ );
sub BUILD {
my( $self, $args ) = @_;
# If we have been handed a dotfile, initialize it into a graph.
if( exists $args->{'dot'} ) {
$self->_graph_from_dot( $args->{'dot'} );
- }
+ } else {
+ }
}
+before 'graph' => sub {
+ my $self = shift;
+ if( @_ ) {
+ # Make sure all unclassed graph nodes are marked extant.
+ my $g = $_[0];
+ throw( "Cannot set graph to a non-Graph object" )
+ unless ref( $g ) eq 'Graph';
+ foreach my $v ( $g->vertices ) {
+ unless( $g->has_vertex_attribute( $v, 'class' ) ) {
+ $g->set_vertex_attribute( $v, 'class', 'extant' );
+ }
+ }
+ $self->set_undirected( $g->is_undirected );
+ }
+};
+
sub _graph_from_dot {
my( $self, $dotfh ) = @_;
my $reader = Graph::Reader::Dot->new();
throw( "Failed to create graph from dot" );
}
$self->graph( $graph );
- # Go through the nodes and set any non-hypothetical node to extant.
- foreach my $v ( $self->graph->vertices ) {
- $self->graph->set_vertex_attribute( $v, 'class', 'extant' )
- unless $self->graph->has_vertex_attribute( $v, 'class' );
- }
}
=head1 METHODS
@edgeopts{ keys %{$opts->{'edge'}} } = values %{$opts->{'edge'}}
if $opts->{'edge'};
+ my $gdecl = $graph->is_directed ? 'digraph' : 'graph';
my @dotlines;
- push( @dotlines, 'digraph stemma {' );
+ push( @dotlines, "$gdecl stemma {" );
## Print out the global attributes
push( @dotlines, _make_dotline( 'graph', %graphopts ) ) if keys %graphopts;
push( @dotlines, _make_dotline( 'edge', %edgeopts ) ) if keys %edgeopts;
# Add each of our edges.
foreach my $e ( $graph->edges ) {
my( $from, $to ) = map { _dotquote( $_ ) } @$e;
- push( @dotlines, " $from -> $to;" );
+ my $connector = $graph->is_directed ? '->' : '--';
+ push( @dotlines, " $from $connector $to;" );
}
push( @dotlines, '}' );
# Create the graph
my $join = ( $opts && exists $opts->{'linesep'} ) ? $opts->{'linesep'} : "\n";
+ my $gdecl = $graph->is_undirected ? 'graph' : 'digraph';
my @dotlines;
- push( @dotlines, 'digraph stemma {' );
+ push( @dotlines, "$gdecl stemma {" );
my @real; # A cheap sort
foreach my $n ( sort $graph->vertices ) {
my $c = $graph->get_vertex_attribute( $n, 'class' );
}
foreach my $e ( sort _by_vertex $graph->edges ) {
my( $from, $to ) = map { _dotquote( $_ ) } @$e;
- push( @dotlines, " $from -> $to;" );
+ my $conn = $graph->is_undirected ? '--' : '->';
+ push( @dotlines, " $from $conn $to;" );
}
push( @dotlines, '}' );
return join( $join, @dotlines );
=head2 situation_graph( $extant, $layered )
-Returns a graph which is the original stemma with all witnesses not in the
-%$extant hash marked as hypothetical, and witness layers added to the graph
-according to the list in @$layered. A layered (a.c.) witness is added as a
-parent of its main version, and additionally shares all other parents and
-children with that version.
+Returns a graph which is the original stemma graph with all witnesses not
+in the %$extant hash marked as hypothetical, and witness layers added to
+the graph according to the list in @$layered. A layered (a.c.) witness is
+added as a parent of its main version, and additionally shares all other
+parents and children with that version.
=cut
sub as_svg {
my( $self, $opts ) = @_;
my $dot = $self->as_dot( $opts );
- my @cmd = qw/dot -Tsvg/;
+ my @cmd = ( '-Tsvg' );
+ unshift( @cmd, $self->is_undirected ? 'neato' : 'dot' );
my $svg;
my $dotfile = File::Temp->new();
## TODO REMOVE
my( $ew, $eh ) = @{$opts->{'size'}};
# If the graph is wider than it is tall, set width to ew and remove height.
# Otherwise set height to eh and remove width.
+ # TODO Also scale the viewbox
my $width = $svgdoc->documentElement->getAttribute('width');
my $height = $svgdoc->documentElement->getAttribute('height');
$width =~ s/\D+//g;
return @wits;
}
+=head2 root( $root_vertex ) {
+
+If the stemma graph is undirected, make it directed with $root_vertex at the root.
+If it is directed, re-root it.
+
+=cut
+
+sub root_graph {
+ my( $self, $rootvertex ) = @_;
+ my $graph;
+ if( $self->is_undirected ) {
+ $graph = $self->graph;
+ } else {
+ # Make an undirected version of this graph.
+ $graph = $self->graph->undirected_copy();
+ }
+ my $rooted = Graph->new();
+ $rooted->add_vertex( $rootvertex );
+ my @next = ( $rootvertex );
+ while( @next ) {
+ my @children;
+ foreach my $v ( @next ) {
+ # Place its not-placed neighbors (ergo children) in the tree
+ # and connect them
+ foreach my $n ( grep { !$rooted->has_vertex( $_ ) }
+ $graph->neighbors( $v ) ) {
+ $rooted->add_vertex( $n );
+ $rooted->add_edge( $v, $n );
+ push( @children, $n );
+ }
+ }
+ @next = @children;
+ }
+ # Set the vertex classes
+ map { $rooted->set_vertex_attribute( $_, 'class', 'hypothetical' ) }
+ $self->graph->hypotheticals;
+ map { $rooted->set_vertex_class( $_, 'class', 'extant' ) }
+ $self->graph->witnesses;
+ return $rooted;
+}
+
+
sub throw {
Text::Tradition::Error->throw(
'ident' => 'Stemma error',
use Graph::Reader::Dot;
use IPC::Run qw/ run binary /;
use Text::Tradition::Error;
+use Text::Tradition::Stemma;
@EXPORT_OK = qw/ character_input phylip_pars parse_newick newick_to_svg /;
=head1 NAME
=head1 SUBROUTINES
-=head2 character_input( $alignment_table )
+=head2 character_input( $tradition, $opts )
Returns a character matrix string suitable for Phylip programs, which
corresponds to the given alignment table. See Text::Tradition::Collation
-for a description of the alignment table format.
+for a description of the alignment table format. Options include:
+
+=over
+
+=item * exclude_layer - Exclude layered witnesses from the character input,
+using only the 'main' text of the witnesses in the tradition.
+
+=item * collapse - A reference to an array of relationship names that should
+be treated as equivalent for the purposes of generating the character matrix.
+
+=back
=cut
sub character_input {
- my $table = shift;
- my $character_matrix = _make_character_matrix( $table );
+ my ( $tradition, $opts ) = @_;
+ my $table = $tradition->collation->alignment_table;
+ if( $opts->{exclude_layer} ) {
+ # Filter out all alignment table rows that do not correspond
+ # to a named witness - these are the layered witnesses.
+ my $newtable = { alignment => [] };
+ foreach my $row ( $table->{alignment} ) {
+ if( $tradition->has_witness( $row->{witness} ) ) {
+ push( @{$newtable->{alignment}}, $row );
+ }
+ }
+ $table = $newtable;
+ }
+ my $character_matrix = _make_character_matrix( $table, $opts );
my $input = '';
my $rows = scalar @{$character_matrix};
my $columns = scalar @{$character_matrix->[0]} - 1;
}
sub _make_character_matrix {
- my( $table ) = @_;
+ my( $table, $opts ) = @_;
# Push the names of the witnesses to initialize the rows of the matrix.
my @matrix = map { [ _normalize_witname( $_->{'witness'} ) ] }
@{$table->{'alignment'}};
foreach my $token_index ( 0 .. $table->{'length'} - 1) {
- # First implementation: make dumb alignment table, caring about
- # nothing except which reading is in which position.
- my @pos_readings = map { $_->{'tokens'}->[$token_index] }
+ my @pos_tokens = map { $_->{'tokens'}->[$token_index] }
@{$table->{'alignment'}};
- my @pos_text = map { $_ ? $_->{'t'} : $_ } @pos_readings;
- my @chars = _convert_characters( \@pos_text );
+ my @pos_readings = map { $_ ? $_->{'t'} : $_ } @pos_tokens;
+ my @chars = _convert_characters( \@pos_readings, $opts );
foreach my $idx ( 0 .. $#matrix ) {
push( @{$matrix[$idx]}, $chars[$idx] );
}
}
sub _convert_characters {
- my $row = shift;
+ my( $row, $opts ) = @_;
# This is a simple algorithm that treats every reading as different.
# Eventually we will want to be able to specify how relationships
# affect the character matrix.
my %unique = ( '__UNDEF__' => 'X',
'#LACUNA#' => '?',
);
+ my %equivalent;
my %count;
my $ctr = 0;
- foreach my $word ( @$row ) {
- if( $word && !exists $unique{$word} ) {
- $unique{$word} = chr( 65 + $ctr );
- $ctr++;
- }
- $count{$word}++ if $word;
+ foreach my $rdg ( @$row ) {
+ next unless $rdg;
+ next if $rdg->is_lacuna;
+ next if exists $unique{$rdg->text};
+ if( ref( $opts->{'collapse'} ) eq 'ARRAY' ) {
+ my @exclude_types = @{$opts->{'collapse'}};
+ my @set = $rdg->related_readings( sub { my $rel = shift;
+ $rel->colocated && grep { $rel->type eq $_ } @exclude_types } );
+ push( @set, $rdg );
+ my $char = chr( 65 + $ctr++ );
+ map { $unique{$_->text} = $char } @set;
+ $count{$rdg->text} += scalar @set;
+ } else {
+ $unique{$rdg->text} = chr( 65 + $ctr++ );
+ $count{$rdg->text}++;
+ }
}
# Try to keep variants under 8 by lacunizing any singletons.
if( scalar( keys %unique ) > 8 ) {
if( scalar( keys %u ) > 8 ) {
warn "Have more than 8 variants on this location; phylip will break";
}
- my @chars = map { $_ ? $unique{$_} : $unique{'__UNDEF__' } } @$row;
+ my @chars = map { $_ ? $unique{$_->text} : $unique{'__UNDEF__' } } @$row;
return @chars;
}
=head2 parse_newick( $newick_string )
-Parses the given Newick tree(s) into one or more undirected Graph objects.
+Parses the given Newick tree(s) into one or more Stemma objects with
+undirected graphs.
=cut
sub parse_newick {
my $newick = shift;
- my @trees;
+ my @stemmata;
# Parse the result into a tree
my $forest = Bio::Phylo::IO->parse(
-format => 'newick',
);
# Turn the tree into a graph, starting with the root node
foreach my $tree ( @{$forest->get_entities} ) {
- push( @trees, _graph_from_bio( $tree ) );
+ my $stemma = Text::Tradition::Stemma->new(
+ graph => _graph_from_bio( $tree ),
+ is_undirected => 1 );
+ push( @stemmata, $stemma );
+ }
+ return \@stemmata;
+}
+
+sub _graph_from_bio {
+ my $tree = shift;
+ my $graph = Graph->new( 'undirected' => 1 );
+ # Give all the intermediate anonymous nodes a name.
+ my $i = 0;
+ my $classes = {};
+ foreach my $n ( @{$tree->get_terminals} ) {
+ # The terminal nodes are our named witnesses.
+ $classes->{$n->get_name} = 'extant';
+ }
+ foreach my $n ( @{$tree->get_internals} ) {
+ unless( defined $n->get_name && $n->get_name ne '' ) {
+ # Get an integer, make sure it's a unique name
+ while( exists $classes->{$i} ) {
+ $i++;
+ }
+ $n->set_name( $i++ );
+ }
+ $classes->{$n->get_name} = 'hypothetical';
+ }
+ _add_tree_children( $graph, $classes, undef, [ $tree->get_root ]);
+ return $graph;
+}
+
+sub _add_tree_children {
+ my( $graph, $classes, $parent, $tree_children ) = @_;
+ foreach my $c ( @$tree_children ) {
+ my $child = $c->get_name;
+ $graph->add_vertex( $child );
+ $graph->set_vertex_attribute( $child, 'class', $classes->{$child} );
+ $graph->add_path( $parent, $child ) if defined $parent;
+ _add_tree_children( $graph, $classes, $child, $c->get_children() );
}
- return \@trees;
}
=head2 newick_to_svg( $newick_string )
return decode_utf8( $svg );
}
-sub _graph_from_bio {
- my $tree = shift;
- my $graph = Graph->new( 'undirected' => 1 );
- # Give all the intermediate anonymous nodes a name.
- my $i = 0;
- foreach my $n ( @{$tree->get_entities} ) {
- next if $n->get_name;
- $n->set_name( $i++ );
- }
- my $root = $tree->get_root->get_name;
- $graph->add_vertex( $root );
- _add_tree_children( $graph, $root, $tree->get_root->get_children() );
- return $graph;
-}
-
-sub _add_tree_children {
- my( $graph, $parent, $tree_children ) = @_;
- foreach my $c ( @$tree_children ) {
- my $child = $c->get_name;
- $graph->add_vertex( $child );
- $graph->add_path( $parent, $child );
- _add_tree_children( $graph, $child, $c->get_children() );
- }
-}
-
sub throw {
Text::Tradition::Error->throw(
'ident' => 'StemmaUtil error',
use Moose;
use namespace::autoclean;
use Text::Tradition::Analysis qw/ run_analysis /;
+use Text::Tradition::StemmaUtil qw/ character_input phylip_pars parse_newick /;
use TryCatch;
$c->forward('View::JSON');
}
+=head2 phylotrees
+
+ GET /phylotrees/$textid
+
+ Calculates the phylogenetic tree(s) from the given text variants, and returns a
+ set of the results. The user may then select a tree, choose a root node, and add
+ that to the stemmata for the tradition (if s/he has edit rights to the tradition.)
+
+=cut
+
+sub phylotrees :Local :Args(1) {
+ my( $self, $c, $textid ) = @_;
+ my $tradition = $c->model('Directory')->tradition( $textid );
+ unless( $tradition ) {
+ return _json_error( $c, 500, "No tradition with ID $textid" );
+ }
+ my $ok = _check_permission( $c, $tradition );
+ return unless $ok;
+
+ ## Make the character matrix and run pars
+ ## TODO normalization options
+ my $charmatrix = character_input( $tradition );
+ my $newick;
+ try {
+ $newick = phylip_pars( $charmatrix );
+ } catch ( Text::Tradition::Error $e ) {
+ return _json_error( $c, 500, $e->message );
+ }
+ ## If we got a result, stash it
+ $c->stash->{'stemmadot'} = [];
+ $c->stash->{'stemmasvg'} = [];
+ if( $newick ) {
+ my $stemmata = parse_newick( $newick );
+ foreach my $st ( @$stemmata ) {
+ push( @{$c->stash->{'stemmadot'}}, $st->editable({ linesep => ' ' }) );
+ my $svgstr = $st->as_svg( {size => [ 800, 600 ] });
+ $svgstr =~ s/\n//mg;
+ push( @{$c->stash->{'stemmasvg'}}, $svgstr );
+ }
+ }
+ $c->stash->{'template'} = 'phylotrees.tt';
+}
+
####################
### Helper functions
####################
--- /dev/null
+[% WRAPPER header.tt
+ pagetitle = "Stemmaweb - Phylogeny calculation tool"
+ applicationjs = c.uri_for( 'js/phylotools.js' )
+%]
+ <script type="text/javascript">
+var basepath = "[% c.uri_for( '/' ) %]";
+var textid = "[% textid %]";
+var editable = "[% editable %]"
+var currSelected;
+var stemmadot = [];
+var stemmasvg = [];
+var stemmata_added = {};
+
+function getPhylogeny () {
+ stemmadot = [];
+ stemmasvg = [];
+ var phylourl = basepath + textid;
+ $('#textinfo_waitbox').show();
+ $.getJSON( basepath + "phylocalc/" + textid, function (textdata) {
+ stemmadot = textdata.stemmadot;
+ stemmasvg = textdata.stemmasvg;
+ $('#textinfo_waitbox').hide();
+ load_stemma( 0 );
+ }); // TODO error handling
+}
+
+function load_stemma( idx ) {
+ // Load the stemma at idx
+ currSelected = idx;
+ show_stemmapager();
+ if( idx > -1 ) {
+ $('#stemma_graph').empty();
+ $('#stemma_graph').append( stemmasvg[idx] );
+ if( stemmadot[idx].substr('digraph') > -1 && stemmata_added[idx] != true ) {
+ // It has a root, so we may add it to the tradition stemmata.
+ $('#add_stemma_button').show();
+ }
+ setTimeout( 'start_element_height = $("#stemma_graph .node")[0].getBBox().height;', 500 );
+ }
+}
+
+function show_stemmapager () {
+ $('.pager_left_button').unbind('click').addClass( 'greyed_out' );
+ $('.pager_right_button').unbind('click').addClass( 'greyed_out' );
+ if( currSelected > 0 ) {
+ $('.pager_left_button').click( function () {
+ load_stemma( currSelected - 1 );
+ }).removeClass( 'greyed_out' );
+ }
+ if( selectedStemmaID + 1 < stemmata.length ) {
+ $('.pager_right_button').click( function () {
+ load_stemma( currSelected + 1 );
+ }).removeClass( 'greyed_out' );
+ }
+}
+
+function add_selected_stemma () {
+ var requrl = basepath + "stemma/" + textid + "/n";
+ var reqparam = { 'dot': stemmadot[currSelected] };
+ $.post( requrl, reqparam, function (data) {
+ // Disable add for any stemma already added
+ stemmata_added[currSelected] = true;
+ $('#add_stemma_button').hide();
+ // TODO maybe check on the server if the stemma exists?
+ }, 'json' );
+}
+
+function rootStemma ( stemidx, root ) {
+ // Send the stemmadot at stemidx to the server, along with the name of the
+ // selected root node. Receive back a dot spec and an SVG, and enable the
+ var rooturl = basepath + 'microservices/rootedstemma';
+ var params = { 'dot': stemmadot[stemidx], 'root': root };
+ $.post( rooturl, params, function (data) {
+ stemmadot[stemidx] = data.stemmadot;
+ stemmasvg[stemidx] = data.stemmasvg;
+ load_stemma( stemidx );
+ }); // TODO error handling
+}
+
+$(document).ready( function() {
+ $('#stemma_graph').mousedown( function(evt) {
+ evt.stopPropagation();
+ $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
+ $('body').mousemove( function(evt) {
+ mouse_scale = 1; // for now, was: mouse_scale = svg_root_element.getScreenCTM().a;
+ dx = (evt.clientX - $('#stemma_graph').data( 'mousedown_xy' )[0]) / mouse_scale;
+ dy = (evt.clientY - $('#stemma_graph').data( 'mousedown_xy' )[1]) / mouse_scale;
+ $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
+ var svg_root = $('#stemma_graph svg').svg().svg('get').root();
+ var g = $('g.graph', svg_root).get(0);
+ current_translate = g.getAttribute( 'transform' ).split(/translate\(/)[1].split(')',1)[0].split(' ');
+ new_transform = g.getAttribute( 'transform' ).replace( /translate\([^\)]*\)/, 'translate(' + (parseFloat(current_translate[0]) + dx) + ' ' + (parseFloat(current_translate[1]) + dy) + ')' );
+ g.setAttribute( 'transform', new_transform );
+ evt.returnValue = false;
+ evt.preventDefault();
+ return false;
+ });
+ $('body').mouseup( function(evt) {
+ $('body').unbind('mousemove');
+ $('body').unbind('mouseup');
+ });
+ });
+
+ $('#stemma_graph').mousewheel(function (event, delta) {
+ event.returnValue = false;
+ event.preventDefault();
+ if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
+ if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
+ if( delta < -9 ) { delta = -9 };
+ var z = 1 + delta/10;
+ z = delta > 0 ? 1 : -1;
+ var svg_root = $('#stemma_graph svg').svg().svg('get').root();
+ var g = $('g.graph', svg_root).get(0);
+ if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 1000))) {
+ var scaleLevel = z/10;
+ current_scale = parseFloat( g.getAttribute( 'transform' ).split(/scale\(/)[1].split(')',1)[0].split(' ')[0] );
+ new_transform = g.getAttribute( 'transform' ).replace( /scale\([^\)]*\)/, 'scale(' + (current_scale + scaleLevel) + ')' );
+ g.setAttribute( 'transform', new_transform );
+ }
+ });
+
+ $('#stemma_root_cancel').hide();
+ if( !editable ) {
+ $('#stemma_add_form').hide();
+ }
+ // call out to run the phylogeny calculation
+ getPhylogeny();
+
+});
+ </script>
+
+[% END %]
+
+ <div id="topbanner">
+ <h1>Stemmaweb - [% algorithm_name %] calculation for [% text_name %]</h1>
+ <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About</a> </span>
+ </div>
+ <div id="textinfo_container">
+ <div id="textinfo_load_status"></div>
+ <h2>Text <span class="texttitle">[% text_name %]</span></h2>
+ <div id="textinfo_container_buttons">
+ <form id="stemma_pager" action="" method="GET" name="stemma_pager">
+ <div id="stemma_pager_buttons">
+ <div class="pager_left_button" id="stemma_pager_left_button"></div>
+ <div class="pager_right_button" id="stemma_pager_right_button"></div>
+ </div>
+ </form>
+ <form id="stemma_root_form" action="" method="GET" name="start_root_stemma">
+ <div class="button" id="stemma_root_button"
+ onClick="TODO">
+ <span>Choose a root for this stemma</span>
+ </div>
+ </form>
+ <form id="stemma_root_cancel" action="" method="GET" name="stemma_root_cancel">
+ <div class="button" id="stemma_root_cancel_button"
+ onClick="TODO">
+ <span>Cancel root selection</span>
+ </div>
+ </form>
+ <form id="stemma_add_form" action="" method="GET" name="stemma_add_form">
+ <div class="button" id="add_stemma_button"
+ onClick="add_selected_stemma()">
+ <span>Add this stemma to the tradition</span>
+ </div>
+ </form>
+ </div>
+ <div id="stemma_graph"></div>
+ </div>
+
+ <!-- Interim 'loading' message for directory box -->
+ <div id="loading_message">
+ <h3>Calculating text phylogeny, please wait...</h3>
+ <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition list..."/>
+ </div>
+
+[% PROCESS footer.tt %]
\ No newline at end of file
use_ok( 'Text::Tradition::Stemma' );
# Try to create a bad graph
+TODO: {
+ local $TODO = "cannot use stdout redirection trick with FastCGI";
my $baddotfh;
-open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
-try {
- my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
- ok( 0, "Created broken stemma from dotfile with syntax error" );
-} catch( Text::Tradition::Error $e ) {
- like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
+ open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
+ try {
+ my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
+ ok( 0, "Created broken stemma from dotfile with syntax error" );
+ } catch( Text::Tradition::Error $e ) {
+ like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
+ }
}
# Create a good graph
$found_unicode_sigil = 1 if $h eq "\x{3b1}";
}
ok( $found_unicode_sigil, "Found a correctly encoded Unicode sigil" );
+
+# TODO Create stemma from graph, create stemma from undirected graph,
+# create stemma from incompletely-specified graph
}