Beispiel #1
0
void printFASTA(char *proteinID, char *aa)
/* print the FASTA format protein sequence */
{
int i, l;
char *chp;

l =strlen(aa);

hPrintf("<B>Total amino acids:</B> %d\n", strlen(aa));
hPrintf("\n");
hPrintf("<P><B>FASTA record:</B>\n");
hPrintf("<pre>\n");
if (hIsGsidServer())
    hPrintf(">%s", proteinID);
else
    hPrintf(">%s|%s|%s", proteinID, protDisplayID, description);

chp = aa;
for (i=0; i<l; i++)
    {
    if ((i%50) == 0) hPrintf("\n");

    hPrintf("%c", *chp);
    chp++;
    }

hPrintf("</pre>");
fflush(stdout);
}
Beispiel #2
0
static void explainCoordSystem()
/* Our coord system is counter-intuitive to users.  Warn them in advance to
 * reduce the frequency with which they find this "bug" on their own and
 * we have to explain it on the genome list. */
{
if (!hIsGsidServer())
    {
    puts("<BR><I>Note: all start coordinates in our database are 0-based, not \n"
     "1-based.  See explanation \n"
     "<A HREF=\"http://genome.ucsc.edu/FAQ/FAQtracks#tracks1\">"
         "here</A>.</I>");
    }
else
    {
    puts("<BR><I>Note: all start coordinates in our database are 0-based, not \n"
         "1-based.\n</I>");
    }
}
Beispiel #3
0
void mapBoxTrackTitle(int x, int y, int width, int height, char *title, char *tagName)
{
hPrintf("<AREA SHAPE=RECT COORDS=\"%d,%d,%d,%d\" ", x-1, y-1, x+width+1, y+height+1);
if (proteinInSupportedGenome)
    {
    hPrintf("HREF=\"../goldenPath/help/pbTracksHelpFiles/pb%s.shtml\"", tagName);
    }
else
    {
    if (hIsGsidServer())
	{
	hPrintf("HREF=\"../goldenPath/help/pbTracksHelpFiles/pbGsid/pb%s.shtml\"", tagName);
	}
    else
	{    
	hPrintf("HREF=\"../goldenPath/help/pbTracksHelpFiles/pb%s.shtml\"", tagName);
    	}
    }
hPrintf(" target=_blank ALT=\"Click here for explanation of %c%s%c\">\n", '\'', title, '\'');
}
Beispiel #4
0
void askForSeq(char *organism, char *db)
/* Put up a little form that asks for sequence.
 * Call self.... */
{
struct serverTable *serve = NULL;

/* JavaScript to update form when org changes */
char *onChangeText = "onchange=\""
    "document.mainForm.changeInfo.value='orgChange';"
    "document.mainForm.submit();\"";

char *userSeq = NULL;

serve = findServer(db, FALSE);

printf( 
"<FORM ACTION=\"../cgi-bin/hgBlat\" METHOD=\"POST\" ENCTYPE=\"multipart/form-data\" NAME=\"mainForm\">\n"
"<H2>BLAT Search Genome</H2>\n");
cartSaveSession(cart);
puts("\n");
puts("<INPUT TYPE=HIDDEN NAME=changeInfo VALUE=\"\">\n");
puts("<TABLE BORDER=0 WIDTH=80>\n<TR>\n");
printf("<TD ALIGN=CENTER>Genome:</TD>");
printf("<TD ALIGN=CENTER>Assembly:</TD>");
printf("<TD ALIGN=CENTER>Query type:</TD>");
printf("<TD ALIGN=CENTER>Sort output:</TD>");
printf("<TD ALIGN=CENTER>Output type:</TD>");
printf("<TD ALIGN=CENTER>&nbsp</TD>");
printf("</TR>\n<TR>\n");
printf("<TD ALIGN=CENTER>\n");
printBlatGenomeListHtml(db, onChangeText);
printf("</TD>\n");
printf("<TD ALIGN=CENTER>\n");
printBlatAssemblyListHtml(db);
printf("</TD>\n");
printf("<TD ALIGN=CENTER>\n");
cgiMakeDropList("type", typeList, ArraySize(typeList), NULL);
printf("</TD>\n");
printf("<TD ALIGN=CENTER>\n");
cgiMakeDropList("sort", sortList, ArraySize(sortList), cartOptionalString(cart, "sort"));
printf("</TD>\n");
printf("<TD ALIGN=CENTER>\n");
cgiMakeDropList("output", outputList, ArraySize(outputList), cartOptionalString(cart, "output"));
printf("</TD>\n");
printf("</TR>\n<TR>\n");
userSeq = cartUsualString(cart, "userSeq", "");
printf("<TD COLSPAN=5 ALIGN=CENTER>\n");
printf("<TEXTAREA NAME=userSeq ROWS=14 COLS=80>%s</TEXTAREA>\n", userSeq);
printf("</TD>\n");
printf("</TR>\n<TR>\n");
printf("<TD COLSPAN=5 ALIGN=CENTER>\n");
printf("<INPUT TYPE=SUBMIT NAME=Submit VALUE=submit>\n");
printf("<INPUT TYPE=SUBMIT NAME=Lucky VALUE=\"I'm feeling lucky\">\n");
printf("<INPUT TYPE=SUBMIT NAME=Clear VALUE=clear>\n");
printf("</TD>\n");
printf("</TR>\n<TR>\n"); 
puts("<TD COLSPAN=5 WIDTH=\"100%\">\n" 
    "Paste in a query sequence to find its location in the\n"
    "the genome. Multiple sequences may be searched \n"
    "if separated by lines starting with '>' followed by the sequence name.\n"
    "</TD>\n"
    "</TR>\n"

);
puts("<TR><TD COLSPAN=5 WIDTH=\"100%\">\n"); 
puts("<BR><B>File Upload:</B> ");
puts("Rather than pasting a sequence, you can choose to upload a text file containing "
	 "the sequence.<BR>");
puts("Upload sequence: <INPUT TYPE=FILE NAME=\"seqFile\">");
puts(" <INPUT TYPE=SUBMIT Name=Submit VALUE=\"submit file\"><P>\n");
printf("%s", 
"<P>Only DNA sequences of 25,000 or fewer bases and protein or translated \n"
"sequence of 10000 or fewer letters will be processed.  Up to 25 sequences\n"
"can be submitted at the same time. The total limit for multiple sequence\n"
"submissions is 50,000 bases or 25,000 letters.\n</P>");
if (hgPcrOk(db))
    printf("<P>For locating PCR primers, use <A HREF=\"../cgi-bin/hgPcr?db=%s\">In-Silico PCR</A>"
           " for best results instead of BLAT.</P>", db);
puts("</TD></TR></TABLE>\n");



printf("</FORM>\n");

webNewSection("About BLAT");
printf( 
"<P>BLAT on DNA is designed to\n"
"quickly find sequences of 95%% and greater similarity of length 25 bases or\n"
"more.  It may miss more divergent or shorter sequence alignments.  It will find\n"
"perfect sequence matches of 20 bases.\n"
"BLAT on proteins finds sequences of 80%% and greater similarity of length 20 amino\n"
"acids or more.  In practice DNA BLAT works well on primates, and protein\n"
"blat on land vertebrates."
);


printf("%s",
"\n</P><P>BLAT is not BLAST.  DNA BLAT works by keeping an index of the entire genome\n"
"in memory.  The index consists of all overlapping 11-mers stepping by 5 except for\n"
"those heavily involved in repeats.  The index takes up about\n"
"2 gigabytes of RAM.  RAM can be further reduced to less than 1 GB by increasing step size to 11.\n"
"The genome itself is not kept in memory, allowing\n"
"BLAT to deliver high performance on a reasonably priced Linux box.\n"
"The index is used to find areas of probable homology, which are then\n"
"loaded into memory for a detailed alignment. Protein BLAT works in a similar\n"
"manner, except with 4-mers rather than 11-mers.  The protein index takes a little\n"
"more than 2 gigabytes.</P>\n"
"<P>BLAT was written by <A HREF=\"mailto:[email protected]\">Jim Kent</A>.\n"
"Like most of Jim's software, interactive use on this web server is free to all.\n"
"Sources and executables to run batch jobs on your own server are available free\n"
"for academic, personal, and non-profit purposes.  Non-exclusive commercial\n"
"licenses are also available. See the \n"
"<A HREF=\"http://www.kentinformatics.com\" TARGET=_blank>Kent Informatics</A>\n"
"website for details.</P>\n"
"\n"
"<P>For more information on the graphical version of BLAT, click the Help \n"
"button on the top menu bar");

if (hIsGsidServer())
    printf(". </P> \n");
else
    printf(" or see the Genome Browser <A HREF=\"../FAQ/FAQblat.html\">FAQ</A>. </P> \n");

}
Beispiel #5
0
void doTracks(char *proteinID, char *mrnaID, char *aa, int *yOffp, char *psOutput)
/* draw various protein tracks */
{
int l;

char aaOrigOffsetStr[20];
int hasResFreq;
char uniProtDbName[50];
char *protDbDate;
char *chrom;
char strand;
char *kgId, *kgPep, *protPep;
char cond_str[255];
char *answer;
//int i, ll;
//char *chp1, *chp2;

g_font = mgSmallFont();
safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale);

if (psOutput != NULL)
    {
    pbScale         = atoi(cartOptionalString(cart, "pbt.pbScaleStr"));
    }

if (cgiOptionalString("trackOffset") != NULL)
	{
	trackOrigOffset = atoi(cgiOptionalString("trackOffset")); 
	}

if (cgiOptionalString("pbScaleStr") != NULL)
	{
	pbScale  = atoi(cgiOptionalString("pbScaleStr")); 
	}

if (cgiOptionalString("pbScale") != NULL)
    {
    scaleButtonPushed = TRUE;
    if (strcmp(cgiOptionalString("pbScale"), "1/6")  == 0) pbScale = 1;
    if (strcmp(cgiOptionalString("pbScale"), "1/2")  == 0) pbScale = 3;
    if (strcmp(cgiOptionalString("pbScale"), "FULL") == 0) pbScale = 6;
    if (strcmp(cgiOptionalString("pbScale"), "DNA")  == 0) pbScale =22;
    safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale);
    cgiMakeHiddenVar("pbScaleStr", pbScaleStr);
    }
else
    {
    scaleButtonPushed = FALSE;
    }

if (psOutput == NULL)
{
if (cgiVarExists("pbt.left3"))
    {
    relativeScroll(-0.95);
    initialWindow = FALSE;
    }
else if (cgiVarExists("pbt.left2"))
    {
    relativeScroll(-0.475);
    initialWindow = FALSE;
    }
else if (cgiVarExists("pbt.left1"))
    {
    relativeScroll(-0.02);
    initialWindow = FALSE;
    }
else if (cgiVarExists("pbt.right1"))
    {
    relativeScroll(0.02);
    initialWindow = FALSE;
    }
else if (cgiVarExists("pbt.right2"))
    {
    relativeScroll(0.475);
    initialWindow = FALSE;
    }
else if (cgiVarExists("pbt.right3"))
    {
    relativeScroll(0.95);
    initialWindow = FALSE;
    }
}

dnaUtilOpen();

l=strlen(aa);

/* initialize AA properties */
aaPropertyInit(&hasResFreq);
sfCount = getSuperfamilies2(proteinID);
if (sfCount == 0)
    {
    sfCount = getSuperfamilies(proteinID);
    }
if (mrnaID != NULL)
    {
    if (kgVersion == KG_III)
    	{
	doExonTrack = FALSE;
	sqlSafefFrag(cond_str, sizeof(cond_str), "spId='%s'", proteinID);
        kgId = sqlGetField(database, "kgXref", "kgId", cond_str);
	if (kgId != NULL)
	    {
	    sqlSafefFrag(cond_str, sizeof(cond_str), "name='%s'", kgId);
            kgPep = sqlGetField(database, "knownGenePep", "seq", cond_str);
      	    //printf("<pre><br>%s", kgPep);fflush(stdout);
	    if (kgPep != NULL)
	    	{
		if (strstr(protDbName, "proteins") != NULL)
		    {
		    protDbDate = strstr(protDbName, "proteins") + strlen("proteins");
		    safef(uniProtDbName, sizeof(uniProtDbName),"sp%s", protDbDate);
		
		    sqlSafefFrag(cond_str, sizeof(cond_str), "acc='%s'", proteinID);
            	    protPep = sqlGetField(uniProtDbName, "protein", "val", cond_str);
            	    //printf("<br>%s\n", protPep);fflush(stdout);
            	    if (protPep != NULL)
		    	{
			if (sameWord(kgPep, protPep))
			    {
			    //printf("<br>MATCH!\n");fflush(stdout);
		    	    sqlSafefFrag(cond_str, sizeof(cond_str), "qName='%s'", kgId);
            	    	    answer = sqlGetField(database, kgProtMapTableName, 
			    			 "qName", cond_str);
            	    	    if (answer != NULL)
			    	{
    			    	/* NOTE: passing in kgId instead of proteinID because
					 kgProtMap2's qName uses kgId instead of 
					 protein display ID */
    			    	getExonInfo(kgId, &exCount, &chrom, &strand);
			    	assert(exCount > 0);
				doExonTrack = TRUE;
			    	}
			    }
			/*
			else
			    {
			    chp1 = kgPep;
			    printf("<br>");
			    chp2 = protPep;
			    ll = strlen(kgPep);
			    if (strlen(protPep) < ll) ll= strlen(protPep);
			    for (i=0; i<ll; i++)
			    	{
				if (*chp1 != *chp2)
					{
					printf("%c", *chp1);
					}
				else
					{
					printf(".");
					}
				chp1++; chp2++;
				}
			    }
			    //printf("</pre>");fflush(stdout);
			*/
			}
		    }
		}
	    }
	}
    else
    	{
	doExonTrack = TRUE;
    	getExonInfo(proteinID, &exCount, &chrom, &strand);
    	assert(exCount > 0);
	}
    /* do the following only if pbTracks called doTracks() */
    if (initialWindow && IAmPbTracks)
	{
	prevGBOffsetSav = calPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID);
	trackOrigOffset = prevGBOffsetSav;
    	if (trackOrigOffset > (protSeqLen*pbScale - 600))
	    trackOrigOffset = protSeqLen*pbScale - 600;
	/* prevent negative value */
	if (trackOrigOffset < 0) trackOrigOffset = 0;
	}

    /* if this if for PDF/Postscript, the trackOrigOffset is already calculated previously,
        use the saved value */
    if (psOutput != NULL)
    	{
    	trackOrigOffset = atoi(cartOptionalString(cart, "pbt.trackOffset"));
    	}
    }

/*printf("<br>%d %d<br>%d %d\n", prevGBStartPos, prevGBEndPos, 
	blockGenomeStartPositive[exCount-1], blockGenomeStartPositive[0]); fflush(stdout);
*/
if (strand == '-')
    {
    if ((prevGBStartPos <= blockGenomeStartPositive[exCount-1]) && (prevGBEndPos >= blockGenomeStartPositive[0]))
    	{
    	showPrevGBPos = FALSE;
    	}
    }
else
    {
    if ((prevGBStartPos <= blockGenomeStartPositive[0]) && (prevGBEndPos >= blockGenomeStartPositive[exCount-1]))
    	{
    	showPrevGBPos = FALSE;
    	}
    }

if ((cgiOptionalString("aaOrigOffset") != NULL) && scaleButtonPushed)
     {
     trackOrigOffset = atoi(cgiOptionalString("aaOrigOffset"))*pbScale;
     }

pixWidth = 160+ protSeqLen*pbScale;
if (pixWidth > MAX_PB_PIXWIDTH)
   {
   pixWidth = MAX_PB_PIXWIDTH;
   }

if ((protSeqLen*pbScale - trackOrigOffset) < MAX_PB_PIXWIDTH)
    {
    pixWidth = protSeqLen*pbScale - trackOrigOffset + 160;
    }

if (pixWidth < 550) pixWidth = 550;

insideWidth = pixWidth-gfxBorder;

if (proteinInSupportedGenome)
    {
    pixHeight = 250;
    }
else
    {
    pixHeight = 215;
    }

if (sfCount > 0) pixHeight = pixHeight + 20;

/* make room for individual residues display */
if (pbScale >=6)  pixHeight = pixHeight + 20;
if (pbScale >=18) pixHeight = pixHeight + 30;

if (psOutput)
    {
    vg = vgOpenPostScript(pixWidth, pixHeight, psOutput);
    suppressHtml = TRUE;
    hideControls = TRUE;
    }
else
    {
    trashDirFile(&gifTn, "pbt", "pbt", ".png");
    vg = vgOpenPng(pixWidth, pixHeight, gifTn.forCgi, FALSE);
    }

/* Put up horizontal scroll controls. */
hWrites("Move ");
hButton("pbt.left3", "<<<");
hButton("pbt.left2", " <<");
hButton("pbt.left1", " < ");
hButton("pbt.right1", " > ");
hButton("pbt.right2", ">> ");
hButton("pbt.right3", ">>>");

hPrintf(" &nbsp &nbsp ");

/* Put up scaling controls. */
hPrintf("Current scale: ");
if (pbScale == 1)  hPrintf("1/6 ");
if (pbScale == 3)  hPrintf("1/2 ");
if (pbScale == 6)  hPrintf("FULL ");
if (pbScale == 22) hPrintf("DNA ");

hPrintf(" &nbsp&nbsp Rescale to ");
hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/6\">\n");
hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/2\">\n");
hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"FULL\">\n");
if (kgVersion == KG_III)
    {
    /* for KG III, the protein has to exist in the kgProtMap2 table 
       (which will turn on doExonTrack flag)
       to provide the genomic position data needed for DNA sequence display */
    if ((proteinInSupportedGenome) && (doExonTrack))
    hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n");
    }
else
    {
    if (proteinInSupportedGenome) 
   	hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n");
    }
hPrintf("<FONT SIZE=1><BR><BR></FONT>\n");

g_vg = vg;

pbRed    = vgFindColorIx(g_vg, 0xf9, 0x51, 0x59);
pbBlue   = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0);
bkgColor = vgFindColorIx(vg, 255, 254, 232);

vgBox(vg, 0, 0, insideWidth, pixHeight, bkgColor);

/* Start up client side map. */
hPrintf("<MAP Name=%s>\n", mapName);

vgSetClip(vg, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder);

/* start drawing indivisual tracks */

doAAScale(l, yOffp, 1);

if (pbScale >= 6)  doResidues(aa, l, yOffp);

if (pbScale >= 18) doDnaTrack(chrom, strand, exCount, l, yOffp);

if ((mrnaID != NULL) && showPrevGBPos)
    {
    doPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID);
    }

if (mrnaID != NULL)
    {
    if (doExonTrack) doExon(exCount, chrom, l, yOffp, proteinID, mrnaID);
    }

doCharge(aa, l, yOffp);

doHydrophobicity(aa, l, yOffp);

doCysteines(aa, l, yOffp);

if (sfCount > 0) doSuperfamily(ensPepName, sfCount, yOffp); 

if (hasResFreq) doAnomalies(aa, l, yOffp);

doAAScale(l, yOffp, -1);

vgClose(&vg);

/* Finish map and save out picture and tell html file about it. */
hPrintf("</MAP>\n");

/* put tracks image here */

hPrintf(
"\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>",
        gifTn.forCgi, pixWidth, pixHeight, mapName);

if (proteinInSupportedGenome)
    {
    hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>");
    }
else
    {
    if (hIsGsidServer())
	{
	hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbGsid/pbTracksHelp.shtml#tracks\" TARGET=_blank>");
    	}
    else
	{
	hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>");
    	}
    }

hPrintf("Explanation of Protein Tracks</A><br>");

safef(trackOffset, sizeof(trackOffset), "%d", trackOrigOffset);
cgiMakeHiddenVar("trackOffset", trackOffset);

/* remember where the AA base origin is so that it can be passed to next PB page */
aaOrigOffset = trackOrigOffset/pbScale;
safef(aaOrigOffsetStr, sizeof(aaOrigOffsetStr), "%d", aaOrigOffset);
cgiMakeHiddenVar("aaOrigOffset", aaOrigOffsetStr);

/* save the following state variables, to be used by PDF/Postcript processing */
cartSetString(cart,"pbt.pbScaleStr", pbScaleStr);
cartSetString(cart,"pbt.trackOffset", trackOffset);
cartSaveSession(cart);
fflush(stdout);
}
void doMiddle(struct cart *theCart)
/* Print the body of an html file.   */
{
char cond_str[255];
struct sqlConnection *conn;
char *proteinAC;
char *chp, *chp1, *chp9;
char *debugTmp = NULL;
char *chromStr, *cdsStartStr, *cdsEndStr, posStr[255];

char *supportedGenomeDatabase;
  
char *answer;
char *queryID;

/* Initialize layout and database. */
cart = theCart;

/* Uncomment this to see parameters for debugging. */
/* Be careful though, it breaks if custom track
 * is more than 4k */
/* 
{ struct dyString *state = cgiUrlString();
  hPrintf("State: %s\n", state->string); 
}
*/

queryID = cartOptionalString(cart, "proteinID");
if (sameString(queryID, ""))
    {
    errAbort("Please go back and enter a gene symbol or a Swiss-Prot/TrEMBL protein ID.\n");
    }
	    
if (cgiVarExists("db"))
    {
    /* if db is known, get key variables set */
    proteinInSupportedGenome = TRUE;
    database = cgiOptionalString("db");
    organism = hDbOrganism(database);
    protDbName = hPdbFromGdb(database);
    proteinID  = strdup(queryID);
    }
else 
    {
    protCntInSwissByGene = searchProteinsInSwissProtByGene(queryID);
    /* no CGI 'db' variable means it did not come in from GB but from pbGateway */
    /* search existing GB databases to see if this protein can be found */
    protCntInSupportedGenomeDb = 
    	searchProteinsInSupportedGenomes(queryID, &supportedGenomeDatabase);
    if ((protCntInSupportedGenomeDb > 1) || protCntInSwissByGene >= 1)
    	{
	/* more than 1 proteins match the query ID, present selection web page */
	proteinInSupportedGenome = 1;
	presentProteinSelections(queryID, protCntInSwissByGene, protCntInSupportedGenomeDb);
	return;
	}
    else
        {
	if (protCntInSupportedGenomeDb == 1)
	    {
	    /* one and only one protein found in a genome DB that support KG and PB */
	    proteinInSupportedGenome = TRUE;
	    database = strdup(supportedGenomeDatabase);
	    organism = hDbOrganism(database);
	    protDbName = hPdbFromGdb(database);
            proteinID=strdup(queryID);
	    }
	else
	    {
	    /* not found in genome DBs that support KG/PB */
	    /* now search PROTEOME_DB_NAMES to see if this protein is there. */
	    answer = uniProtFindPrimAcc(queryID);
	    if (answer == NULL)
		{
	        if (hIsGsidServer())
		    {
		    errAbort(
		    "'%s' does not seem to be a valid protein ID.<br><br>Click <A HREF=\"../cgi-bin/gsidPbGateway\">here</A> to start another query."
		    	    , queryID);
		    }
		else
		    {
		    errAbort(
		    "'%s' does not seem to be a valid UniProt(Swiss-Prot/TrEMBL) protein ID or a gene symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
		    	    , queryID);
		    }
	    	}
	    
	    proteinInSupportedGenome = FALSE;
	    database = strdup(GLOBAL_PB_DB);
	    organism = strdup("");
    	    protDbName = strdup(PROTEOME_DB_NAME);
	    proteinID = strdup(answer);
	    }
	}
    
    if (proteinInSupportedGenome)
        {
        spConn = sqlConnect(database);
        safef(cond_str, sizeof(cond_str), "alias='%s'", queryID);
        proteinID = sqlGetField(database, "kgSpAlias", "spID", cond_str);
    	
        safef(cond_str, sizeof(cond_str), "spID='%s'", proteinID);
        answer = sqlGetField(database, "kgXref", "spDisplayID", cond_str);
    	
	safef(cond_str, sizeof(cond_str), "proteinID='%s'", answer);
    	chromStr    = sqlGetField(database, "knownGene", "chrom", cond_str);
	if (chromStr)
	    {
	    cdsStartStr = sqlGetField(database, "knownGene", "cdsStart", cond_str);
	    cdsEndStr   = sqlGetField(database, "knownGene", "cdsEnd", cond_str);
	    safef(posStr, sizeof(posStr), "%s:%s-%s", chromStr, cdsStartStr, cdsEndStr);
	    positionStr = strdup(posStr);
	    cartSetString(cart, "position", positionStr);
	    cartSetString(cart, "organism", organism);
	    }
	}
    }
/* print out key variables for debugging */
/* printf("<br>before enter main section: <br>proteinInSupportedGenome=%d<br>proteinID=%s <br>database=%s <br>organism=%s <br>protDbName=%s\n",
proteinInSupportedGenome, proteinID, database, organism, protDbName);fflush(stdout);
*/

if (hTableExists(database, "kgProtMap2"))
    {
    kgVersion = KG_III;
    strcpy(kgProtMapTableName, "kgProtMap2");
    }
		
debugTmp = cartUsualString(cart, "hgDebug", "off");
if(sameString(debugTmp, "on"))
    hgDebug = TRUE;
else
    hgDebug = FALSE;
conn  = hAllocConn(database);
hgsid     = cartOptionalString(cart, "hgsid");
if (hgsid != NULL)
    {
    safef(hgsidStr, sizeof(hgsidStr), "&hgsid=%s", hgsid);
    }
else
    {
    strcpy(hgsidStr, "");
    }

/* check proteinID to see if it is a valid SWISS-PROT/TrEMBL accession or display ID */
/* then assign the accession number to global variable proteinID */
safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
if (proteinAC == NULL)
    {
    safef(cond_str, sizeof(cond_str), "displayID='%s'", proteinID);
    proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
    if (proteinAC == NULL)
	{
	if (hIsGsidServer())
	    {
    	    safef(cond_str, sizeof(cond_str), "acc='%s'", proteinID);
    	    proteinAC = sqlGetField(protDbName, "uniProtAlias", "acc", cond_str);
	    if (proteinAC != NULL)	
		{
		protDisplayID = proteinID;
		proteinID = proteinAC;
		}
	    else
	    	{
	    	errAbort("'%s' does not seem to be a valid protein ID.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
		, proteinID);
	    	}
	    }
	else
	    {
	    errAbort("'%s' does not seem to be a valid Swiss-Prot/TrEMBL protein ID or gene symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
	, proteinID);
	    }
	}
    else
	{
	protDisplayID = proteinID;
	proteinID = proteinAC;
	}
    }
else
    {
    safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
    protDisplayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str);
    }
    
if (proteinInSupportedGenome)
    {
    if (kgVersion == KG_III)
    	{
    	safef(cond_str, sizeof(cond_str), "spId='%s'", proteinID);
    	mrnaID = sqlGetField(database, "kgXref", "kgId", cond_str);
	}
    else
    	{
    	safef(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID);
    	mrnaID = sqlGetField(database, "knownGene", "name", cond_str);
    	}
    }
else
    {
    mrnaID = NULL;
    positionStr = NULL;
    }

safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
description = sqlGetField(protDbName, "spXref3", "description", cond_str);

if (positionStr != NULL)
    {
    chp = strstr(positionStr, ":");
    *chp = '\0';
    prevGBChrom = cloneString(positionStr);
    
    chp1 = chp + 1;
    chp9 = strstr(chp1, "-");
    *chp9 = '\0';
    prevGBStartPos = atoi(chp1);
    chp1 = chp9 + 1;
    prevGBEndPos   = atoi(chp1);
    }
else
    {
    prevGBChrom    = NULL;
    prevGBStartPos = -1;
    prevGBEndPos   = -1;
    }

/* Do main display. */
if (cgiVarExists("pbt.psOutput"))
    handlePostscript();
else
    {
    doTrackForm(NULL, NULL);
    }
}
void doStamps(char *proteinID, char *mrnaID, char *aa, struct vGfx *vg, int *yOffp)
/* draw proteome browser stamps */
{
int i,j,l;

char cond_str[200];
char *valStr;
char valStr2[50];
char *answer;
double pI=0.0;
double exonCount;
char *chp;
int len;
int cCnt;

int xPosition;
int yPosition;
int stampWidth, stampHeight;

int aaResCnt[30];
double aaResFreqDouble[30];
int aaResFound;
int totalResCnt;

double molWeight=0.0;
double hydroSum;
struct pbStamp *stampDataPtr;

for (j=0; j<23; j++)
    {
    aaResCnt[j] = 0;
    }

l=len = strlen(aa);
chp = aa;
for (i=0; i<l; i++)
    {
    aaResFound = 0;
    for (j=0; j<23; j++)
    	{
        if (*chp == aaAlphabet[j])
            {
            aaResFound = 1;
            aaResCnt[j] ++;
            }
        }
    chp++;
    }

totalResCnt = 0;
for (i=0; i<23; i++)
    {
    totalResCnt = totalResCnt + aaResCnt[i];
    }

for (i=0; i<20; i++)
    {
    aaResFreqDouble[i] = ((double)aaResCnt[i])/((double)totalResCnt);
    }

AllocVar(stampPictPtr);

stampWidth  = 75*(1+pbScale/3);
stampHeight = 60*(1+pbScale/3);
xPosition   = 15;
yPosition   = *yOffp + 135;
if (pbScale >= 6) yPosition = yPosition + 20;

boundaryColor = vgFindColorIx(g_vg, 170, 170, 170);

/* draw pI stamp */

safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
answer = sqlGetField(database, "pepPi", "count(*)", cond_str);

/* either 0 or multiple rows are not valid */
if (strcmp(answer, "1") == 0)
    {
    answer = sqlGetField(database, "pepPi", "pI", cond_str);
    pI     = (double)atof(answer);
    stampDataPtr = getStampData("pepPi");
    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    drawPbStamp(stampDataPtr, stampPictPtr);
    drawXScaleNonInt(stampDataPtr, stampPictPtr, 2);
    safef(valStr2, sizeof(valStr2), "%.1f", pI);
    markStamp(stampDataPtr, stampPictPtr, pI, valStr2, tx, ty);
    pbStampFree(&stampDataPtr);
    }
else
    {
    stampDataPtr = getStampData("pepPi");
    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    drawPbStamp(stampDataPtr, stampPictPtr);
    drawXScale(stampDataPtr, stampPictPtr, 2);
    safef(valStr2, sizeof(valStr2), "N/A");
    markStamp0(stampDataPtr, stampPictPtr, pI, valStr2, tx, ty);
    pbStampFree(&stampDataPtr);
    }

/* skip Mol Wt, if it is GSID */
if (!hIsGsidServer())
    {
    /* draw Mol Wt stamp */
    safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
    answer = sqlGetField(database, "pepMwAa", "MolWeight", cond_str);
    if (answer != NULL)
    	{
    	safef(valStr2, sizeof(valStr2), "%s Da", answer);
    	molWeight  = (double)atof(answer);
    	stampDataPtr = getStampData("pepMolWt");
    	xPosition = xPosition + stampWidth + stampWidth/8;
    	setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	drawXScaleMW(stampDataPtr, stampPictPtr, 50000);
    	markStamp(stampDataPtr, stampPictPtr, molWeight, valStr2, tx, ty);
    	pbStampFree(&stampDataPtr);
    	}
    else
    	{
    	safef(valStr2, sizeof(valStr2), "N/A");
    	stampDataPtr = getStampData("pepMolWt");
    	xPosition = xPosition + stampWidth + stampWidth/8;
    	setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	drawXScaleMW(stampDataPtr, stampPictPtr, 50000);
    	markStamp0(stampDataPtr, stampPictPtr, molWeight, valStr2, tx, ty);
    	pbStampFree(&stampDataPtr);
    	}
    }
    
if (!proteinInSupportedGenome)
	{
	if (!hIsGsidServer())
	    xPosition = xPosition + stampWidth + stampWidth/8;
	goto skip_exon;
	}
	
/* draw exon count stamp */
if (kgVersion == KG_III)
    {
    safef(cond_str, sizeof(cond_str), "qName='%s'", mrnaID);
    }
else
    {
    safef(cond_str, sizeof(cond_str), "qName='%s'", proteinID);
    }
answer = sqlGetField(database, kgProtMapTableName, "blockCount", cond_str);
if (answer != NULL)
    {
    valStr       = cloneString(answer);
    exonCount    = (double)atoi(answer);
    stampDataPtr = getStampData("exonCnt");
    xPosition = xPosition + stampWidth + stampWidth/8;
    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    drawPbStamp(stampDataPtr, stampPictPtr);
    drawXScale(stampDataPtr, stampPictPtr, 5);
    markStamp(stampDataPtr, stampPictPtr, exonCount, valStr, tx, ty);
    pbStampFree(&stampDataPtr);
    }
skip_exon:

if (!hIsGsidServer())
    {
    /* draw AA residual anomolies stamp */
    if (answer != NULL)
    	{
    	stampDataPtr = getStampData("pepRes");
    	xPosition = xPosition + stampWidth + stampWidth/8;
    	setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, 
		       3*stampWidth/2, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	for (i=0; i<20; i++)
	    {
            markResStamp(aaAlphabet[i], stampDataPtr, stampPictPtr, i, aaResFreqDouble[i], 
			tx, ty, avg, stddev);
	    }
    	pbStampFree(&stampDataPtr);
    	}

    xPosition = 15;
    yPosition = yPosition + 170;
    }

/* skip swInterPro if it is GSID */
if (!hIsGsidServer())
    {

    /* draw family size stamp */
    safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
    answer = sqlGetField(protDbName, "swInterPro", "count(*)", cond_str);
    if (answer != NULL)
    	{
    	valStr       = cloneString(answer);
    	stampDataPtr = getStampData("intPCnt");
    	setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	drawXScale(stampDataPtr, stampPictPtr, 1);
    	markStamp(stampDataPtr, stampPictPtr, (double)(atoi(answer)), valStr, tx, ty);
    	pbStampFree(&stampDataPtr);
    	}
    else
    	{
    	valStr       = cloneString("N/A");
    	stampDataPtr = getStampData("intPCnt");
    	setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	drawXScale(stampDataPtr, stampPictPtr, 1);
    	markStamp0(stampDataPtr, stampPictPtr, (double)(atoi(answer)), valStr, tx, ty);
    	pbStampFree(&stampDataPtr);
    	}
    }

/* draw hydrophobicity stamp */
chp      = protSeq;
hydroSum = 0;
for (i=0; i<protSeqLen; i++)
    {
    hydroSum = hydroSum + aa_hydro[(int)(*chp)];
    chp++;
    }
stampDataPtr = getStampData("hydro");
xPosition = xPosition + stampWidth + stampWidth/8;
setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
drawPbStamp(stampDataPtr, stampPictPtr);
drawXScaleHydro(stampDataPtr, stampPictPtr, 1.0);
safef(valStr2, sizeof(valStr2), "%.1f", hydroSum/(double)len);
markStamp(stampDataPtr, stampPictPtr, hydroSum/(double)len, valStr2, tx, ty);
pbStampFree(&stampDataPtr);

/* draw Cystein Count stamp */
chp  = protSeq;
cCnt = 0;
for (i=0; i<len; i++)
    {
    if (*chp == 'C') cCnt ++;
    chp++;
    }
stampDataPtr = getStampData("cCnt");
xPosition = xPosition + stampWidth + stampWidth/8;
setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
drawPbStamp(stampDataPtr, stampPictPtr);
drawXScale(stampDataPtr, stampPictPtr, 10);
safef(valStr2, sizeof(valStr2), "%d", cCnt);
markStamp(stampDataPtr, stampPictPtr, (double)cCnt, valStr2, tx, ty);
pbStampFree(&stampDataPtr);

/* if it is GSID, draw AA residual anomolies here */
if (hIsGsidServer())
    {
    xPosition = 15;
    yPosition = yPosition + 170;

    /* draw AA residual anomolies stamp */
    if (answer != NULL)
    	{
    	stampDataPtr = getStampData("pepRes");
        setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, 
	3*stampWidth/2, stampHeight);
    	drawPbStamp(stampDataPtr, stampPictPtr);
    	for (i=0; i<20; i++)
            {
            markResStamp(aaAlphabet[i], stampDataPtr, stampPictPtr, i, aaResFreqDouble[i],
                         tx, ty, avg, stddev);
            }
    	pbStampFree(&stampDataPtr);
    	}
    }

/* draw AA residual anomolies stddev stamp */
if (answer != NULL)
    {
    exonCount    = (double)atof(answer);
    stampDataPtr = getStampData("pepRes");
if (hIsGsidServer())
    {
    xPosition = xPosition + stampWidth*1.62 + stampWidth/8;
    }
else
    {
    xPosition = xPosition + stampWidth + stampWidth/8;
    }

    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, 3*stampWidth/2, stampHeight);
    
    stampDataPtr->ymin = -4.0;
    stampDataPtr->ymax =  4.0;
    for (i=0; i<20; i++)
	{
        markResStdvStamp(stampDataPtr, stampPictPtr, i, aaResFreqDouble[i], tx, ty, avg, stddev);
	}

    /* draw background after bars drawn so that "... stddev" labels do not get covered by bars */
    stampDataPtr = getStampData("pepRes");
    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, 3*stampWidth/2, stampHeight);
    drawPbStampB(stampDataPtr, stampPictPtr);

    pbStampFree(&stampDataPtr);
    }

/* The follwing section was used to plot freq distribution for each AA so that we can view than to decide on 
   whether +/- 2 stddev is applicable and what cutoff thresholds to use.  Keep it here for possible 
   future reuse. */
/*
vertLabel = cloneString("Frequency");
for (i=strlen(vertLabel)-1; i>=0; i--)
    {
    vertLabel[i+1] = '\0';
    vgTextCentered(g_vg, 3, 45+i*10, 10, 10, MG_BLACK, g_font, vertLabel+i);
    vgTextCentered(g_vg, 3, 215+i*10, 10, 10, MG_BLACK, g_font, vertLabel+i);
    }

xPosition = xPosition + 80;
for (j=0; j<20; j++)
    {
    safef(tempStr, sizeof(tempStr), "%c", aaAlphabet[j]);
    stampDataPtr = getStampData(tempStr);

    xPosition = xPosition + stampWidth + stampWidth/8;
    setPbStampPict(stampPictPtr, stampDataPtr, xPosition, yPosition, stampWidth, stampHeight);
    drawPbStamp(stampDataPtr, stampPictPtr);
    drawXScale(stampDataPtr, stampPictPtr, 10);
    safef(valStr2, sizeof(valStr2), "%c", aaAlphabet[j]);
    markStamp(stampDataPtr, stampPictPtr, 0.0, valStr2, tx, ty);
    pbStampFree(&stampDataPtr);
    }
*/
}