00001 #include "log.h"
00002 #include "format.h"
00003 #include "html.h"
00004 #include "htmlLinker.h"
00005 #include "gfr.h"
00006 #include "geneFusionsConfig.h"
00007 #include "linestream.h"
00008 #include "stringUtil.h"
00009
00010
00011
00012 static char* processString (char *str)
00013 {
00014 static Stringa buffer = NULL;
00015 Texta tokens;
00016 int i;
00017
00018 if (!strchr (str,'|')) {
00019 return str;
00020 }
00021 stringCreateClear (buffer,100);
00022 tokens = textStrtokP (str,"|");
00023 for (i = 0; i < arrayMax (tokens); i++) {
00024 stringAppendf (buffer,"%s%s",textItem (tokens,i),i < arrayMax (tokens) - 1 ? "<br>" : "");
00025 }
00026 return string (buffer);
00027 }
00028
00029
00030
00031 static void generateOutput (char* prefix, char* typeSelected, int minNum)
00032 {
00033 GfrEntry *currGE;
00034 Stringa buffer;
00035 char *pos;
00036
00037 puts ("<html>");
00038 puts ("<head>");
00039 puts ("<title>Results - Gene Fusions</title>");
00040 html_printGenericStyleSheet (12);
00041 puts ("</head>");
00042 puts ("<body>");
00043 if (prefix[0] == '\0') {
00044 die ("Invalid prefix");
00045 }
00046 printf ("<h1>Results - %s</h1><br><br><br>",prefix);
00047
00048 buffer = stringCreate(50);
00049
00050 LineStream ls;
00051 char* chrSignal=NULL;
00052 stringPrintf(buffer, "ls -1 %s/BGRS/%s_chr*.bgr.gz 2> /dev/null", WEB_DATA_DIR,prefix);
00053 ls = ls_createFromPipe( string( buffer ) );
00054 int countCol = 0;
00055 puts ("Expression signal: ");
00056 fflush(stdout);
00057 while( chrSignal = ls_nextLine( ls ) ) {
00058
00059 char* chrTmp = stringBetween( prefix, ".bgr.gz", chrSignal );
00060 chrTmp++;
00061 printf ("[<a href=%s&hgt.customText=%s/BGRS/%s_%s.bgr.gz target='blank'>%s</a>] ",
00062 htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human", chrTmp, UCSC_GENOME_BROWSER_FLANKING_REGION, 50000000 + UCSC_GENOME_BROWSER_FLANKING_REGION),
00063 WEB_DATA_LINK, prefix, chrTmp, chrTmp);
00064 if(countCol>10) {
00065 puts( "<BR>" );
00066 countCol=0;
00067 }
00068 countCol++;
00069 }
00070 if( countCol==0) puts( "No data available yet" );
00071 ls_destroy(ls);
00072 puts ("<br><br>");
00073 puts ("For a definition of SPER, DASPER and RESPER see <a href=http://rnaseq.gersteinlab.org/fusionseq/>FusionSeq</a>");
00074 puts ("<br><br>");
00075 puts ("<br><table border=0 width=100% align=center cellpadding=10>");
00076 puts ("<tr align=left>");
00077 puts ("<th>SPER</th>");
00078 puts ("<th>DASPER</th>");
00079 puts ("<th>RESPER</th>");
00080 puts ("<th>Number of inter paired-end reads</th>");
00081 puts ("<th>Type</th>");
00082 puts ("<th>Genomic coordinates</th>");
00083 puts ("<th>Gene symbol</th>");
00084 puts ("<th>Description</th>");
00085 puts ("<th>Genomic coordinates</th>");
00086 puts ("<th>Gene symbol</th>");
00087 puts ("<th>Description</th>");
00088 puts ("<th></th>");
00089 puts ("</tr>");
00090 fflush(stdout);
00091
00092 stringPrintf (buffer,"%s/%s.gfr",WEB_DATA_DIR,prefix);
00093 gfr_init (string (buffer));
00094 int countElements = 0;
00095 while (currGE = gfr_nextEntry ()) {
00096 if (currGE->numInter < minNum) {
00097 continue;
00098 }
00099 if (strEqual (typeSelected,"all") || strEqual (currGE->fusionType,typeSelected) ||
00100 ( strEqual(currGE->fusionType,"cis") && strEqual( typeSelected,"same") ) ||
00101 ( strEqual(currGE->fusionType,"read-through") && strEqual( typeSelected,"same") ) ) {
00102 if (pos = strchr (currGE->descriptionTranscript1,'|')) {
00103 *pos = '\0';
00104 }
00105 if (pos = strchr (currGE->descriptionTranscript2,'|')) {
00106 *pos = '\0';
00107 }
00108 puts ("<tr>");
00109 printf ("<td align=left>%1.3f</td>\n",currGE->SPER);
00110 printf ("<td align=left>%1.3f</td>\n",currGE->DASPER);
00111 printf ("<td align=left>%1.3f</td>\n",currGE->RESPER);
00112 printf ("<td align=left>%d</td>\n",currGE->numInter);
00113 printf ("<td align=left>%s</td>\n",currGE->fusionType);
00114 printf ("<td align=left><a href=%s target=blank>%s:%d-%d</a></td>\n",
00115 htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",currGE->chromosomeTranscript1,currGE->startTranscript1 - UCSC_GENOME_BROWSER_FLANKING_REGION,currGE->endTranscript1 + UCSC_GENOME_BROWSER_FLANKING_REGION),
00116 currGE->chromosomeTranscript1,currGE->startTranscript1,currGE->endTranscript1);
00117 printf ("<td align=left>%s</td>\n",processString (currGE->geneSymbolTranscript1));
00118 printf ("<td align=left>%s</td>\n",currGE->descriptionTranscript1);
00119 printf ("<td align=left><a href=%s target=blank>%s:%d-%d</a></td>\n",
00120 htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",currGE->chromosomeTranscript2,currGE->startTranscript2 - UCSC_GENOME_BROWSER_FLANKING_REGION,currGE->endTranscript2 + UCSC_GENOME_BROWSER_FLANKING_REGION),
00121 currGE->chromosomeTranscript2,currGE->startTranscript2,currGE->endTranscript2);
00122 printf ("<td align=left>%s</td>\n",processString (currGE->geneSymbolTranscript2));
00123 printf ("<td align=left>%s</td>\n",currGE->descriptionTranscript2);
00124 printf ("<td align=left><a href=%s/showDetails_cgi?%s+%s>Details</a></td>\n",WEB_URL_CGI,prefix,currGE->id);
00125 puts ("</tr>");
00126 countElements++;
00127 }
00128 }
00129 gfr_deInit ();
00130 stringDestroy (buffer);
00131 puts ("</table><br><br>");
00132 if( countElements == 0) puts("No fusion candidates can be found satisfying all specified criteria.");
00133 puts ("</body>");
00134 puts ("</html>");
00135 fflush (stdout);
00136 }
00137
00138
00139
00140 int main (int argc, char *argv[])
00141 {
00142 char *queryString;
00143
00144 cgiInit();
00145 cgiHeader("text/html");
00146 queryString = cgiGet2Post();
00147 if (queryString[0] == '\0') {
00148 puts ("<html>");
00149 puts ("<head>");
00150 html_printGenericStyleSheet (12);
00151 puts ("<title>geneFusions</title>\n");
00152 puts ("</head>");
00153 puts ("<body>");
00154 puts ("<h1>Identification of potential gene fusions using paired-end reads</h1><br><br>");
00155 printf ("<form action=%s/geneFusions_cgi method=get>",WEB_URL_CGI);
00156 puts ("<b>Data prefix</b>: ");
00157 puts ("<input type=text name=prefix>");
00158 puts ("<br><br><br>");
00159 puts ("<b>Minimum number of paired-end reads connecting two genes</b>: ");
00160 puts ("<select name=minNum>");
00161 puts ("<option value=2>2");
00162 puts ("<option value=3>3");
00163 puts ("<option value=5 selected>5");
00164 puts ("<option value=10>10");
00165 puts ("</select>");
00166 puts ("<br><br><br>");
00167 puts ("<b>Type of gene fusion</b>: ");
00168 puts ("<select name=type>");
00169 puts ("<option value=read-through>Read-through events");
00170 puts ("<option value=cis>Cis events");
00171 puts ("<option value=intra>Intra-chromosomal events");
00172 puts ("<option value=same>Genes on the same chromosome");
00173 puts ("<option value=inter>Genes on different chromosomes");
00174 puts ("<option value=all selected>All potential gene fusions");
00175 puts ("</select>");
00176 puts ("<br><br><br>");
00177 puts ("<input type=submit value=Submit>");
00178 puts ("<input type=reset value=Reset>");
00179 puts ("</form>");
00180 puts ("</body>");
00181 puts ("</html>");
00182 fflush (stdout);
00183 }
00184 else {
00185 int first;
00186 Stringa item = stringCreate (20);
00187 Stringa value = stringCreate (20);
00188 char *iPtr,*vPtr,*prefix,*type;
00189 int minNum;
00190
00191 first = 1;
00192 cgiGetInit ();
00193 while (cgiGetNextPair (&first,item,value)) {
00194 iPtr = string (item);
00195 vPtr = string (value);
00196 if (strEqual (iPtr,"prefix")) {
00197 prefix = hlr_strdup (vPtr);
00198 }
00199 if (strEqual (iPtr,"type")) {
00200 type = hlr_strdup (vPtr);
00201 }
00202 if (strEqual (iPtr,"minNum")) {
00203 minNum = atoi (vPtr);
00204 }
00205 }
00206 generateOutput (prefix,type,minNum);
00207 }
00208 return 0;
00209 }