File: ctc.php

package info (click to toggle)
r-bioc-ctc 1.80.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 452 kB
  • sloc: php: 52; makefile: 2
file content (178 lines) | stat: -rw-r--r-- 4,478 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php

/*
   This program is a sample to use R and ctc as a web application.

   Standard setup: 
   put ctc.php in your public_html directory
   check that webserver user (apache, or www) is able
   to write in public_html (chmod 'a+w' ~/public_html)

   Change global variable R_BIN below

   That's all.

   Example working:
   http://bioinfo.genopole-toulouse.prd.fr/~lucas/ctc.php

 */ 

/*  Some globals variables */


$R_BIN = "R";   // "/usr/bin/R";
$MAX_FILE = 307200;  // 300 Ko
/* End of personalization */
?>


<html>
<header>
<title>Ctc Demo Web application V0-1</title>
</header>
<body>
<center>
<p>
<b>This demo makes hierarchical clustering on your data</b>

<?php 


/* and ID made by TIME + Process_ID  */
$ID = "tmp_".time().getmypid();


/* Print form  */
if ($_POST[page] != "Exec") 
  {

    ?>
    <p>
    Upload your data (text-tabulated file)
    <form 
      action="ctc.php"
      enctype="multipart/form-data"   
      method="POST"
    >
      <INPUT TYPE = hidden  NAME=page value="Exec"></input>
      <INPUT type="file" name="FileData" />
      <p>
      File Description:
      <table><tr>
      <td>A first Column</td><td>
        <SELECT NAME=rownames>
           <OPTION SELECTED  VALUE = "1">with labels
           <OPTION VALUE = "NULL">with data
        </SELECT>
      </td></tr>
      <tr><td>
      A first line</td><td>
        <SELECT NAME=header>
           <OPTION SELECTED  VALUE = TRUE>with columns header
           <OPTION VALUE = FALSE>with data
        </SELECT>
         </td></tr></table>


      <INPUT TYPE=SUBMIT VALUE="Submit" name="GO">
    </form>    
    <?php
  }
else
{


   mkdir($ID,0777);

   $HEADER = $_POST[header];
   $ROWNAMES = $_POST[rownames];


   /* Get upload data */
   if(is_uploaded_file ($_FILES['FileData']['tmp_name'] ))
     {
       move_uploaded_file ($_FILES['FileData']['tmp_name'],$ID."/data.txt");
       $taillefichier = filesize($ID."/data.txt");
       if($taillefichier>$MAX_FILE)
	 exit("File size: $taillefichier; max allowed: $MAX_FILE");
     }



   /* ================================== */
   /* We write R code in file $ID/prog.R */
   /* ================================== */

   $fp=fopen("$ID/prog.R",'w');

   fwrite($fp,"library(ctc)\n");


   /* Read Data */
   fwrite($fp,"data <- read.delim('$ID/data.txt',header=$HEADER,row.names=$ROWNAMES) \n" );


   fwrite($fp,"data                                        \n"); 


   /* Hierarchical clustering */
   fwrite($fp,"hr <- hclust(dist(data))                     \n");
   fwrite($fp,"hc <- hclust(dist(t(data)))                  \n");
   fwrite($fp,"dr <- as.dendrogram(hr)                      \n");
   fwrite($fp,"dc <- as.dendrogram(hc)                      \n");

   /* A pdf file */
   fwrite($fp,"pdf(file='$ID/Rplots.pdf')                        \n");
   fwrite($fp,"heatmap(as.matrix(data),Colv=dc,Rowv=dr)          \n"); 
   fwrite($fp,"dev.off()                                         \n");

   /* Some png images */
   fwrite($fp,"bitmap(file='$ID/heatmap.png')                    \n");
   fwrite($fp,"heatmap(as.matrix(data),Colv=dc,Rowv=dr)          \n");
   fwrite($fp,"dev.off()                                         \n");


   fwrite($fp,"r2atr(hc,file='$ID/cluster.atr')                  \n");
   fwrite($fp,"r2gtr(hr,file='$ID/cluster.gtr')                  \n");
   fwrite($fp,"r2cdt(hr,hc,data ,file='$ID/cluster.cdt')         \n");


   fclose($fp);


   /* ===================== */
   /* Send command (R batch)*/
   /* ===================== */
   system("$R_BIN --no-save < $ID/prog.R > $ID/prog.R.out  2> $ID/prog.R.warnings");
 

   /* ===================================== */
   /* We create html page including results */
   /* ===================================== */


   echo "<h3>Ctc Demo results </h3>";
   echo "<a href=$ID/Rplots.pdf>A pdf file</a><p>";
   echo "3 files for <a href=http://magix.fri.uni-lj.si/freeview/>Freeview</a>";
   echo " or <a href=http://rana.lbl.gov/>Treeview</a>: ";
   echo "<a href=$ID/cluster.cdt>cdt</a> ";
   echo "<a href=$ID/cluster.atr>atr</a> ";
   echo "<a href=$ID/cluster.gtr>gtr</a> ";
   echo "<p>";
   echo "<img src=$ID/heatmap.png></img><p>";
   /* Signature  */

   echo "<p>This results made by <a
href='http://www.bioconductor.org/'>ctc
package</a>. Code use: <a href='$ID/prog.R'>prog.R</a>, 
Out: <a href='$ID/prog.R.out'>prog.R.out</a>,
Warnings: <a href='$ID/prog.R.warnings'>prog.R.warnings</a>.";

}
?>



</center>
</body>
</html>