当前位置: 首页>>代码示例>>PHP>>正文


PHP Tree::BuildWeights方法代码示例

本文整理汇总了PHP中Tree::BuildWeights方法的典型用法代码示例。如果您正苦于以下问题:PHP Tree::BuildWeights方法的具体用法?PHP Tree::BuildWeights怎么用?PHP Tree::BuildWeights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree::BuildWeights方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:56,代码来源:tkml.php

示例2: main


//.........这里部分代码省略.........
            $b = array();
            foreach ($data as $row) {
                $b[] = $row->label;
            }
            $filename = 'tmp/' . uniqid() . '.gml';
            $gml = create_graph($taxa, $b);
            file_put_contents($filename, $gml);
            //echo $gml;
            // Compute maximum weight bipartite matching
            $command = $matching_path . 'matching ' . $filename;
            $output = array();
            exec($command, $output);
            //echo $command;
            $json = join("", $output);
            //echo $json;
            $match = json_decode($json);
            if (0) {
                echo '<pre>';
                $n = count($taxa);
                foreach ($match->matching as $pair) {
                    echo $taxa[$pair[0]] . "|\t" . $b[$pair[1] - $n] . "\n";
                }
                echo '</pre>';
            }
            // Mapping between tree labels and table labels
            $match_by_label = array();
            $n = count($taxa);
            foreach ($match->matching as $pair) {
                $match_by_label[$taxa[$pair[0]]] = $b[$pair[1] - $n];
            }
            // match and build KML file
            $t = new Tree();
            $t->Parse($newick);
            $t->BuildWeights($t->GetRoot());
            //echo $newick;
            $ni = new NodeIterator($t->getRoot());
            $q = $ni->Begin();
            while ($q != NULL) {
                if ($q->IsLeaf()) {
                    $data = $data_lookup_by_label[$match_by_label[$q->GetLabel()]];
                    $q->SetAttribute('lat', $data->latlong['latitude']);
                    $q->SetAttribute('long', $data->latlong['longitude']);
                }
                $q = $ni->Next();
            }
            // KML...
            //echo '<pre>';
            //$t->Dump();
            //echo '</pre>';
            $kml = tree2kml($t);
            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 - Step 3</title>
   <script type="text/javascript" src="https://www.google.com/jsapi"> </script>
   <script type="text/javascript">
      var ge;
      google.load("earth", "1");

      function init() {
         google.earth.createInstance(\'map3d\', initCB, failureCB);
      }
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:66,代码来源:index.php

示例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();
            }
//.........这里部分代码省略.........
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:101,代码来源:tree2svg.php


注:本文中的Tree::BuildWeights方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。