| 1 | package Bio::Phylo::Unparsers::Html; | ||
| 2 | use strict; | ||
| 3 | use base 'Bio::Phylo::Unparsers::Abstract'; | ||
| 4 | use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :objecttypes'; | ||
| 5 | use Bio::Phylo::Util::Exceptions 'throw'; | ||
| 6 | use Bio::Phylo::Util::Dependency qw'Template'; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Bio::Phylo::Unparsers::Html - Serializer used by Bio::Phylo::IO, no serviceable | ||
| 11 | parts inside | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | This module creates an HTML representation of the provided project | ||
| 16 | |||
| 17 | =begin comment | ||
| 18 | |||
| 19 | Type : Wrapper | ||
| 20 | Title : _to_string | ||
| 21 | Usage : my $json_string = $obj->_to_string; | ||
| 22 | Function: Stringifies a Bio::Phylo object into an HTML string | ||
| 23 | Alias : | ||
| 24 | Returns : SCALAR | ||
| 25 | Args : Bio::Phylo::* object | ||
| 26 | |||
| 27 | =end comment | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub _to_string { | ||
| 32 | my $self = shift; | ||
| 33 | my $obj = $self->{'PHYLO'}; | ||
| 34 | if ( $obj->_type == _PROJECT_ ) { | ||
| 35 | my $result; | ||
| 36 | my $template = $self->{'TEMPLATE'} || \*DATA; | ||
| 37 | my $tt = Template->new; | ||
| 38 | $tt->process($template,{'proj' => $obj},\$result); | ||
| 39 | return $result; | ||
| 40 | } | ||
| 41 | else { | ||
| 42 | throw 'ObjectMismatch' => "Can't make HTML string out of $obj"; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | # podinherit_insert_token | ||
| 47 | |||
| 48 | =head1 SEE ALSO | ||
| 49 | |||
| 50 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||
| 51 | for any user or developer questions and discussions. | ||
| 52 | |||
| 53 | =over | ||
| 54 | |||
| 55 | =item L<Bio::Phylo::IO> | ||
| 56 | |||
| 57 | The html unparser is called by the L<Bio::Phylo::IO> object. | ||
| 58 | Look there to learn how to unparse objects. | ||
| 59 | |||
| 60 | =item L<Bio::Phylo::Manual> | ||
| 61 | |||
| 62 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||
| 63 | |||
| 64 | =back | ||
| 65 | |||
| 66 | =head1 CITATION | ||
| 67 | |||
| 68 | If you use Bio::Phylo in published research, please cite it: | ||
| 69 | |||
| 70 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||
| 71 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||
| 72 | I<BMC Bioinformatics> B<12>:63. | ||
| 73 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | 1; | ||
| 78 | |||
| 79 | __DATA__ | ||
| 80 | <html> | ||
| 81 | <head> | ||
| 82 | <title> | ||
| 83 | [% IF proj.get_name %] | ||
| 84 | [% proj.get_name %] | ||
| 85 | [% END %] | ||
| 86 | </title> | ||
| 87 | </head> | ||
| 88 | <body> | ||
| 89 | <img src="http://www.evoio.org/wg/evoio/images/f/f1/Phylotastic_logo.png"/> | ||
| 90 | <h1>Document</h1> | ||
| 91 | [% PROCESS identifiable obj = proj, tag = "h2" %] | ||
| 92 | |||
| 93 | <!-- process taxa blocks, if any --> | ||
| 94 | [% IF proj.get_taxa.size > 0 %] | ||
| 95 | <h1>Taxa</h1> | ||
| 96 | <!-- iterate over each taxa block --> | ||
| 97 | <ul> | ||
| 98 | [% FOREACH taxa = proj.get_taxa %] | ||
| 99 | <li> | ||
| 100 | |||
| 101 | <!-- write taxa block metadata --> | ||
| 102 | [% PROCESS identifiable obj = taxa, tag = "h2" %] | ||
| 103 | <h3>Number of taxa: [% taxa.get_ntax %]</h3> | ||
| 104 | |||
| 105 | <!-- write taxon contents --> | ||
| 106 | <ul> | ||
| 107 | [% FOREACH taxon = taxa.get_entities %] | ||
| 108 | [% PROCESS identifiable obj = taxon, tag = "li" %] | ||
| 109 | [% END %] | ||
| 110 | </ul> | ||
| 111 | </li> | ||
| 112 | [% END %] | ||
| 113 | </ul> | ||
| 114 | [% END %] | ||
| 115 | |||
| 116 | <!-- process characters blocks, if any --> | ||
| 117 | [% IF proj.get_matrices.size > 0 %] | ||
| 118 | <h1>Characters</h1> | ||
| 119 | <!-- iterate over each characters block --> | ||
| 120 | [% FOREACH matrix = proj.get_matrices %] | ||
| 121 | |||
| 122 | <!-- write characters block metadata --> | ||
| 123 | [% PROCESS identifiable obj = matrix, tag = "h2" %] | ||
| 124 | <ul> | ||
| 125 | <li>Data type: [% matrix.get_type %]</li> | ||
| 126 | <li>Number of taxa: [% matrix.get_ntax %]</li> | ||
| 127 | <li>Number of characters: [% matrix.get_nchar %]</li> | ||
| 128 | <li>Taxa block: | ||
| 129 | <a href="#[% matrix.get_taxa.get_xml_id %]"> | ||
| 130 | [% matrix.get_taxa.get_internal_name %] | ||
| 131 | </a> | ||
| 132 | <li> | ||
| 133 | </ul> | ||
| 134 | |||
| 135 | <!-- write datum contents --> | ||
| 136 | <table> | ||
| 137 | [% FOREACH datum = matrix.get_entities %] | ||
| 138 | <tr> | ||
| 139 | <td> | ||
| 140 | [% PROCESS identifiable obj = datum, tag = "h3" %] | ||
| 141 | </td> | ||
| 142 | <td> | ||
| 143 | <pre>[% datum.get_char %]</pre> | ||
| 144 | </td> | ||
| 145 | </tr> | ||
| 146 | [% END %] | ||
| 147 | <table> | ||
| 148 | [% END %] | ||
| 149 | [% END %] | ||
| 150 | |||
| 151 | <!-- process trees blocks, if any --> | ||
| 152 | [% IF proj.get_forests.size > 0 %] | ||
| 153 | <h1>Trees</h1> | ||
| 154 | <!-- iterate over each trees block --> | ||
| 155 | [% FOREACH forest = proj.get_forests %] | ||
| 156 | |||
| 157 | <!-- write trees block metadata --> | ||
| 158 | [% PROCESS identifiable obj = forest, tag = "h2" %] | ||
| 159 | |||
| 160 | <!-- write trees block contents --> | ||
| 161 | [% FOREACH tree = forest.get_entities %] | ||
| 162 | [% PROCESS identifiable obj = tree, tag = "h3" %] | ||
| 163 | <pre>[% tree.to_newick %]</pre> | ||
| 164 | [% END %] | ||
| 165 | [% END %] | ||
| 166 | [% END %] | ||
| 167 | </body> | ||
| 168 | </html> | ||
| 169 | |||
| 170 | [% BLOCK identifiable %] | ||
| 171 | <[% tag %] id="[% obj.get_xml_id %]" class="[% obj.get_tag %]"> | ||
| 172 | <a name="[% obj.get_xml_id %]"> | ||
| 173 | [% IF obj.get_name %] | ||
| 174 | [% obj.get_name %] | ||
| 175 | [% END %] | ||
| 176 | </a> | ||
| 177 | </[% tag %]> | ||
| 178 | [% PROCESS annotatable %] | ||
| 179 | [% END %] | ||
| 180 | |||
| 181 | [% BLOCK annotatable %] | ||
| 182 | [% IF obj.get_meta.size > 0 %] | ||
| 183 | <ul> | ||
| 184 | [% FOREACH meta = obj.get_meta %] | ||
| 185 | <li id="[% meta.get_xml_id %]" class="[% meta.get_tag %]"> | ||
| 186 | <a href="[% meta.get_predicate_namespace %][% meta.get_predicate_local %]" class="predicate"> | ||
| 187 | [% meta.get_predicate %] | ||
| 188 | </a> = | ||
| 189 | [% IF meta.is_resource %] | ||
| 190 | [% IF meta.is_xml_literal %] | ||
| 191 | <pre class="xml_literal">[% meta.get_object %]</pre> | ||
| 192 | [% ELSE %] | ||
| 193 | <a href="[% meta.get_object %]" rel="[% meta.get_predicate %]" class="resource"> | ||
| 194 | [% meta.get_object %] | ||
| 195 | </a> | ||
| 196 | [% END %] | ||
| 197 | [% ELSE %] | ||
| 198 | <span class="[% meta.get_object_type %]">[% meta.get_object %]</span> | ||
| 199 | [% END %] | ||
| 200 | [% PROCESS annotatable obj = meta %] | ||
| 201 | </li> | ||
| 202 | [% END %] | ||
| 203 | </ul> | ||
| 204 | [% END %] | ||
| 205 | [% END %] |