/* Handle details pages for dbRIP tracks. */ #include "common.h" #include "hash.h" #include "linefile.h" #include "hgc.h" #include "hui.h" #include "obscure.h" #include "cheapcgi.h" #include "htmshell.h" #include "dbRIP.h" #include "polyGenotype.h" static int sortEthnicGroup(const void *e1, const void *e2) /* used by slSort to sort the polyGenotype in order of ethnic group name */ { const struct polyGenotype *p1 = *((struct polyGenotype**)e1); const struct polyGenotype *p2 = *((struct polyGenotype**)e2); return(strcmp(p1->ethnicGroup, p2->ethnicGroup)); } static void polyTable(char *name) { struct sqlConnection *conn = hAllocConn(database); char query[256]; struct sqlResult *sr; char **row; struct polyGenotype *pgList = NULL; sprintf(query, "select * from polyGenotype where name = '%s'", name); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct polyGenotype *pg; AllocVar(pg); pg = polyGenotypeLoad(row); slAddHead(&pgList, pg); } sqlFreeResult(&sr); hFreeConn(&conn); if (slCount(pgList) > 0) { struct polyGenotype *pg; int totalPlusPlus = 0; int totalPlusMinus = 0; int totalMinusMinus = 0; int totalSamples = 0; double alleleFrequency = 0.0; double unbiasedHeterozygosity = 0.0; int sampleSize = 0; int plusAlleles = 0; int minusAlleles = 0; slSort(&pgList,sortEthnicGroup); printf("Polymorphism Frequencies and Genotypes:
\n"); /* This surrounding table avoids the problem of the border lines of * the second table go missing. Something about the style sheet ... */ printf("
\n"); printf("\n"); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf("\n"); for (pg = pgList; pg != NULL; pg = pg->next) { plusAlleles = (pg->plusPlus << 1) + pg->plusMinus; minusAlleles = (pg->minusMinus << 1) + pg->plusMinus; sampleSize = pg->plusPlus + pg->plusMinus + pg->minusMinus; if ((plusAlleles + minusAlleles) > 0) { alleleFrequency = (double)plusAlleles / (double)(plusAlleles + minusAlleles); } else alleleFrequency = 0.0; printf("", pg->ethnicGroup); printf("", sampleSize); printf("", alleleFrequency); printf("", pg->plusPlus); printf("", pg->plusMinus); printf("", pg->minusMinus); /* adjust by 2N/(2N-1) for small sample heterozygosity calculation * http://www.genetics.org/cgi/content/abstract/89/3/583 * Masatoshi Nei (1978) */ if (sampleSize > 0) { unbiasedHeterozygosity=2*alleleFrequency*(1.0 - alleleFrequency); unbiasedHeterozygosity *= (double)(sampleSize << 1) / (double)((sampleSize << 1) - 1); } else unbiasedHeterozygosity=2*alleleFrequency*(1.0 - alleleFrequency); printf("", unbiasedHeterozygosity); printf("\n"); totalSamples += sampleSize; totalPlusPlus += pg->plusPlus; totalMinusMinus += pg->minusMinus; totalPlusMinus += pg->plusMinus; } plusAlleles = (totalPlusPlus << 1) + totalPlusMinus; minusAlleles = (totalMinusMinus << 1) + totalPlusMinus; if ((plusAlleles + minusAlleles) > 0) { alleleFrequency = (double)plusAlleles / (double)(plusAlleles + minusAlleles); } else { alleleFrequency = 0.0; } printf(""); printf("", totalSamples); printf("", alleleFrequency); printf("", totalPlusPlus); printf("", totalPlusMinus); printf("", totalMinusMinus); if (totalSamples > 0) { unbiasedHeterozygosity = 2 * alleleFrequency * (1.0 - alleleFrequency); unbiasedHeterozygosity *= (double)(totalSamples << 1)/(double)((totalSamples << 1) - 1); } else unbiasedHeterozygosity = 2 * alleleFrequency * (1.0 - alleleFrequency); printf("", unbiasedHeterozygosity); printf("\n"); printf("
Ethnic GroupSample SizeAllele Frequency+/++/--/-Unbiased Heterozygosity
%s%d%.3f%d%d%d%.3f
All Samples%d%.3f%d%d%d%.3f
\n"); printf("
\n"); } else printf("Polymorphism Frequencies and Genotypes: NA
\n"); } void dbRIP(struct trackDb *tdb, char *item, char *itemForUrl) /* Put up dbRIP track info */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr = NULL; char table[64]; boolean hasBin; struct dbRIP *loadItem; struct dyString *query = newDyString(512); char **row; boolean firstTime = TRUE; int start = cartInt(cart, "o"); int itemCount = 0; genericHeader(tdb, item); hFindSplitTable(database, seqName, tdb->table, table, &hasBin); dyStringPrintf(query, "select * from %s where chrom = '%s' and ", table, seqName); hAddBinToQuery(winStart, winEnd, query); dyStringPrintf(query, "name = '%s' and chromStart = %d", item, start); sr = sqlGetResult(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) { if (firstTime) firstTime = FALSE; else htmlHorizontalLine(); ++itemCount; loadItem = dbRIPLoad(row+hasBin); printf("Database ID: %s
\n", loadItem->name); printf("Original ID: %s
\n", loadItem->originalId); printf("Class: %s
\n", loadItem->polyClass); printf("Family: %s
\n", loadItem->polyFamily); printf("Subfamily: %s
\n", loadItem->polySubfamily); printf("Associated Disease: %s
\n", loadItem->disease); printf("Sequence of L1 insertion and 400bp flanking on each side:"); printf("(5' flanking-"); // ' = ' printf(""); printf("TSD1-REPEAT SEQUENCE"); printf("-"); printf("TSD2-3' flanking)
"); // ' = ' printf("(\"nnnnn\""); printf(" --> unknown TSD; \"NNNNNNNNNN\" -->"); printf(" unknown Repeat Sequence):
\n
%s", loadItem->polySeq);
    printf("

\n"); printf("Forward Primer: %s
\n", loadItem->forwardPrimer); printf("Reverse Primer: %s
\n", loadItem->reversePrimer); if (loadItem->tm > 0.0) printf("Annealing Temperature: %.1f °C.
\n", loadItem->tm); else printf("Annealing Temperature: NA
\n"); if (loadItem->filledSize > 0) printf("PCR Product Size (Filled): %d bp.
\n", loadItem->filledSize); else printf("PCR Product Size (Filled): NA
\n"); if (loadItem->emptySize > 0) printf("PCR Product Size (Empty): %d bp.
\n", loadItem->emptySize); else printf("PCR Product Size (Empty): NA
\n"); printf("Ascertaining Method: %s
\n", loadItem->ascertainingMethod); printf("Insertion found in reference sequence: %s
\n", startsWith("UCSC",loadItem->polySource) ? "yes" : "no"); printf("Remarks: %s
\n", loadItem->remarks); if (strlen(loadItem->genoRegion) > 0) printf("Gene Context: %s
\n", loadItem->genoRegion); else printf("Gene Context: NA
\n"); polyTable(loadItem->name); printPosOnChrom(loadItem->chrom, loadItem->chromStart, loadItem->chromEnd, loadItem->strand, TRUE, loadItem->name); printf("
\nReference(s): %s\n
\n", loadItem->reference); } sqlFreeResult(&sr); hFreeConn(&conn); printTrackHtml(tdb); }