00001
00002 #include "array.h"
00003 #include "log.h"
00004 #include "format.h"
00005 #include <stdlib.h>
00006 #include "numUtil.h"
00007 #include "mrf.h"
00008 #include "segmentationUtil.h"
00009
00010 #include "html.h"
00011 #include "htmlLinker.h"
00012 #include "geneFusionsConfig.h"
00013 #include "sqvUtil.h"
00014 #include "sqvWeb.h"
00015 #include "sqvCircos.h"
00016
00017 #define RFILTER_THOLD 2
00018 #define RFILTER_MAXGAP 5
00019 #define RFILTER_MINRUN 20
00020
00024 void validateMappedRead( Locus *mr ) {
00025 }
00026 static int containedLocus ( MrfEntry* query, Locus* target )
00027 {
00028 int overlap=0;
00029
00030 if( query->isPairedEnd ) {
00031 int i;
00032 for( i=0; i<arrayMax( (query->read1).blocks ); i++) {
00033 MrfBlock* qBlock = arrp( (query->read1).blocks, i, MrfBlock);
00034 if( !strcmp( qBlock->targetName, target->chromosome) ) {
00035 if( positiveRangeIntersection( qBlock->targetStart, qBlock->targetEnd, target->start, target->end ) > 0 ) {
00036 overlap = 1;
00037 i = arrayMax( (query->read1).blocks );
00038 }
00039 }
00040 }
00041 if( overlap == 0 ) {
00042 for( i=0; i<arrayMax( (query->read2).blocks ); i++) {
00043 MrfBlock* qBlock = arrp( (query->read2).blocks, i, MrfBlock);
00044 if( !strcmp( qBlock->targetName, target->chromosome) ) {
00045 if( positiveRangeIntersection( qBlock->targetStart, qBlock->targetEnd, target->start, target->end ) > 0 ) {
00046 overlap = 1;
00047 i = arrayMax( (query->read2).blocks );
00048 }
00049 }
00050 }
00051 }
00052 }
00053
00054 return overlap;
00055 }
00056
00057 void printLocus( Locus l) {
00058 printf("%s:%d-%d\n", l.chromosome, l.start, l.end);
00059 }
00060 void sprintfLocus( char* str, Locus l) {
00061 sprintf(str, "%s\t%d\t%d", l.chromosome, l.start, l.end);
00062 }
00063
00067 int write_circosConf (char* prefix,
00068 Locus locus,
00069 Array regions,
00070 Chrdata_t *chromosomes,
00071 SVCfg_t *settings)
00072 {
00073 float rpos = 0.99;
00074 FILE *fp;
00075 Stringa buffer = stringCreate(50);
00076 int scale = getScale (regions);
00077
00078 stringPrintf (buffer, "%s/test/circos_%s_%s_%d_%d.conf",
00079 WEB_CIRCOS_DIR, prefix, locus.chromosome, locus.start, locus.end);
00080
00081 if (!(fp = fopen (string (buffer), "w"))) {
00082 die ("Unable to open target file");
00083 return -1;
00084 };
00085
00086 printf ("<h2>%i</h2>", scale);
00087
00088
00089 conf_printHeader (fp, WEB_CIRCOS_DIR, WEB_DATA_DIR, WEB_SDATA_DIR, chromosomes, prefix, locus, scale);
00090 conf_printUnits (fp, regions, chromosomes, scale);
00091
00092 if (scale <= 10000) {
00093 conf_printDataTracks (fp, prefix, locus, WEB_SDATA_DIR, WEB_DATA_DIR, &rpos, regions, chromosomes, settings);
00094 }
00095
00096 conf_printLinks (fp, WEB_DATA_DIR, &rpos, prefix, locus, settings->readlim);
00097 conf_printFooter (fp);
00098
00099 fclose (fp);
00100 stringDestroy (buffer);
00101 return 0;
00102 }
00103
00104 static void regionFilter (Array arrFiltered, Array arrPER, Array regions, int minspan)
00105 {
00106 int i, j;
00107 int perspan;
00108 int chrnum1, chrnum2;
00109 int diffchr;
00110
00111 PEreads *new;
00112
00113 for (i = 0, j = 0; i < arrayMax (arrPER); i++) {
00114 PEreads* currPER = arrp (arrPER, i, PEreads);
00115
00116 chrnum1 = getChrnum (currPER->read1.chromosome+3);
00117 chrnum2 = getChrnum (currPER->read2.chromosome+3);
00118
00119 if (chrnum1 == chrnum2)
00120 diffchr = 0;
00121 else
00122 diffchr = 1;
00123
00124 if (inRegions (regions, chrnum1, currPER->read1.start, currPER->read1.end) &&
00125 inRegions (regions, chrnum2, currPER->read2.start, currPER->read2.end)) {
00126
00127 perspan = currPER->read2.start - currPER->read1.end;
00128 if (perspan < 0)
00129 perspan = 0 - perspan;
00130
00131 if (diffchr || perspan >= minspan) {
00132 new = arrayp (arrFiltered, j, PEreads);
00133 new->read1.chromosome = hlr_strdup (currPER->read1.chromosome);
00134 new->read2.chromosome = hlr_strdup (currPER->read2.chromosome);
00135 new->read1.start = currPER->read1.start;
00136 new->read2.start = currPER->read2.start;
00137 new->read1.end = currPER->read1.end;
00138 new->read2.end = currPER->read2.end;
00139 new->id = currPER->id;
00140 j++;
00141 }
00142 }
00143 }
00144 }
00145
00146 static void segmentFilter (char *prefix,
00147 Locus target,
00148 Array *arrFiltered,
00149 Array regions,
00150 int thold,
00151 int maxgap,
00152 int minrun,
00153 int showtars)
00154 {
00155 Array newFiltered;
00156
00157 Array arrWigs;
00158 Array arrTars;
00159
00160 Array *tmpWigs;
00161 Array *tmpTars;
00162
00163 SRegion_t *tmpReg;
00164 Wig *tmpW;
00165 Tar *tmpT;
00166 FILE *outTar;
00167 int i, j, k;
00168 int nregions = arrayMax (regions);
00169 int regionSpan;
00170 Stringa buffer = stringCreate (50);
00171
00172 if (showtars) {
00173 stringPrintf (buffer, "%s/tmp/%s_%s_%d_%d.hlight.txt", WEB_DATA_DIR, prefix, target.chromosome, target.start, target.end);
00174 if (!(outTar = fopen (string (buffer), "w"))) {
00175 die ("Unable to open target highlight file");
00176 }
00177 }
00178
00179 tmpReg = arrayp (regions, 0, SRegion_t);
00180 if (tmpReg->chromosome == 0) {
00181 return;
00182 }
00183
00184
00185
00186
00187 newFiltered = arrayCreate (200, PEreads);
00188 arrWigs = arrayCreate (nregions, Array);
00189 arrTars = arrayCreate (nregions, Array);
00190 for (i = 0; i < nregions; i++) {
00191 tmpReg = arrayp (regions, i, SRegion_t);
00192 regionSpan = tmpReg->end - tmpReg->start + 1;
00193
00194 tmpWigs = arrayp (arrWigs, i, Array);
00195 tmpTars = arrayp (arrTars, i, Array);
00196
00197 *tmpWigs = arrayCreate (regionSpan, Wig);
00198 *tmpTars = arrayCreate (200, Tar);
00199
00200 for (j = 0; j < regionSpan; j++) {
00201 tmpW = arrayp (*tmpWigs, j, Wig);
00202 tmpW->position = j + 1;
00203 tmpW->value = 0;
00204 }
00205 }
00206
00207
00208
00209
00210 for (i = 0; i < arrayMax (*arrFiltered); i++) {
00211 PEreads* currPER = arrp (*arrFiltered, i, PEreads);
00212
00213
00214 for (j = 0; j < nregions; j++) {
00215 tmpReg = arrayp (regions, j, SRegion_t);
00216 tmpWigs = arrayp (arrWigs, j, Array);
00217
00218 if (tmpReg->chromosome == getChrnum (currPER->read1.chromosome+3) &&
00219 inRegion (currPER->read1.start, currPER->read1.end, tmpReg->start, tmpReg->end)) {
00220 break;
00221 }
00222 }
00223
00224 int gstart = currPER->read1.start - tmpReg->start;
00225 int gend = currPER->read1.end - tmpReg->start;
00226 for (k = gstart; k <= gend; k++) {
00227 tmpW = arrayp (*tmpWigs, k, Wig);
00228 tmpW->value += 1;
00229 }
00230
00231
00232 j = 0;
00233 for (j = 0; j < nregions; j++) {
00234 tmpReg = arrayp (regions, j, SRegion_t);
00235 tmpWigs = arrayp (arrWigs, j, Array);
00236 if (tmpReg->chromosome == getChrnum (currPER->read2.chromosome+3) &&
00237 inRegion (currPER->read2.start, currPER->read2.end, tmpReg->start, tmpReg->end)) {
00238 break;
00239 }
00240 }
00241
00242 gstart = currPER->read2.start - tmpReg->start;
00243 gend = currPER->read2.end - tmpReg->start;
00244 for (k = gstart; k <= gend; k++) {
00245 tmpW = arrayp (*tmpWigs, k, Wig);
00246 tmpW->value += 1;
00247 }
00248 }
00249
00250
00251
00252
00253 for (i = 0; i < nregions; i++) {
00254 tmpWigs = arrayp (arrWigs, i, Array);
00255 tmpTars = arrayp (arrTars, i, Array);
00256 tmpReg = arrayp (regions, i, SRegion_t);
00257
00258 Stringa chrname = stringCreate (3);
00259 if (tmpReg->chromosome == 23) {
00260 stringPrintf (chrname, "X");
00261 } else if (tmpReg->chromosome == 24) {
00262 stringPrintf (chrname, "Y");
00263 } else {
00264 stringPrintf (chrname, "%i", tmpReg->chromosome);
00265 }
00266
00267 performSegmentation (*tmpTars, *tmpWigs, string (chrname), thold, maxgap, minrun);
00268
00269 for (j = 0; j < arrayMax (*tmpWigs); j++) {
00270 tmpW = arrayp (*tmpWigs, j, Wig);
00271 tmpW->value = 0;
00272 }
00273
00274 for (j = 0; j < arrayMax (*tmpTars); j++) {
00275 tmpT = arrayp (*tmpTars, j, Tar);
00276 int gstart = tmpT->start;
00277 int gend = tmpT->end;
00278
00279 if (showtars)
00280 fprintf (outTar, "hs%s %i %i\n", string (chrname), gstart-1 + tmpReg->start, gend-1 + tmpReg->start);
00281
00282 for (k = gstart-1; k <= gend-1; k++) {
00283 tmpW = arrayp (*tmpWigs, k, Wig);
00284 tmpW->value = 1;
00285 }
00286 }
00287 stringDestroy (chrname);
00288 }
00289
00290
00291
00292
00293 for (i = 0; i < arrayMax (*arrFiltered); i++) {
00294 PEreads* currPER = arrp (*arrFiltered, i, PEreads);
00295 int gstart, gend;
00296
00297
00298 for (j = 0; j < nregions; j++) {
00299 tmpReg = arrayp (regions, j, SRegion_t);
00300 tmpWigs = arrayp (arrWigs, j, Array);
00301 if (tmpReg->chromosome == getChrnum (currPER->read1.chromosome+3) &&
00302 inRegion (currPER->read1.start, currPER->read1.end, tmpReg->start, tmpReg->end)) {
00303 break;
00304 }
00305 }
00306
00307 gstart = currPER->read1.start - tmpReg->start;
00308 gend = currPER->read1.end - tmpReg->start;
00309 if ((arrayp (*tmpWigs, gstart, Wig))->value > 0 ||
00310 (arrayp (*tmpWigs, gend, Wig))->value > 0) {
00311 for (j = 0; j < nregions; j++) {
00312 tmpReg = arrayp (regions, j, SRegion_t);
00313 tmpWigs = arrayp (arrWigs, j, Array);
00314 if (tmpReg->chromosome == getChrnum (currPER->read2.chromosome+3) &&
00315 inRegion (currPER->read2.start, currPER->read2.end, tmpReg->start, tmpReg->end)) {
00316 break;
00317 }
00318 }
00319
00320 gstart = currPER->read2.start - tmpReg->start;
00321 gend = currPER->read2.end - tmpReg->start;
00322
00323 if ((arrayp (*tmpWigs, gstart, Wig))->value > 0 ||
00324 (arrayp (*tmpWigs, gend, Wig))->value > 0) {
00325
00326 PEreads *newPER = arrayp (newFiltered, arrayMax (newFiltered), PEreads);
00327 newPER->id = currPER->id;
00328 newPER->read1.chromosome = hlr_strdup (currPER->read1.chromosome);
00329 newPER->read2.chromosome = hlr_strdup (currPER->read2.chromosome);
00330 newPER->read1.start = currPER->read1.start;
00331 newPER->read2.start = currPER->read2.start;
00332 newPER->read1.end = currPER->read1.end;
00333 newPER->read2.end = currPER->read2.end;
00334 }
00335 }
00336 }
00337
00338 for (i = 0; i < nregions; i++) {
00339 tmpWigs = arrayp (arrWigs, i, Array);
00340 tmpTars = arrayp (arrTars, i, Array);
00341 arrayDestroy (*tmpWigs);
00342 arrayDestroy (*tmpTars);
00343 }
00344
00345 arrayDestroy (arrWigs);
00346 arrayDestroy (arrTars);
00347 arrayDestroy (*arrFiltered);
00348 *arrFiltered = newFiltered;
00349 stringDestroy (buffer);
00350 if (showtars)
00351 fclose (outTar);
00352 }
00353
00354 static void printLinks (FILE *fp, int *targetCounts, Array arrPER)
00355 {
00356 int i, diffchr;
00357 for (i = 0; i < arrayMax (arrPER); i++) {
00358 PEreads* currPER = arrp (arrPER, i, PEreads);
00359 if (targetCounts[getChrnum (currPER->read1.chromosome+3) - 1] > 9 &&
00360 targetCounts[getChrnum (currPER->read2.chromosome+3) - 1] > 9 ) {
00361 Stringa chr1 = stringCreate (5);
00362 Stringa chr2 = stringCreate (5);
00363
00364 Stringa entry1 = stringCreate (30);
00365 Stringa entry2 = stringCreate (30);
00366
00367 stringPrintf (chr1, "hs%s", currPER->read1.chromosome+3);
00368 stringPrintf (chr2, "hs%s", currPER->read2.chromosome+3);
00369
00370 diffchr = strDiffer (string (chr1), string (chr2));
00371
00372 stringPrintf (entry1, "data%d %s %d %d",
00373 currPER->id,
00374 string(chr1),
00375 currPER->read1.start,
00376 currPER->read1.end);
00377 if (diffchr) {
00378 stringAppendf (entry1, " color=red");
00379 }
00380
00381 stringPrintf (entry2, "data%d %s %d %d",
00382 currPER->id,
00383 string(chr2),
00384 currPER->read2.start,
00385 currPER->read2.end);
00386 if (diffchr) {
00387 stringAppendf (entry2, " color=red");
00388 }
00389
00390 fprintf (fp, "%s\n", string (entry1));
00391 fprintf (fp, "%s\n", string (entry2));
00392
00393 stringDestroy (entry1);
00394 stringDestroy (entry2);
00395 stringDestroy (chr1);
00396 stringDestroy (chr2);
00397 }
00398 }
00399 }
00400
00401 static void generateOutput (char *prefix,
00402 char *location,
00403 Array regions,
00404 Chrdata_t *chromosomes,
00405 SVCfg_t *settings)
00406 {
00407 int i;
00408 Stringa buffer = stringCreate (50);
00409 Stringa sbuffer = stringCreate (50);
00410 Stringa imgUrl = stringCreate (50);
00411 Stringa svgUrl = stringCreate (50);
00412 char *loc = strdup (location);
00413
00414 WordIter w = wordIterCreate (location, ":-", 0);
00415 Locus target;
00416 target.chromosome = hlr_strdup (wordNext (w));
00417 char* tmp = wordNext (w);
00418 strTranslate (tmp, ",", "");
00419 target.start = atoi (tmp);
00420 tmp = wordNext (w);
00421 strTranslate (tmp, ",", "");
00422 target.end = atoi (tmp);
00423 if (target.end < target.start) {
00424 swapInt (&target.end, &target.start);
00425 }
00426 wordIterDestroy (w);
00427 stringPrintf (imgUrl, "%s/tmp/%s_%s_%d_%d.png", WEB_DATA_LINK, prefix, target.chromosome, target.start, target.end );
00428 stringPrintf (svgUrl, "%s/tmp/%s_%s_%d_%d.svg", WEB_DATA_LINK, prefix, target.chromosome, target.start, target.end );
00429
00430
00431
00432
00433 web_printHTMLHead(regions, chromosomes, WEB_PUB_DIR);
00434 web_printPageHeader(prefix, loc);
00435
00436 web_printSidebar (WEB_URL_CGI,
00437 prefix,
00438 loc,
00439 string (imgUrl),
00440 string (svgUrl),
00441 regions,
00442 chromosomes,
00443 settings);
00444 fflush(stdout);
00445
00446
00447
00448
00449
00450 Stringa mrfFile = stringCreate (50);
00451 stringPrintf (mrfFile, "zcat %s/mrf/%s_%s.mrf.gz", WEB_DATA_DIR, prefix, target.chromosome);
00452
00453
00454 mrf_initFromPipe (string (mrfFile));
00455
00456 MrfEntry* currMRFE;
00457 int count = 0;
00458 FILE *fp;
00459 FILE *sfp;
00460 Array arrPER = arrayCreate (1000, PEreads);
00461 Array arrFiltered = arrayCreate (1000, PEreads);
00462
00463 int targetCounts[24];
00464
00465 for (i = 0; i < 24; i++)
00466 targetCounts[i] = 0;
00467
00468 while (currMRFE = mrf_nextEntry ()) {
00469 MrfBlock* currBlock1 = arrp ((currMRFE->read1).blocks, 0, MrfBlock);
00470 MrfBlock* currBlock2 = arrp ((currMRFE->read2).blocks, 0, MrfBlock);
00471 if (containedLocus (currMRFE, &target) &&
00472 strlen (currBlock1->targetName) < 6 &&
00473 strlen (currBlock2->targetName) < 6) {
00474 PEreads* currPER = arrayp (arrPER, arrayMax (arrPER), PEreads);
00475 if( !strcmp( currBlock1->targetName, currBlock2->targetName) ) {
00476 if( currBlock1->targetStart < currBlock2->targetStart ) {
00477 currPER->read1.chromosome = hlr_strdup (currBlock1->targetName);
00478 currPER->read2.chromosome = hlr_strdup (currBlock2->targetName);
00479 currPER->read1.start = currBlock1->targetStart;
00480 currPER->read2.start = currBlock2->targetStart;
00481 currPER->read1.end = currBlock1->targetEnd;
00482 currPER->read2.end = currBlock2->targetEnd;
00483 } else {
00484 currPER->read2.chromosome = hlr_strdup (currBlock1->targetName);
00485 currPER->read1.chromosome = hlr_strdup (currBlock2->targetName);
00486 currPER->read2.start = currBlock1->targetStart;
00487 currPER->read1.start = currBlock2->targetStart;
00488 currPER->read2.end = currBlock1->targetEnd;
00489 currPER->read1.end = currBlock2->targetEnd;
00490 }
00491 } else {
00492 int chr1, chr2;
00493 if( !strcmp(currBlock1->targetName,"X") ) {
00494 chr1=23;
00495 } else if(!strcmp(currBlock1->targetName,"Y") ) {
00496 chr1=24;
00497 } else
00498 chr1=atoi( currBlock1->targetName+3 );
00499 if( !strcmp(currBlock2->targetName,"X") ) {
00500 chr2=23;
00501 } else if(!strcmp(currBlock2->targetName,"Y") ) {
00502 chr2=24;
00503 } else chr2=atoi( currBlock2->targetName+3 );
00504 if( chr1 < chr2 ) {
00505 currPER->read1.chromosome = hlr_strdup (currBlock1->targetName);
00506 currPER->read2.chromosome = hlr_strdup (currBlock2->targetName);
00507 currPER->read1.start = currBlock1->targetStart;
00508 currPER->read2.start = currBlock2->targetStart;
00509 currPER->read1.end = currBlock1->targetEnd;
00510 currPER->read2.end = currBlock2->targetEnd;
00511 } else {
00512 currPER->read2.chromosome = hlr_strdup (currBlock1->targetName);
00513 currPER->read1.chromosome = hlr_strdup (currBlock2->targetName);
00514 currPER->read2.start = currBlock1->targetStart;
00515 currPER->read1.start = currBlock2->targetStart;
00516 currPER->read2.end = currBlock1->targetEnd;
00517 currPER->read1.end = currBlock2->targetEnd;
00518 }
00519 }
00520 currPER->id = count;
00521 targetCounts[getChrnum (currBlock1->targetName+3) - 1]++;
00522 targetCounts[getChrnum (currBlock2->targetName+3) - 1]++;
00523 count++;
00524 }
00525 }
00526
00527 stringPrintf (buffer, "%s/tmp/%s_%s_%d_%d.data", WEB_DATA_DIR, prefix, target.chromosome, target.start, target.end);
00528 if (!(fp = fopen (string (buffer), "w"))) {
00529 die ("Unable to open target file");
00530 };
00531 stringPrintf (sbuffer, "%s/tmp/%s_%s_%d_%d_s.data", WEB_DATA_DIR, prefix, target.chromosome, target.start, target.end);
00532 if (!(sfp = fopen (string (sbuffer), "w"))) {
00533 die ("Unable to open target file");
00534 };
00535
00536 arraySort (arrPER, (ARRAYORDERF) &sortPosition);
00537 arrayUniq (arrPER, NULL, (ARRAYORDERF) &sortPosition);
00538 arraySort (arrPER, (ARRAYORDERF) &PEReadSizeCmp);
00539
00540 regionFilter (arrFiltered, arrPER, regions, settings->minspan);
00541
00542 if (settings->rfilter.on)
00543 segmentFilter (prefix,
00544 target,
00545 &arrFiltered,
00546 regions,
00547 settings->rfilter.thold,
00548 settings->rfilter.maxgap,
00549 settings->rfilter.minrun,
00550 settings->rfilter.showtars);
00551
00552 printLinks (fp, targetCounts, arrPER);
00553 printLinks (sfp, targetCounts, arrFiltered);
00554
00555 fclose (sfp);
00556 fclose (fp);
00557
00558
00559
00560
00561 if (write_circosConf (prefix,
00562 target,
00563 regions,
00564 chromosomes,
00565 settings)) {
00566 die ("Error creating circos configuration file");
00567 }
00568 stringPrintf (buffer, "rm %s/tmp/%s_%s_%d_%d.png", WEB_DATA_DIR, prefix, target.chromosome, target.start, target.end);
00569
00570
00571
00572
00573
00574
00575 stringPrintf (buffer,"%s/bin/circos -conf %s/test/circos_%s_%s_%d_%d.conf -silent",
00576 WEB_CIRCOS_DIR,WEB_CIRCOS_DIR, prefix, target.chromosome, target.start, target.end);
00577
00578 hlr_system (string (buffer),0);
00579 hlr_free(target.chromosome);
00580 mrf_deInit ();
00581
00582 printf ("<div class=\"img_circ\"><a href=\"%s\" target=\"_blank\">\n", string (imgUrl));
00583 printf ("<img width=\"650px\" src=\"%s\" id=\"circosImg\" border=\"1\" onload=\"setImageLoaded();\"/>", string (imgUrl));
00584 puts ("</a></div>\n");
00585
00586
00587
00588
00589
00590 web_printBody (WEB_URL_CGI,
00591 prefix,
00592 loc,
00593 regions,
00594 chromosomes,
00595 settings);
00596
00597
00598 fflush (stdout);
00599 free (loc);
00600 arrayDestroy (arrPER);
00601 arrayDestroy (arrFiltered);
00602 stringDestroy (imgUrl);
00603 stringDestroy (svgUrl);
00604 stringDestroy (buffer);
00605 stringDestroy (sbuffer);
00606 }
00607
00608
00609 int main (int argc, char *argv[])
00610 {
00611 cgiInit();
00612 cgiHeader("text/html");
00613 setenv ("PERL5LIB","/home/asboner/PerlModules/lib/perl5/site_perl/5.8.8/:/home/asboner/PerlModules/lib64/perl5/site_perl/5.8.8/:/home/asboner/PerlModules/lib/perl5/5.8.8/",1);
00614
00615 char *querystr = cgiGet2Post();
00616
00617 Stringa item;
00618 Stringa value;
00619 char *iPtr, *vPtr;
00620
00621 char *prefix = NULL;
00622 char *location = NULL;
00623
00624 int chrnum, instnum, i;
00625 Array regions = arrayCreate(1, SRegion_t);
00626 Chrdata_t *chromosomes = (Chrdata_t *) calloc(25, sizeof(*chromosomes));
00627 SRegion_t *tmp;
00628
00629 SVCfg_t settings;
00630 settings.minspan = 0;
00631 settings.readlim = 0;
00632 settings.rfilter.on = 0;
00633 settings.rfilter.thold = RFILTER_THOLD;
00634 settings.rfilter.maxgap = RFILTER_MAXGAP;
00635 settings.rfilter.minrun = RFILTER_MINRUN;
00636 settings.rfilter.showtars = 0;
00637 settings.tracks.expr = 0;
00638 settings.tracks.genes = 0;
00639 settings.tracks.exons = 0;
00640
00641 int first = 1;
00642
00643 tmp = arrayp(regions, 0, SRegion_t);
00644 tmp->chromosome = -1;
00645 tmp->instance = -1;
00646 tmp->show = 0;
00647 tmp->start = 0;
00648 tmp->end = -1;
00649 tmp->mstart = 0;
00650 tmp->mend = -1;
00651
00652 for (i = 0; i < 25; i++) {
00653 chromosomes[i].show = 0;
00654 chromosomes[i].instances = 0;
00655 }
00656
00657 if (strcmp(querystr, "") != 0) {
00658 item = stringCreate (20);
00659 value = stringCreate (20);
00660 while (cgiGetNextPair (&first,item,value)) {
00661 iPtr = string (item);
00662 vPtr = string (value);
00663 if (strEqual (iPtr,"prefix")) {
00664 prefix = hlr_strdup ( vPtr );
00665 }
00666 if (strEqual (iPtr,"location")) {
00667 location = hlr_strdup ( vPtr );
00668 }
00669
00670 if (strEqual (iPtr, "rfilter"))
00671 settings.rfilter.on = atoi (vPtr);
00672 if (strEqual (iPtr, "rthold"))
00673 settings.rfilter.thold = atoi (vPtr);
00674 if (strEqual (iPtr, "rminrun"))
00675 settings.rfilter.minrun = atoi (vPtr);
00676 if (strEqual (iPtr, "rmaxgap"))
00677 settings.rfilter.maxgap = atoi (vPtr);
00678 if (strEqual (iPtr, "rshowtars"))
00679 settings.rfilter.showtars = atoi (vPtr);
00680 if (strEqual (iPtr, "expr"))
00681 settings.tracks.expr = 1;
00682 if (strEqual (iPtr, "genes"))
00683 settings.tracks.genes = 1;
00684 if (strEqual (iPtr, "exons"))
00685 settings.tracks.exons = atoi (vPtr);
00686 if (strEqual (iPtr, "readlim"))
00687 settings.readlim = atoi (vPtr);
00688 if (strEqual (iPtr, "minspan"))
00689 settings.minspan = atoi (vPtr);
00690
00691 if (!strncmp (iPtr, "hs", 2)) {
00692 if (!strcmp (&iPtr[2], "X")) {
00693 chrnum = 23;
00694 }
00695 else if (!strcmp (&iPtr[2], "Y")) {
00696 chrnum = 24;
00697 }
00698 else {
00699 chrnum = atoi (&iPtr[2]);
00700 }
00701
00702 if (chromosomes[0].show != chrnum) {
00703 chromosomes[0].show = chrnum;
00704 chromosomes[0].instances++;
00705 }
00706 chromosomes[chrnum].show = 1;
00707 }
00708
00709
00710
00711
00712
00713 if (!strncmp(iPtr, "shs", 3) || !strncmp(iPtr, "mhs", 3)) {
00714 instnum = antoi(&iPtr[6], 6);
00715 if (!strncmp(&iPtr[4], "X", 1))
00716 chrnum = 23;
00717 else if (!strncmp(&iPtr[4], "Y", 1))
00718 chrnum = 24;
00719 else
00720 chrnum = antoi(&iPtr[3], 2);
00721
00722 for (i = 0; i < arrayMax(regions); i++) {
00723 tmp = arrayp(regions, i, SRegion_t);
00724 if ((chrnum == tmp->chromosome && instnum == tmp->instance) ||
00725 (chrnum == -1 && instnum && -1)) {
00726 tmp->instance = instnum;
00727 tmp->chromosome = chrnum;
00728 break;
00729 }
00730 }
00731
00732 if (i >= arrayMax(regions)) {
00733 tmp = arrayp(regions, i, SRegion_t);
00734 tmp->instance = instnum;
00735 tmp->chromosome = chrnum;
00736 tmp->show = 0;
00737 tmp->start = 0;
00738 tmp->end = -1;
00739 tmp->mend = -1;
00740 }
00741
00742 if (!strncmp(iPtr, "shs", 3)) {
00743 if (!strcmp(&iPtr[8], "show")) {
00744 tmp->show = 1;
00745 }
00746 else if (!strcmp(&iPtr[8], "start")) {
00747 tmp->start = atoi(vPtr);
00748 }
00749 else if (!strcmp(&iPtr[8], "end")) {
00750 tmp->end = atoi(vPtr);
00751 }
00752 }
00753 else {
00754 if (!strcmp(&iPtr[8], "start")) {
00755 tmp->mstart = atoi(vPtr);
00756 }
00757 else if (!strcmp(&iPtr[8], "end")) {
00758 tmp->mend = atoi(vPtr);
00759 }
00760 }
00761 }
00762 }
00763 filterChrRegions (®ions, &chromosomes);
00764 if (!settings.rfilter.on) {
00765 settings.rfilter.showtars = 0;
00766 }
00767 }
00768
00769 if (!strcmp (querystr, "") || prefix == NULL || location == NULL) {
00770 web_printSingleLocusForm (WEB_URL_CGI, WEB_PUB_DIR);
00771 fflush (stdout);
00772 }
00773 else {
00774 generateOutput (prefix, location, regions, chromosomes, &settings);
00775 }
00776
00777 cgiGet2PostReset();
00778 arrayDestroy(regions);
00779 free(chromosomes);
00780 return 0;
00781 }
00782