CytoscapeをPHPで動かす

Pocket

perl から Cytoscape を扱えることはperlからCytoscapeを利用し、jpegに保存の通りできることがわかった
しかし、使う言語ってphpかCのどちらかなんですよね
皆さんはどうでしょう?
今回は perl で書かれていたサンプルプログラムをPHPにしてみました

ソースはこちら

<br />
&lt;?php</p>
<p>        require_once(&quot;XML/RPC2/Client.php&quot;);</p>
<p>        $options = array(<br />
                &quot;prefix&quot;        =&gt; &quot;Cytoscape.&quot;<br />
                );</p>
<p>        $client = XML_RPC2_Client::create(&quot;http://localhost:9000/Cytoscape&quot;,<br />
                                        $options<br />
                );</p>
<p>        $networkID = $client-&gt;createNetwork(&quot;PHP Test Network&quot;);</p>
<p>        $networkTitle = $client-&gt;getNetworkTitle((string)$networkID);</p>
<p>        print $networkTitle . &quot;\n&quot;;</p>
<p>        $done = $client-&gt;createNodes(array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;,&quot;g&quot;));</p>
<p>        print &quot;Done adding nodes.&quot;.&quot;\n&quot;;<br />
        $nrNodes = $client-&gt;countAllNodes();<br />
        print &quot;There are now &quot;. $nrNodes. &quot; nodes present in Cytoscape&quot;.&quot;\n&quot;;</p>
<p>        $done = $client-&gt;addNodeAttributes(<br />
                        &quot;str&quot;,<br />
                        &quot;STRING&quot;,<br />
                        array(<br />
                                'a' =&gt; 'aa',<br />
                                'b' =&gt; 'aa',<br />
                                'c' =&gt; 'bb',<br />
                                'd' =&gt; 'ee',<br />
                                'e' =&gt; 'cc',<br />
                                'f' =&gt; 'cc',<br />
                                'g' =&gt; 'cc'<br />
                        ),<br />
                        true<br />
                );</p>
<p>        $done = $client-&gt;addNodeAttributes(<br />
                        &quot;nr&quot;,<br />
                        &quot;FLOATING&quot;,<br />
                        array(<br />
                                &quot;a&quot;     =&gt;      1.10,<br />
                                &quot;b&quot;     =&gt;      2.10,<br />
                                &quot;c&quot;     =&gt;      3.10,<br />
                                &quot;d&quot;     =&gt;      4.10,<br />
                                &quot;e&quot;     =&gt;      5.10,<br />
                                &quot;f&quot;     =&gt;      6.10,<br />
                                &quot;g&quot;     =&gt;      7.10<br />
                        ),<br />
                        true<br />
                );</p>
<p>        print &quot;Adding edges.&quot;.&quot;\n&quot;;</p>
<p>        $from = array(&quot;b&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;d&quot;, &quot;d&quot;, &quot;d&quot;);<br />
        $to =   array(&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;);<br />
        $type = array(&quot;relation&quot;,&quot;relation&quot;,&quot;relation&quot;,&quot;relation&quot;,&quot;relation&quot;,&quot;relation&quot;,&quot;relation&quot;);</p>
<p>        $directed = array(true,true,true,true,true,true,true);</p>
<p>        $edge_ids = $client-&gt;createEdges(<br />
                        (string)$networkID,<br />
                        $from,<br />
                        $to,<br />
                        $type,<br />
                        $directed,<br />
                        true<br />
                );</p>
<p>        print &quot;Done adding edges.&quot; . &quot;\n&quot;;</p>
<p>        $nrEdges = $client-&gt;countAllEdges();</p>
<p>        print &quot;There are now &quot; . $nrEdges . &quot; edges present in Cytoscape.&quot; . &quot;\n&quot;;</p>
<p>        $edge_attrs = array();<br />
        foreach( $edge_ids as $edge) {<br />
                $edge_attrs[$edge] = (int)(rand(0,99));<br />
        }</p>
<p>        /*<br />
        $done = $client-&gt;addIntegerEdgeAttributes(<br />
                        &quot;integer&quot;,<br />
                        $edge_ids,<br />
                        array_values($edge_attrs)<br />
                );<br />
        */</p>
<p>        $done = $client-&gt;addEdgeAttributes(<br />
                        &quot;integer_attribute&quot;,<br />
                        &quot;INTEGER&quot;,<br />
                        $edge_attrs<br />
        );</p>
<p>        // Set node selection<br />
        $done = $client-&gt;setSelectedNodes(<br />
                        $from<br />
                );</p>
<p>        // Get a list of the selected nodes<br />
        print &quot;calling getSelectedNodes...&quot;;<br />
        $out = $client-&gt;getSelectedNodes();<br />
        print_r( $out);</p>
<p>        // Perform force-directed Layout<br />
        // Take a look at the possible layouts with: getLayoutNames<br />
        $done = $client-&gt;performLayout(<br />
                        (string)$networkID,<br />
                        &quot;force-directed&quot;<br />
                );</p>
<p>        // Set another attribute as the node label<br />
        /*<br />
        $done = $client-&gt;setNodeLabel(<br />
                        (string)$netowrkID,<br />
                        &quot;str&quot;,<br />
                        &quot;defaultvalue&quot;,<br />
                        &quot;default&quot;<br />
                );<br />
        */</p>
<p>        //Force a redraw of the current network<br />
        $done = $client-&gt;redraw();</p>
<p>        //Set the shapes of the nodes based on another attribute<br />
        $done = $client-&gt;discreteMapper(<br />
                        (string)$networkID,<br />
                        &quot;default&quot;,<br />
                        &quot;str&quot;,<br />
                        &quot;Node Shape&quot;,<br />
                        &quot;triangle&quot;,<br />
                        array(<br />
                                'aa' =&gt; 'hexagon',<br />
                                'bb' =&gt; 'ellipse',<br />
                                'cc' =&gt; 'rect'<br />
                        )<br />
                );</p>
<p>        $done = $client-&gt;createContinuousNodeVisualStyle(<br />
                        &quot;nr&quot;,<br />
                        &quot;Node Color&quot;,<br />
                        array(2.1, 2.51, 7.3, 8.2),<br />
                        array('0F0FFF', '#0FFF0A', '#FF000A', '#0F000A', '#A000F0', '#AAFA0A')<br />
                );</p>
<p>        $done = $client-&gt;exportView(<br />
                        (string)$networkID,<br />
                        &quot;/tmp/hoge.jpg&quot;,<br />
                        &quot;jpg&quot;,<br />
                        2.0<br />
        );</p>
<p>        print &quot;\n&quot;;<br />
?&gt;<br />

当初、実行したら下のようなエラーが出てexportView() の所が動かなかった

<br />
PHP Fatal error:  Uncaught exception 'XML_RPC2_FaultException' with message 'No method matching arguments: java.lang.String, java.lang.String, java.lang.String, java.lang.String' in /usr/share/pear/XML/RPC2/Backend/Xmlrpcext/Client.php:126<br />
Stack trace:<br />
#0 [internal function]: XML_RPC2_Backend_Xmlrpcext_Client-&gt;remoteCall___('exportView', Array)<br />
#1 /usr/share/pear/XML/RPC2/Client.php(256): call_user_func_array(Array, Array)<br />
#2 /home/hoge/cytoscape.php(156): XML_RPC2_Client-&gt;__call('exportView', Array)<br />
#3 /home/hoge/cytoscape.php(156): XML_RPC2_Backend_Xmlrpcext_Client-&gt;exportView('15', '/tmp/hoge.jpg', 'jpg', '2.0')<br />
#4 {main}<br />
  thrown in /usr/share/pear/XML/RPC2/Backend/Xmlrpcext/Client.php on line 126<br />

exportView() の 2.0 の所を下のようにダブルクォートで囲っていた

<br />
        $done = $client-&gt;exportView(<br />
                        (string)$networkID,<br />
                        &quot;/tmp/hoge.jpg&quot;,<br />
                        &quot;jpg&quot;,<br />
                        &quot;2.0&quot;<br />
        );<br />

perl の方は動いてたので、perl.pl を実行してwireshark でパケット見てみた
exportView() のリクエストで 2.0 がdoubleタグで囲まれてた
phpのソースから exportView() の 2.0 についてたダブルクォート抜いたら動いたよ

コメントを残す