本文整理汇总了PHP中Tree::getRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP Tree::getRoot方法的具体用法?PHP Tree::getRoot怎么用?PHP Tree::getRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree::getRoot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tree2kml
function tree2kml($obj, $default_labels = 'taxa')
{
$t = new Tree();
$t->Parse($obj->tree->newick);
$t->BuildWeights($t->GetRoot());
// compute KML coordinates
$attr = array();
$td = new KmlTreeDrawer($t, $attr);
$td->CalcCoordinates();
// raw labels (OTUs)
// $port->StartGroup('otu', (('otu' == $default_labels) || !isset($obj->translations)) );
$kml = '';
$kml .= "<?xml version =\"1.0\" encoding=\"UTF-8\"?>\n";
$kml .= "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n";
$kml .= "<Document>\n";
$kml .= "<Style id=\"treeLine\">\n";
$kml .= "<LineStyle><color>7fffffff</color><width>2</width></LineStyle>\n";
$kml .= "</Style>\n";
$kml .= "<Style id=\"whiteBall\">\n";
$kml .= "<IconStyle>\n";
$kml .= "<Icon>\n";
$kml .= "<href>http://iphylo.org/~rpage/phyloinformatics/images/whiteBall.png</href>\n";
$kml .= "</Icon>\n";
$kml .= "</IconStyle>\n";
$kml .= "<LineStyle>\n";
$kml .= "<width>2</width>\n";
$kml .= "</LineStyle>\n";
$kml .= "</Style>\n";
$td->Draw(null);
$kml .= $td->kml;
$kml .= "<Folder>\n";
$kml .= "<name>Labels</name>\n";
// labels
$ni = new NodeIterator($t->getRoot());
$q = $ni->Begin();
while ($q != NULL) {
if ($q->IsLeaf()) {
$kml .= "<Placemark>\n";
$kml .= "<name>" . $q->Getlabel() . "</name>\n";
$kml .= "<styleUrl>#whiteBall</styleUrl>\n";
$kml .= "<Point>\n";
$kml .= "<altitudeMode>absolute</altitudeMode>\n";
$kml .= "<extrude>1</extrude>\n";
$kml .= "<coordinates>\n";
$kml .= $q->GetAttribute('long') . "," . $q->GetAttribute('lat') . "," . $q->GetAttribute('altitude') . "\n";
$kml .= "</coordinates>\n";
$kml .= "</Point>\n";
$kml .= "</Placemark>\n";
}
$q = $ni->Next();
}
$kml .= "</Folder>\n";
$kml .= "</Document>\n";
$kml .= "</kml>\n";
echo $kml;
}
示例2: main
function main()
{
global $matching_path;
$have_tree = false;
$have_taxa = false;
$have_table = false;
$newick = '';
if (isset($_POST['tree'])) {
$obj = parse_nexus(stripcslashes($_POST['tree']));
$taxa = get_taxa_from_tree($obj);
$newick = $obj->tree->newick;
//echo $newick;
//print_r($obj);
$t = new Tree();
$t->Parse($newick);
$ni = new NodeIterator($t->getRoot());
$q = $ni->Begin();
while ($q != NULL) {
if ($q->IsLeaf()) {
if (isset($obj->translations->translate)) {
$q->SetLabel($obj->translations->translate[$q->GetLabel()]);
}
}
$q = $ni->Next();
}
$newick = $t->WriteNewick();
//echo $newick;
$have_tree = true;
}
if (isset($_POST['taxa'])) {
$have_taxa = true;
}
if (isset($_POST['table'])) {
$table = $_POST['table'];
$have_table = true;
}
if (isset($_POST['newick'])) {
$newick = $_POST['newick'];
}
if ($have_tree || $have_taxa) {
if ($have_table) {
// get taxa
$taxa = explode("\n", stripcslashes($_POST['taxa']));
$n = count($taxa);
for ($i = 0; $i < $n; $i++) {
$taxa[$i] = trim($taxa[$i]);
}
// get table data
$table = stripcslashes($_POST['table']);
// Interpret table automatically...
// assume column one contains OTUs, and some other column(s) have lat and long
$data = extract_table($table);
//print_r($data);
if (count($taxa) != count($data)) {
echo '<html>
<head>
<meta charset="utf-8" />
<style type="text/css" title="text/css">
body { font-family:sans-serif;padding:20px; }
</style>
<title>Create KML tree - Error</title>
</head>
<body>
<a href=".">Back</a>
<h1>Error</h1>
<p>The number of taxa in the tree (' . count($taxa) . ') does not match the number in the table (' . count($data) . ')</p>
</body>
</html>';
exit;
}
$data_lookup_by_label = array();
foreach ($data as $d) {
$data_lookup_by_label[$d->label] = $d;
}
// show matching...
/*
echo ' <form method="post" action=".">
<table border="1">';
echo '<tr><th>Taxa in tree</th><th>Taxa in table</th><th>Latitude</th><th>Longitude</th></tr>';
$nrows = count($data);
for ($i=0;$i < $nrows; $i++)
{
echo '<tr>';
echo '<td>' . $taxa[$i] . '</td>';
echo '<td>' . $data[$i]->label . '</td>';
echo '<td>' . $data[$i]->latlong['latitude'] . '</td>';
echo '<td>' . $data[$i]->latlong['longitude'] . '</td>';
echo '</td></tr>';
}
echo '</table>
<input type="submit" value="Go"></input>
</form>';
//.........这里部分代码省略.........
示例3: tree2svg
/**
* @begin Draw tree and labels in SVG
*
* @param width Width (pixels) to draw tree + labels in
* @param height
* @param label_space Width (pixels) of space to draw leaf labels in
* @param font_height Height of font to use to draw labels
* @param default_labels Name of group of labels to show by default
*
*/
function tree2svg($obj, $width = 400, $height = 400, $label_space = 150, $font_height = 10, $force_height = false, $default_labels = 'taxa')
{
//----------------------------------------------------------------------------------------------
$t = new Tree();
$t->Parse($obj->tree->newick);
$t->BuildWeights($t->GetRoot());
$tree_width = $width - $label_space;
if (!$force_height) {
// adjust height to accomodate tree
$height = $t->GetNumLeaves() * ($font_height + $font_height / 3);
$inset = $font_height;
} else {
$inset = 0;
}
// Drawing properties
$attr = array();
$attr['inset'] = $inset;
$attr['width'] = $tree_width;
$attr['height'] = $height;
$attr['font_height'] = $font_height;
$attr['line_width'] = 1;
// Don't draw labels (we do this afterwards)
$attr['draw_leaf_labels'] = false;
$attr['draw_internal_labels'] = false;
$td = NULL;
if ($t->HasBranchLengths()) {
$td = new PhylogramTreeDrawer($t, $attr);
} else {
$td = new RectangleTreeDrawer($t, $attr);
}
$td->CalcCoordinates();
if (!$force_height) {
$port = new SVGPort('', $width, $td->max_height + $attr['font_height']);
} else {
$port = new SVGPort('', $width, $height + 2);
}
$port->StartGroup('tree');
$td->Draw($port);
$port->EndGroup();
// labels
if ($label_space > 0) {
$ni = new NodeIterator($t->getRoot());
// raw labels (OTUs)
$port->StartGroup('otu', 'otu' == $default_labels || !isset($obj->translations));
$q = $ni->Begin();
while ($q != NULL) {
if ($q->IsLeaf()) {
$p0 = $q->GetAttribute('xy');
$p0['x'] += $font_height / 3;
$text = $q->Getlabel();
$text = str_replace("_", " ", $text);
$action = 'onclick="node_info(\'' . htmlentities($text) . '\');"';
$port->DrawText($p0, $text, $action);
}
$q = $ni->Next();
}
$port->EndGroup();
if ($obj->translations) {
// Tree has a one or more translation tables
foreach ($obj->translations as $k => $v) {
// Draw labels as a separate group
$port->StartGroup($k, $k == $default_labels ? true : false);
$q = $ni->Begin();
while ($q != NULL) {
if ($q->IsLeaf()) {
$p0 = $q->GetAttribute('xy');
$p0['x'] += $font_height / 3;
$label = $q->Getlabel();
if (is_array($v)) {
if (isset($v[$label])) {
$label = $v[$label];
} else {
// No translation for this OTU
$label = '[' . $label . ']';
}
} else {
if (isset($v->{$label})) {
$label = $v->{$label};
} else {
// No translation for this OTU
$label = '[' . $label . ']';
}
}
$action = 'onclick="node_info(\'' . $q->Getlabel() . '\');"';
$port->DrawText($p0, $label, $action);
}
$q = $ni->Next();
}
$port->EndGroup();
}
//.........这里部分代码省略.........
示例4: get_panneaux_count_6
function get_panneaux_count_6($data,$keys)
{
$this->load->library('tree');
$result = array();
$tempRoot = '';
for($i = 0; $i < count($data[$keys[0]]); $i++)
{
if ($data[$keys[0]][$i] != $rootTemp)
{
$tree = new Tree();
$tree->addRoot($keys[0],$this->skip_caracters3($data[$keys[0]][$i]));
$tempRoot = $data[$keys[0]][$i];
}
for($j = 0; $j < count($data[$keys[1]]); $j++)
{
for($k = 0; $k < count($data[$keys[2]]); $k++)
{
for($l = 0; $l < count($data[$keys[3]]); $l++)
{
for($m = 0; $m < count($data[$keys[4]]); $m++)
{
for($n = 0; $n < count($data[$keys[5]]); $n++)
{
$where = "`" . $keys[0] . "` = '" . $this->skip_caracters3($data[$keys[0]][$i]) . "' AND `" . $keys[1] . "` = '" . $this->skip_caracters2($data[$keys[1]][$j]) . "' AND `" . $keys[2] . "` = '" . $this->skip_caracters2($data[$keys[2]][$k]) . "' AND `" . $keys[3] . "` = '" . $this->skip_caracters2($data[$keys[3]][$l]) . "' AND `" . $keys[4] . "` = '" . $this->skip_caracters2($data[$keys[4]][$m]) . "' AND `" . $keys[5] . "` = '" . $this->skip_caracters2($data[$keys[5]][$n]) . "'";
$nbre = $this->data_model->get_nbre_panneaux($where);
$res = $this->data_model->get_grp_panneaux($where);
$grp = $res[0]->grp;
$res = $this->data_model->get_tarif_panneaux($where);
$tarif = $res[0]->tarif;
$cout_grp = $tarif / $grp;
$cout_grp_moyen = $grp / $nbre;
$nbre_face = $this->data_model->get_nbre_face_panneaux($where);
$nbre_fixe = $this->data_model->get_nbre_fixe_panneaux($where);
$audience = $nbre_fixe / $nbre_face;
$visiblite = $nbre /$nbre_face;
if ($nbre > 0)
{
$pann[] = $this->data_model->get_panneaux($where);
$index1 = $tree->insertRootChild($keys[1],$this->skip_caracters3($data[$keys[1]][$j]));
$index2 = $tree->insertChild($keys[2],$this->skip_caracters3($data[$keys[2]][$k]),$tree->getRoot()->getChildAt($index1));
$index3 = $tree->insertChild($keys[3],$this->skip_caracters3($data[$keys[3]][$l]),$tree->getRoot()->getChildAt($index1)->getChildAt($index2));
$index4 = $tree->insertChild($keys[4],$this->skip_caracters3($data[$keys[4]][$m]),$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3));
$index5 = $tree->insertChild($keys[5],$this->skip_caracters3($data[$keys[5]][$n]),$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4));
$index6 = $tree->insertChild('nbre',$nbre,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5));
$index7 = $tree->insertChild('grp',$grp,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5)->getChildAt($index6));
$index8 = $tree->insertChild('cout_grp',$cout_grp,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5)->getChildAt($index6)->getChildAt($index7));
$index9 = $tree->insertChild('cout_grp_moyen',$cout_grp_moyen,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5)->getChildAt($index6)->getChildAt($index7)->getChildAt($index8));
$index10 = $tree->insertChild('audience',$audience,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5)->getChildAt($index6)->getChildAt($index7)->getChildAt($index8)->getChildAt($index9));
$tree->insertChild('visiblite',$visiblite,$tree->getRoot()->getChildAt($index1)->getChildAt($index2)->getChildAt($index3)->getChildAt($index4)->getChildAt($index5)->getChildAt($index6)->getChildAt($index7)->getChildAt($index8)->getChildAt($index9)->getChildAt($index10));
}
}
}
}
}
}
$this->data_model->set_panneaux($pann);
$result[] = $tree;
}
return $result;
}