/* pbTracksGlobal.c - UCSC Global Proteome Browser main cgi script. */
#include "common.h"
#include "hCommon.h"
#include "portable.h"
#include "jksql.h"
#include "vGfx.h"
#include "cheapcgi.h"
#include "htmshell.h"
#include "cart.h"
#include "hdb.h"
#include "web.h"
#include "hgColors.h"
#include "hui.h"
#include "spDb.h"
#include "pbStamp.h"
#include "pbStampPict.h"
#include "pbTracks.h"
#include "trashDir.h"
#include "psGfx.h"
boolean hgDebug = FALSE; /* Activate debugging code. Set to true by hgDebug=on in command line*/
struct cart *cart; /* The cart where we keep persistent variables. */
/* These variables persist from one incarnation of this program to the
* next - living mostly in the cart. */
char *database; /* Name of database we're using. */
char *organism; /* Name of organism we're working on. */
char *hgsid;
char hgsidStr[50];
boolean IAmPbTracks = FALSE;
int kgVersion = KG_UNKNOWN;
boolean proteinInSupportedGenome; /* The protein is in supported genome DB */
int protCntInSupportedGenomeDb; /* The protein count in supported genome DBs */
int protCntInSwissByGene; /* The protein count from gene search in Swiss-Prot */
int gfxBorder = 1; /* Width of graphics border. */
int insideWidth; /* Width of area to draw tracks in in pixels. */
char *protDbName; /* Name of proteome database for this genome. */
struct tempName gifTn, gifTn2; /* gifTn for tracks image and gifTn2 for stamps image */
boolean hideControls = FALSE; /* Hide all controls? */
boolean suppressHtml = FALSE; /* If doing PostScript output we'll suppress most
* of HTML output. */
char *proteinID;
char *protDisplayID;
char *mrnaID;
char *description;
char *positionStr;
char *prevGBChrom; /* chrom previously chosen by Genome Browser */
int prevGBStartPos; /* start position previously chosen by Genome Browser */
int prevGBEndPos; /* end position previously chosen by Genome Browser */
int prevExonStartPos; /* start position chosen by Genome Browser, converted to exon pos */
int prevExonEndPos; /* end position chosen by Genome Browser, converted to exon pos */
char *ensPepName; /* Ensembl peptide name, used for Superfamily track */
int sfCount; /* count of Superfamily domains */
struct sqlConnection *spConn; /* Connection to SwissProt database. */
char aaAlphabet[30] = {"WCMHYNFIDQKRTVPGEASLXZB"};
char *protSeq;
int protSeqLen;
char aaChar[20];
float aa_hydro[256];
int aa_attrib[256];
char aa[100000];
struct vGfx *g_vg;
MgFont *g_font;
Color pbRed, pbBlue;
int currentYoffset;
int pbScale = {6};
char pbScaleStr[5];
boolean scaleButtonPushed;
double tx[100000], ty[100000];
double xScale = 50.0;
double yScale = 100.0;
struct pbStampPict *stampPictPtr;
double avg[20];
double stddev[20];
int exStart[500], exEnd[500];
int exCount;
int aaStart[500], aaEnd[500];
char kgProtMapTableName[20] = {"kgProtMap"};
int blockSize[500], blockSizePositive[500];
int blockStart[500], blockStartPositive[500];
int blockEnd[500], blockEndPositive[500];
int blockGenomeStart[500], blockGenomeStartPositive[500];
int blockGenomeEnd[500], blockGenomeEndPositive[500];
int trackOrigOffset = 0; /* current track display origin offset */
int aaOrigOffset = 0; /* current track AA base origin offset */
boolean initialWindow = TRUE;
struct vGfx *vg, *vg2;
Color bkgColor;
Color abnormalColor;
Color normalColor;
void dvPrintf(char *format, va_list args)
/* Suppressable variable args hPrintf. */
{
char temp[1000];
safef(temp, sizeof(temp), "
%s", format);
vprintf(temp, args);
fflush(stdout);
}
/* used for debugging only */
/* #include "dPrint.c" */
void hvPrintf(char *format, va_list args)
/* Suppressable variable args hPrintf. */
{
if (!suppressHtml)
vprintf(format, args);
}
void hPrintf(char *format, ...)
/* Printf that can be suppressed if not making
* html. */
{
va_list(args);
va_start(args, format);
hvPrintf(format, args);
va_end(args);
}
void smallBreak()
/* Draw small horizontal break */
{
hPrintf("
\n");
}
void makeActiveImagePB(char *psOutput, char *psOutput2)
/* Make image and image map. */
{
char *mapName = "map";
int pixWidth, pixHeight;
char *answer;
char cond_str[255];
struct sqlConnection *conn;
struct sqlConnection *connCentral;
char query[256];
struct sqlResult *sr;
char **row;
int iypos;
char *blatGbDb;
char *sciName, *commonName;
char *spDisplayId;
char *oldDisplayId;
conn = sqlConnect(UNIPROT_DB_NAME);
hPrintf("
Protein ");
hPrintf("%s\n",
proteinID, proteinID);
spDisplayId = spAccToId(conn, spFindAcc(conn, proteinID));
if (strstr(spDisplayId, spFindAcc(conn, proteinID)) == NULL)
{
hPrintf(" (aka %s", spDisplayId);
/* show once if the new and old displayId are the same */
oldDisplayId = oldSpDisplayId(spDisplayId);
if (oldDisplayId != NULL)
{
if (!sameWord(spDisplayId, oldDisplayId))
{
hPrintf(" or %s", oldSpDisplayId(spDisplayId));
}
}
hPrintf(")\n");
}
hPrintf(" %s\n", description);
hPrintf("
");
hPrintf("Organism: ");
/* get scientific and Genbank common name of this organism */
sciName = NULL;
commonName = NULL;
safef(cond_str, sizeof(cond_str),"accession='%s'", proteinID);
answer = sqlGetField(PROTEOME_DB_NAME, "spXref3", "division", cond_str);
if (answer != NULL)
{
safef(cond_str, sizeof(cond_str), "id=%s and nameType='scientific name'", answer);
sciName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str);
safef(cond_str, sizeof(cond_str), "id=%s and nameType='genbank common name'", answer);
commonName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str);
}
if (sciName != NULL)
{
hPrintf("%s", sciName);
}
if (commonName != NULL)
{
hPrintf(" (%s)", commonName);
}
hPrintf("
");
protSeq = getAA(proteinID);
if (protSeq == NULL)
{
hUserAbort("%s is not a current valid entry in UniProtKB\n", proteinID);
}
protSeqLen = strlen(protSeq);
fflush(stdout);
iypos = 15;
doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput);
if (!hTableExists(database, "pbStamp")) goto histDone;
pbScale = 3;
pixWidth = 765;
insideWidth = pixWidth-gfxBorder;
pixHeight = 350;
if (psOutput2)
{
vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2);
}
else
{
trashDirFile(&gifTn2, "pbt", "pbt", ".png");
vg2 = vgOpenPng(pixWidth, pixHeight, gifTn2.forCgi, FALSE);
}
g_vg = vg2;
pbRed = vgFindColorIx(vg2, 0xf9, 0x51, 0x59);
pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0);
normalColor = pbBlue;
abnormalColor = pbRed;
bkgColor = vgFindColorIx(vg2, 255, 254, 232);
vgBox(vg2, 0, 0, insideWidth, pixHeight, bkgColor);
/* Start up client side map. */
mapName=cloneString("pbStamps");
hPrintf("\n\n");
/* Save out picture and tell html file about it. */
vgClose(&vg2);
hPrintf("
");
hPrintf("\n
",
gifTn2.forCgi, pixWidth, pixHeight, mapName);
if (proteinInSupportedGenome)
{
hPrintf("\n");
}
else
{
hPrintf("\n");
}
hPrintf("Explanation of Protein Property Histograms
");
hPrintf("
"); histDone: hPrintf("
");
fflush(stdout);
/* See if a UCSC Genome Browser exist for this organism. If so, display BLAT link. */
connCentral = hConnectCentral();
safef(query, sizeof(query),
"select defaultDb.name from dbDb, defaultDb where dbDb.scientificName='%s' and dbDb.name=defaultDb.name",
sciName);
sr = sqlGetResult(connCentral, query);
row = sqlNextRow(sr);
if (row != NULL)
{
blatGbDb = strdup(row[0]);
}
else
{
blatGbDb = NULL;
}
sqlFreeResult(&sr);
hDisconnectCentral(&connCentral);
if (proteinInSupportedGenome || (blatGbDb != NULL))
{
hPrintf("\nUCSC Links:
\n ");
hPrintf("
"); } /* This section shows various types of domains */ conn = sqlConnect(UNIPROT_DB_NAME); domainsPrint(conn, proteinID); hPrintf("
"); /* Do Pathway section only if the protein belongs to a supported genome */ if (proteinInSupportedGenome); { doPathwayLinks(proteinID, mrnaID); } printFASTA(proteinID, protSeq); } void doTrackForm(char *psOutput, char *psOutput2) /* Make the tracks display form */ { if (psOutput != NULL) { suppressHtml = TRUE; hideControls = TRUE; } /* Tell browser where to go when they click on image. */ hPrintf("
"); } void handlePostscript() /* Deal with Postscript output. */ { struct tempName psTn; struct tempName psTn2; char *pdfFile = NULL; trashDirFile(&psTn, "pbt", "pbt", ".eps"); trashDirFile(&psTn2, "pbt", "pbt2", ".eps"); printf("