/************************************************************* Date: 06/23/2000 Purpose: This program works in conjunction with the addxpress program to graphically display the light & heavy ICAT peptide elution profiles. User is able to adjust the start & end scans for the above profile displays which updates the quantitation ratio calculations based on the new peak start/end determination. Copyright: Jimmy Eng, Copyright (c) Institute for Systems Biology, 2000. All rights reserved. License: Use/distribution of this Program is goverened by the following terms: 1. You may copy and distribute copies of the Program (as source code or executables), in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, must print or display an announcement including the appropriate copyright notice (shown above) and the terms of this License. 3. By modifying or distributing the Program or any work derived from the Program, you indicate your acceptance of this License. Modifications: 06/30/2000 Need to add in plotting 10/19/2000 Modify variable names, clean up analysis 02/02/2001 Plot out smoothed spectrum 03/06/2001 Add in button to update quantitation in all interact-data files. 03/15/2001 Add in bXpressLight1 option (set light or heavy quan to 1) 04/01/2001 Remove Peptide= link ... only use filename/scan# to ID summary lines to update 06/22/2001 Add in link to update=bad data 09/13/2001 Add in random number generator for image filename 04/15/2002 Update to receive interact base filename and pass to updatecgixpress 07/01/2002 Buttons to swap heavy/light masses for RIC *************************************************************/ #include #include #include #include #include #include #ifdef WIN32 #include "d:\sequest\icatratio\machine.h" #include "d:\sequest\icatratio\oap_private.h" #else #include "icis/machine.h" #include "icis/oap_private.h" #endif /* * Include gd library to create gif files * see http://www.boutell.com/gd/ */ #include "gd.h" #include "gdfonts.h" #define szVERSION "XPRESS v.2" #define szAUTHOR "by J.Eng © Institute for Systems Biology, 2000. All rights reserved." #define SIZE_FILE 256 #define MAX_MS_SCANS 20000 #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define SCALE_V(x,y,z,w) (int)((x-y)*z/w); int bXpressLight1; char szDatFile[SIZE_FILE], szOutputFile[SIZE_FILE], szInteractBaseName[SIZE_FILE], szInteractDir[SIZE_FILE]; struct QuanStruct { int iquantitation_id; int iChargeState; int iSwapMass; int iLightFirstScan; int iLightLastScan; int iHeavyFirstScan; int iHeavyLastScan; double dLightPeptideMass; double dHeavyPeptideMass; double dLightQuanValue; double dHeavyQuanValue; double dMassTol; char bLightPeptide; char szNewQuan[20]; } pQuan; void PRINT_FORM(char *szArgv0, struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile); void EXTRACT_QUERY_STRING(struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile, char *szInteractDir, char *szInteractBaseName, int *bXpressLight1); void GET_PARAMETERS(struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile, char *szInteractDir, int *bXpressLight1); void GET_QUANTITATION(char *szDatFile, struct QuanStruct *pQuan); void MAKE_PLOT(int iPlotStartScan, int iPlotEndScan, int iLightStartScan, int iLightEndScan, int iHeavyStartScan, int iHeavyEndScan, double dMaxLightInten, double dMaxHeavyInten, double *pdLight, double *pdHeavy, double *dLightFiltered, double *dHeavyFiltered, struct QuanStruct *pQuan); void FILTER_MS(double *dOrigMS, double *dFilteredMS, double *dTmpFilter, double dMaxInten, int iNumMSScans, int iPlotStartScan, int iPlotEndScan); void UPDATE_QUAN(void); void BAD_QUAN(void); extern void getword(char *word, char *line, char stop); extern void unescape_url(char *url); extern void plustospace(char *str); int main(int argc, char **argv) { /* * Print html header */ printf("Content-type: text/html\n\n"); printf("\n%s, %s\n", szVERSION, szAUTHOR); printf("\n"); szDatFile[0]='\0'; szOutputFile[0]='\0'; szInteractDir[0]='\0'; szInteractBaseName[0]='\0'; bXpressLight1=0; EXTRACT_QUERY_STRING(&pQuan, szDatFile, szOutputFile, szInteractDir, szInteractBaseName, &bXpressLight1); if (pQuan.iquantitation_id>0 && strlen(szInteractDir)==0) { GET_PARAMETERS(&pQuan, szDatFile, szOutputFile, szInteractDir, &bXpressLight1); } if (pQuan.iSwapMass==1) { pQuan.dHeavyPeptideMass = pQuan.dLightPeptideMass; pQuan.dLightPeptideMass -= 8.0; } else if (pQuan.iSwapMass==2) { pQuan.dLightPeptideMass = pQuan.dHeavyPeptideMass; pQuan.dHeavyPeptideMass += 8.0; } PRINT_FORM(argv[0], &pQuan, szDatFile, szOutputFile); GET_QUANTITATION(szDatFile, &pQuan); printf("\n"); printf("
"); if (strlen(szInteractDir)>1) { BAD_QUAN(); } printf(""); printf("
"); printf("\n"); if (pQuan.dLightQuanValue!=0.0) printf("\n", pQuan.dHeavyQuanValue / pQuan.dLightQuanValue); else printf("\n"); if (pQuan.dHeavyQuanValue!=0.0) printf("\n", pQuan.dLightQuanValue / pQuan.dHeavyQuanValue); else printf("\n"); printf("
Light:Heavy
1:%0.2f
1:NaN
%0.2f:1
NaN:1
\n"); if (bXpressLight1==1) { if (pQuan.dLightQuanValue == 0.0) sprintf(pQuan.szNewQuan, "1:INF"); else sprintf(pQuan.szNewQuan, "1:%0.2f", pQuan.dHeavyQuanValue / pQuan.dLightQuanValue); } else if (bXpressLight1==2) { if (pQuan.dHeavyQuanValue == 0.0) sprintf(pQuan.szNewQuan, "INF:1"); else sprintf(pQuan.szNewQuan, "%0.2f:1", pQuan.dLightQuanValue / pQuan.dHeavyQuanValue); } else { if (pQuan.dLightQuanValue==0.0 && pQuan.dHeavyQuanValue==0.0) sprintf(pQuan.szNewQuan, "?"); else if (pQuan.dLightQuanValue > pQuan.dHeavyQuanValue) sprintf(pQuan.szNewQuan, "1:%0.2f", pQuan.dHeavyQuanValue / pQuan.dLightQuanValue); else sprintf(pQuan.szNewQuan, "%0.2f:1", pQuan.dLightQuanValue / pQuan.dHeavyQuanValue); } printf("
"); if (strlen(szInteractDir)>1) { UPDATE_QUAN(); } printf("
\n"); printf("

See "); printf("http://www.boutell.com/gd/ for info. on the gd graphics library used by this program\n"); printf("\n"); return(0); } /*main*/ void PRINT_FORM(char *szArgv0, struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile) { printf("%s, %s\n", szVERSION, szAUTHOR); #ifdef WIN32 printf("

"); #else /* printf("", szArgv0); */ printf("", szArgv0); #endif printf("\n", pQuan->iquantitation_id); printf("\n", szInteractDir); printf("\n", szInteractBaseName); printf("\n", bXpressLight1); printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("Light scans:"); printf(" \n", pQuan->iLightFirstScan); printf(" \n", pQuan->iLightLastScan); printf(" mass:\n", pQuan->dLightPeptideMass); printf(" tol: ", pQuan->dMassTol); printf("
Heavy scans:"); printf(" \n", pQuan->iHeavyFirstScan); printf(" \n", pQuan->iHeavyLastScan); printf(" mass:\n", pQuan->dHeavyPeptideMass); printf("

 Raw file: \n", szDatFile); printf("
.out file: ", szOutputFile); printf("

\n
Charge
"); printf("+1
\n", ((pQuan->iChargeState)==1?"checked":"")); printf("+2
\n", ((pQuan->iChargeState)==2?"checked":"")); printf("+3
\n", ((pQuan->iChargeState)==3?"checked":"")); printf("

"); printf("
"); printf("no mass swap "); printf("   swap light to heavy "); printf("   swap heavy to light
"); printf("
\n"); printf("
\n"); } /*PRINT_FORM*/ void EXTRACT_QUERY_STRING(struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile, char *szInteractDir, char *szInteractBaseName, int *bXpressLight1) { char *pStr = getenv("REQUEST_METHOD"); if (pStr==NULL) { printf(" Error - this is a CGI program that cannot be\n"); printf(" run from the command line.\n\n"); exit(EXIT_FAILURE); } else if (!strcmp(pStr, "GET")) { int i; char *szQuery, szWord[512]; /* * Get: * ChargeState - charge state of precursor */ szQuery = getenv("QUERY_STRING"); if (szQuery == NULL) { printf("

No query information to decode.\n"); printf("\n\n"); exit(EXIT_FAILURE); } for (i=0; szQuery[0] != '\0'; i++) { getword(szWord, szQuery, '='); plustospace(szWord); unescape_url(szWord); if (!strcmp(szWord, "LightFirstScan")) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iLightFirstScan)); } else if (!strcmp(szWord, "LightLastScan") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iLightLastScan)); } else if (!strcmp(szWord, "HeavyFirstScan") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iHeavyFirstScan)); } else if (!strcmp(szWord, "HeavyLastScan") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iHeavyLastScan)); } else if (!strcmp(szWord, "DatFile") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%s", szDatFile); } else if (!strcmp(szWord, "OutFile") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%s", szOutputFile); } else if (!strcmp(szWord, "InteractDir") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%s", szInteractDir); } else if (!strcmp(szWord, "InteractBaseName") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%s", szInteractBaseName); } else if (!strcmp(szWord, "ChargeState") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iChargeState)); } else if (!strcmp(szWord, "SwapMass") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iSwapMass)); } else if (!strcmp(szWord, "LightMass") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%lf", &(pQuan->dLightPeptideMass)); } else if (!strcmp(szWord, "HeavyMass") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%lf", &(pQuan->dHeavyPeptideMass)); } else if (!strcmp(szWord, "MassTol") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%lf", &(pQuan->dMassTol)); } else if (!strcmp(szWord, "bXpressLight1") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", bXpressLight1); } else if (!strcmp(szWord, "quantitation_id") ) { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); sscanf(szWord, "%d", &(pQuan->iquantitation_id)); } else { getword(szWord, szQuery, '&'); plustospace(szWord); unescape_url(szWord); } } /*for*/ } else { printf(" Error not called with GET method\n"); exit(EXIT_FAILURE); } } /*EXTRACT_QUERY_STRING*/ /*############################################################################# # try_tds_login - Make the connection to the database #############################################################################*/ int try_tds_login( TDSLOGIN **login, TDSSOCKET **tds, char *appname, int verbose) { TDSCONTEXT *context; int DEBUG=FALSE; #ifdef MACROGENICS static char SERVER[] = "mssql"; static char USER[] = "macrog_ro"; static char PASSWORD[] = "RockMD"; #else static char SERVER[] = "mssql"; static char USER[] = "sbeams"; static char PASSWORD[] = "SB444"; #endif if (verbose || DEBUG) { fprintf(stdout, "Entered tds_try_login()
\n"); } if (! login) { fprintf(stderr, "Invalid TDSLOGIN**\n"); return TDS_FAIL; } if (! tds) { fprintf(stderr, "Invalid TDSSOCKET**\n"); return TDS_FAIL; } if (verbose || DEBUG) { fprintf(stdout, "Setting login parameters
\n"); } *login = tds_alloc_login(); if (! *login) { fprintf(stderr, "tds_alloc_login() failed.
\n"); return TDS_FAIL; } tds_set_passwd(*login, PASSWORD); tds_set_user(*login, USER); tds_set_app(*login, appname); tds_set_host(*login, "myhost"); tds_set_library(*login, "TDS-Library"); tds_set_server(*login, SERVER); tds_set_charset(*login, "iso_1"); tds_set_language(*login, "us_english"); tds_set_packet(*login, 512); if (verbose || DEBUG) { fprintf(stdout, "Connecting to database
\n"); } //*tds = tds_connect(*login, NULL); context = tds_alloc_context(); *tds = tds_connect(*login,context,NULL); if (! *tds) { fprintf(stderr, "tds_connect() failed
\n"); return TDS_FAIL; } if (verbose || DEBUG) { fprintf(stdout, "Connected.
\n"); } return TDS_SUCCEED; } /*try_tds_login*/ /*############################################################################# # GET_PARAMETERS from the database given quantitation_id #############################################################################*/ void GET_PARAMETERS(struct QuanStruct *pQuan, char *szDatFile, char *szOutputFile, char *szInteractDir, int *bXpressLight1) { TDSLOGIN *login; TDSSOCKET *tds; int verbose = 0; int num_cols = 2; int rc; int i,col_idx; int iStrLength; int DEBUG=FALSE; char column_name[255]; int type; char *ptr_row; int offset; void *ptr_value; char sql_query[1024],tmp1[1024]; #ifdef MACROGENICS static char DATABASE[] = "MGproteomics"; #else static char DATABASE[] = "proteomics"; #endif //#### Build the query string if (DEBUG) printf("\n\nquantition_id = %d
\n\n\n\n\n",pQuan->iquantitation_id); sprintf(sql_query," USE %s SELECT d0_first_scan,d0_last_scan,d0_mass,d8_first_scan,d8_last_scan,d8_mass, norm_flag,mass_tolerance,SB.data_location+'/../'+ F.fraction_tag AS 'dat_file',S.assumed_charge FROM dbo.quantitation Q JOIN dbo.search_hit SH ON ( Q.search_hit_id = SH.search_hit_id ) JOIN dbo.search S ON ( SH.search_id = S.search_id ) JOIN dbo.search_batch SB ON ( S.search_batch_id = SB.search_batch_id ) JOIN dbo.msms_spectrum MSS ON ( S.msms_spectrum_id = MSS.msms_spectrum_id ) JOIN dbo.fraction F ON ( MSS.fraction_id = F.fraction_id ) WHERE quantitation_id = '%d'", DATABASE,pQuan->iquantitation_id); //#### Connect and login to database rc = try_tds_login(&login, &tds, "Xpress.cgi", verbose); if (rc != TDS_SUCCEED) { fprintf(stderr, "try_tds_login() failed\n"); return; } //#### Issue query if (DEBUG) printf("

\n%s\n\n
\n",sql_query); rc = tds_submit_query(tds,sql_query); if (rc != TDS_SUCCEED) { fprintf(stderr, "tds_submit_query() failed\n"); printf("tds_submit_query() failed
\n"); return; } //#### Loop over all returned result sets while ((rc=tds_process_result_tokens(tds))==TDS_SUCCEED) { //#### Determine number of columns in this result set num_cols = tds->res_info->num_cols; if (DEBUG) printf("Number of columns in resultset: %d
\n",num_cols); //#### Loop over all rows in the result set while ((rc=tds_process_row_tokens(tds))==TDS_SUCCEED) { //#### Loop over all columns in the row, processing certain values for (col_idx=0; col_idxres_info->columns[col_idx]->column_name); type = tds->res_info->columns[col_idx]->column_type; ptr_row = tds->res_info->current_row; offset = tds->res_info->columns[col_idx]->column_offset; ptr_value = (ptr_row+offset); if (strcmp(column_name,"d0_first_scan")==0) { pQuan->iLightFirstScan = *(int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,pQuan->iLightFirstScan); } else if (strcmp(column_name,"d0_last_scan")==0) { pQuan->iLightLastScan = *(int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,pQuan->iLightLastScan); } else if (strcmp(column_name,"d0_mass")==0) { pQuan->dLightPeptideMass = *(float *)ptr_value; if (DEBUG) printf(" %s = %f
\n",column_name,pQuan->dLightPeptideMass); } else if (strcmp(column_name,"d8_first_scan")==0) { pQuan->iHeavyFirstScan = *(int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,pQuan->iHeavyFirstScan); } else if (strcmp(column_name,"d8_last_scan")==0) { pQuan->iHeavyLastScan = *(int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,pQuan->iHeavyLastScan); } else if (strcmp(column_name,"d8_mass")==0) { pQuan->dHeavyPeptideMass = *(float *)ptr_value; if (DEBUG) printf(" %s = %f
\n",column_name,pQuan->dHeavyPeptideMass); } else if (strcmp(column_name,"norm_flag")==0) { bXpressLight1 = (int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,*bXpressLight1); } else if (strcmp(column_name,"mass_tolerance")==0) { pQuan->dMassTol = *(float *)ptr_value; if (DEBUG) printf(" %s = %f
\n",column_name,pQuan->dMassTol); } else if (strcmp(column_name,"assumed_charge")==0) { pQuan->iChargeState = *(int *)ptr_value; if (DEBUG) printf(" %s = %d
\n",column_name,pQuan->iChargeState); } else if (strcmp(column_name,"dat_file")==0) { iStrLength = strlen((char *)ptr_value); if (iStrLength > SIZE_FILE) iStrLength = SIZE_FILE; strncpy(szDatFile, (char *)ptr_value, iStrLength); szDatFile[iStrLength] = '\0'; if (szDatFile[0] != '/') { strcpy(tmp1,"/data3/sbeams/archive/"); strcat(tmp1,szDatFile); strcpy(szDatFile,tmp1); } if (DEBUG) printf(" %s = %s
\n",column_name,szDatFile); } } } //#### Check for unexpected status codes if (rc == TDS_FAIL) { fprintf(stderr, "tds_process_row_tokens() returned TDS_FAIL\n"); } else if (rc != TDS_NO_MORE_ROWS) { fprintf(stderr, "tds_process_row_tokens() unexpected return\n"); } } //#### Check for unexpected status codes if (rc == TDS_FAIL) { fprintf(stderr, "tds_process_result_tokens() returned TDS_FAIL\n"); } else if (rc != TDS_NO_MORE_RESULTS) { fprintf(stderr, "tds_process_result_tokens() unexpected return\n"); } //#### Logout of server if (DEBUG) printf("No more rows. Query finished.
\n"); tds_free_socket(tds); tds_free_login(login); //#### Set szInteractDir to something bogus but non-blank to simulate //#### the Interact environment if (!(strlen(szInteractDir)>0)) { strcpy(szInteractDir,"SBEAMS"); } } /*GET_PARAMETERS*/ /* * Reads .dat files and get quantitation numbers */ void GET_QUANTITATION(char *szDatFile, struct QuanStruct *pQuan) { int i, ctScan, iAnalysisFirstScan, iAnalysisLastScan, iLightStartScan, iLightEndScan, iHeavyStartScan, iHeavyEndScan, iPlotStartScan, iPlotEndScan, iPlotBuffer=25, iStart, iEnd, iWhichCharge; double dLightMass, dHeavyMass, H=1.008, *dLightMS, *dHeavyMS, *dLightFilteredMS, *dHeavyFilteredMS, *dTmpMS, dMaxLightInten, dMaxHeavyInten; char szTmpFile[SIZE_FILE]; int iSumPeaks=0; OAP_FILE *pOapFile; SPECTRUM *pSpectrum; ANALYSIS *pAnalysis; sprintf(szTmpFile, "%s.dat", szDatFile); /* * Open icis file */ if ((pOapFile = oap_open(szTmpFile, READ_FLAG)) == NULL) { printf(" Cannot open analysis - %s\n", szTmpFile); exit(EXIT_FAILURE); } /* * Get the analysis start, end scans */ if ((pAnalysis = get_header(pOapFile, 0)) != NULL) { iAnalysisFirstScan = (INT_4) pAnalysis->first_spect; iAnalysisLastScan = (INT_4) pAnalysis->last_spect; } else { printf(" Unable to read the analysis header of %s!\n", szDatFile); exit(EXIT_FAILURE); } if ( (dLightMS=(double *)malloc(sizeof(double)*(iAnalysisLastScan+5)))==NULL) { printf(" Error, cannot malloc dLightMS[%d]\n\n", iAnalysisLastScan+5); exit(EXIT_FAILURE); } if ( (dHeavyMS=(double *)malloc(sizeof(double)*(iAnalysisLastScan+5)))==NULL) { printf(" Error, cannot malloc dHeavyMS[%d]\n\n", iAnalysisLastScan+5); exit(EXIT_FAILURE); } if ( (dLightFilteredMS=malloc(sizeof(double)*(iAnalysisLastScan+5)))==NULL) { printf(" Error, cannot malloc dLightFilteredMS[%d]\n\n", iAnalysisLastScan+5); exit(EXIT_FAILURE); } if ( (dHeavyFilteredMS=malloc(sizeof(double)*(iAnalysisLastScan+5)))==NULL) { printf(" Error, cannot malloc dHeavyFilteredMS[%d]\n\n", iAnalysisLastScan+5); exit(EXIT_FAILURE); } if ( (dTmpMS=malloc(sizeof(double)*(iAnalysisLastScan+5)))==NULL) { printf(" Error, cannot malloc dTmpMS[%d]\n\n", iAnalysisLastScan+5); exit(EXIT_FAILURE); } iWhichCharge=pQuan->iChargeState; /* * Calculate the precursor mass */ if (iWhichCharge==1) { dLightMass = pQuan->dLightPeptideMass; dHeavyMass = pQuan->dHeavyPeptideMass; } else if (iWhichCharge==2) { dLightMass = (H+ pQuan->dLightPeptideMass)/2.0; dHeavyMass = (H+ pQuan->dHeavyPeptideMass)/2.0; } else if (iWhichCharge==3) { dLightMass = (H+H + pQuan->dLightPeptideMass)/3.0; dHeavyMass = (H+H + pQuan->dHeavyPeptideMass)/3.0; } else { printf(" Error, charge state = %d\n\n", iWhichCharge); exit(EXIT_FAILURE); } /* * Clear all values */ memset(dLightMS, 0, sizeof(dLightMS)); memset(dHeavyMS, 0, sizeof(dHeavyMS)); memset(dLightFilteredMS, 0, sizeof(dLightFilteredMS)); memset(dHeavyFilteredMS, 0, sizeof(dHeavyFilteredMS)); iStart = pQuan->iLightFirstScan - 100; iEnd = pQuan->iLightLastScan + 100; if (iStartiAnalysisLastScan) iEnd=iAnalysisLastScan; /* * Read all MS scan values */ for (ctScan=iStart; ctScan<=iEnd; ctScan++) { /* * Open a scan */ if ((pSpectrum=get_spectrum(pOapFile, ctScan, TRUE)) != NULL) { if ( (pSpectrum->spect_flags[0]&16) && (pSpectrum->spect_flags[5]&16) ) { DATA_PKT *pDataPt; /* * Store intensity value for each peptide/charge * mass across all MS scans in the datafile. */ while ((pDataPt=get_packet(pOapFile, 0))!=NULL) { if ( fabs(dLightMass - pDataPt->mass) <= pQuan->dMassTol) { if (iSumPeaks == 1) { dLightMS[ctScan]+=pDataPt->intensity; } else { if (pDataPt->intensity > dLightMS[ctScan]) dLightMS[ctScan]=pDataPt->intensity; } } if ( fabs(dHeavyMass - pDataPt->mass) <= pQuan->dMassTol) { if (iSumPeaks == 1) { dHeavyMS[ctScan]+=pDataPt->intensity; } else { if (pDataPt->intensity > dHeavyMS[ctScan]) dHeavyMS[ctScan]=pDataPt->intensity; } } } } } } /*for*/ /* * Starting from the start and end scans read from .out * files, need to see the real start/end scan of eluting * peptide by looking at smoothed/filtered MS profile. */ /* * Get peptide start & end scans */ iLightStartScan = pQuan->iLightFirstScan; iLightEndScan = pQuan->iLightLastScan; iHeavyStartScan = pQuan->iHeavyFirstScan; iHeavyEndScan = pQuan->iHeavyLastScan; /* * Print out data for plotting */ iPlotStartScan = iLightStartScan; iPlotEndScan = iLightEndScan; if (iHeavyStartScan < iPlotStartScan) iPlotStartScan = iHeavyStartScan; if (iHeavyEndScan > iPlotEndScan) iPlotEndScan = iHeavyEndScan; if (iPlotStartScan-iPlotBuffer < iAnalysisFirstScan) iPlotStartScan = iAnalysisFirstScan; else iPlotStartScan -= iPlotBuffer; if (iPlotEndScan+iPlotBuffer> iAnalysisLastScan-1) iPlotEndScan = iAnalysisLastScan-1; else iPlotEndScan += iPlotBuffer; dMaxLightInten=0.0; dMaxHeavyInten=0.0; for (i=iPlotStartScan; i<=iPlotEndScan; i++) { if (dLightMS[i]>dMaxLightInten) dMaxLightInten=dLightMS[i]; if (dHeavyMS[i]>dMaxHeavyInten) dMaxHeavyInten=dHeavyMS[i]; } /* * Sum up intensity values across each charge state */ for (i=iLightStartScan; i<=iLightEndScan; i++) pQuan->dLightQuanValue += dLightMS[i]; for (i=iHeavyStartScan; i<=iHeavyEndScan; i++) pQuan->dHeavyQuanValue += dHeavyMS[i]; memset(dTmpMS, 0, sizeof(dTmpMS)); FILTER_MS(dLightMS, dLightFilteredMS, dTmpMS, dMaxLightInten, iAnalysisLastScan+5, iPlotStartScan, iPlotEndScan); memset(dTmpMS, 0, sizeof(dTmpMS)); FILTER_MS(dHeavyMS, dHeavyFilteredMS, dTmpMS, dMaxHeavyInten, iAnalysisLastScan+5, iPlotStartScan, iPlotEndScan); if (dLightMS[iLightStartScan]!=0.0) iLightStartScan--; if (dLightMS[iLightEndScan]!=0.0) iLightEndScan++; if (dHeavyMS[iHeavyStartScan]!=0.0) iHeavyStartScan--; if (dHeavyMS[iHeavyEndScan]!=0.0) iHeavyEndScan++; MAKE_PLOT(iPlotStartScan, iPlotEndScan, iLightStartScan, iLightEndScan, iHeavyStartScan, iHeavyEndScan, dMaxLightInten, dMaxHeavyInten, dLightMS, dHeavyMS, dLightFilteredMS, dHeavyFilteredMS, pQuan); free(dLightMS); free(dHeavyMS); oap_close(pOapFile); } /*GET_QUANTITATION*/ void MAKE_PLOT(int iPlotStartScan, int iPlotEndScan, int iLightStartScan, int iLightEndScan, int iHeavyStartScan, int iHeavyEndScan, double dMaxLightInten, double dMaxHeavyInten, double *pdLight, double *pdHeavy, double *pdLightFiltered, double *pdHeavyFiltered, struct QuanStruct *pQuan) { int i, iImageWidth=450, iImageHeight=150, iBottomBorder=20, iTopBorder=10, iGrey, iGrey2, iWhite, iWhite2, iBlack, iBlack2, iRed, iRed2, iBlue, iBlue2; char szImageFile[SIZE_FILE], szImageFile2[SIZE_FILE], szImageDir[SIZE_FILE], szLabel[SIZE_FILE]; FILE *fp; double H=1.008; time_t tStartTime; gdImagePtr gdImageLight, gdImageHeavy; /* * first color allocated defines background color */ gdImageLight = gdImageCreate(iImageWidth, iImageHeight); iWhite = gdImageColorAllocate(gdImageLight, 248, 255, 255), iGrey = gdImageColorAllocate(gdImageLight, 150, 150, 150), iBlack = gdImageColorAllocate(gdImageLight, 0, 0, 0), iRed = gdImageColorAllocate(gdImageLight, 255, 0, 0), iBlue = gdImageColorAllocate(gdImageLight, 0, 0, 255), gdImageHeavy = gdImageCreate(iImageWidth, iImageHeight); iWhite2 = gdImageColorAllocate(gdImageHeavy, 255, 248, 255), iGrey2 = gdImageColorAllocate(gdImageHeavy, 150, 150, 150), iBlack2 = gdImageColorAllocate(gdImageHeavy, 0, 0, 0), iRed2 = gdImageColorAllocate(gdImageHeavy, 255, 0, 0), iBlue2 = gdImageColorAllocate(gdImageHeavy, 0, 0, 255), sprintf(szLabel, "Light %0.3lf %+d", (pQuan->dLightPeptideMass + H*(pQuan->iChargeState -1)) /(pQuan->iChargeState), pQuan->iChargeState); gdImageString(gdImageLight, gdFontSmall, 3, 3, szLabel, iBlue); sprintf(szLabel, "AREA:%0.2E", pQuan->dLightQuanValue); gdImageString(gdImageLight, gdFontSmall, 3, 15, szLabel, iBlue); sprintf(szLabel, "%0.2E", dMaxLightInten); gdImageString(gdImageLight, gdFontSmall, iImageWidth-50, 3, szLabel, iBlue); sprintf(szLabel, "Heavy %0.3lf %+d", (pQuan->dHeavyPeptideMass + H*(pQuan->iChargeState -1)) /(pQuan->iChargeState), pQuan->iChargeState); gdImageString(gdImageHeavy, gdFontSmall, 3, 3, szLabel, iBlue2); sprintf(szLabel,"AREA:%0.2E", pQuan->dHeavyQuanValue); gdImageString(gdImageHeavy, gdFontSmall, 3, 15, szLabel, iBlue2); sprintf(szLabel,"%0.2E", dMaxHeavyInten); gdImageString(gdImageHeavy, gdFontSmall, iImageWidth-50, 3, szLabel, iBlue2); /* * Plot out spectra */ for (i=iPlotStartScan; i<=iPlotEndScan; i++) { int iX1Pos, iX2Pos, iY1PosLight, iY2PosLight, iY1PosHeavy, iY2PosHeavy; gdPoint gPoints[4]; iX1Pos= (int)( (i-iPlotStartScan)*iImageWidth/(iPlotEndScan-iPlotStartScan)); iX2Pos= (int)( (i+1-iPlotStartScan)*iImageWidth/(iPlotEndScan-iPlotStartScan)); if (dMaxLightInten>0.0) { iY1PosLight = iImageHeight - iBottomBorder - (int)((pdLight[i]/dMaxLightInten)*(iImageHeight-iBottomBorder-iTopBorder)); iY2PosLight = iImageHeight - iBottomBorder - (int)((pdLight[i+1]/dMaxLightInten)*(iImageHeight-iBottomBorder-iTopBorder)); } else { iY1PosLight = iImageHeight - iBottomBorder; iY2PosLight = iImageHeight - iBottomBorder; } if (dMaxHeavyInten>0.0) { iY1PosHeavy = iImageHeight - iBottomBorder - (int)((pdHeavy[i]/dMaxHeavyInten)*(iImageHeight-iBottomBorder-iTopBorder)); iY2PosHeavy = iImageHeight - iBottomBorder - (int)((pdHeavy[i+1]/dMaxHeavyInten)*(iImageHeight-iBottomBorder-iTopBorder)); } else { iY1PosHeavy = iImageHeight - iBottomBorder; iY2PosHeavy = iImageHeight - iBottomBorder; } /* * define triangle for filled polygon ... one of many ways to display trace */ gPoints[0].x = iX1Pos; gPoints[0].y = iImageHeight-iBottomBorder; gPoints[1].x = iX1Pos; gPoints[1].y = iY1PosLight; gPoints[2].x = iX2Pos; gPoints[2].y = iY2PosLight; gPoints[3].x = iX2Pos; gPoints[3].y = iImageHeight-iBottomBorder; if (i>=iLightStartScan && i=iHeavyStartScan && i0.0) { iY1PosLight = iImageHeight - iBottomBorder - (int)((pdLightFiltered[i]/dMaxLightInten)*(iImageHeight-iBottomBorder-iTopBorder)); } else { iY1PosLight= iImageHeight - iBottomBorder; } if (dMaxHeavyInten>0.0) { iY1PosHeavy = iImageHeight - iBottomBorder - (int)((pdHeavyFiltered[i]/dMaxHeavyInten)*(iImageHeight-iBottomBorder-iTopBorder)); } else { iY1PosHeavy = iImageHeight - iBottomBorder; } if (i>=iLightStartScan && i=iHeavyStartScan && iiLightFirstScan+pQuan->iHeavyFirstScan+ (int)(pQuan->dLightPeptideMass*5.0)); tStartTime=time((time_t *)NULL); strcpy(szImageFile, szImageDir); strcpy(szImageFile2, szImageDir); sprintf(szImageFile+strlen(szImageFile), "x%d-%d.gif", tStartTime, random()); sprintf(szImageFile2+strlen(szImageFile2), "x%d-%db.gif", tStartTime, random()); gdImageInterlace(gdImageLight, 1); if ( (fp=fopen(szImageFile, "wb"))!=NULL) { gdImageGif(gdImageLight, fp); fclose(fp); gdImageDestroy(gdImageLight); } else printf(" Error - cannot create file %s
\n", szImageFile); gdImageInterlace(gdImageHeavy, 1); if ( (fp=fopen(szImageFile2, "wb"))!=NULL) { gdImageGif(gdImageHeavy, fp); fclose(fp); gdImageDestroy(gdImageHeavy); } else printf(" Error - cannot create file %s
\n", szImageFile2); printf("

", szImageFile, szImageFile2); } /*MAKE_PLOT*/ #define FILTER_SIZE 6 /* * Use my standard filtering routine */ void FILTER_MS(double *dOrigMS, double *dFilteredMS, double *dTmpFilter, double dMaxInten, int iNumMSScans, int iPlotStartScan, int iPlotEndScan) { int i, iArraySize=iNumMSScans*sizeof(double); double dTmpMax; /* * Defines 5th order butterworth filter w/ cut-off frequency * of 0.25 where 1.0 corresponse to half the sample rate. */ /* 5th order, 0.10 double a[FILTER_SIZE]={1.0000, -3.9845, 6.4349, -5.2536, 2.1651, -0.3599}, b[FILTER_SIZE]={0.0000598, 0.0002990, 0.0005980, 0.0005980, 0.0002990, 0.0000598}; 5th order, 0.15 */ double a[FILTER_SIZE]={1.0000, -3.4789, 5.0098, -3.6995, 1.3942, -0.2138}, b[FILTER_SIZE]={0.0004, 0.0018, 0.0037, 0.0037, 0.0018, 0.0004}; /* 5th order, 0.20 double a[FILTER_SIZE]={1.0000, -2.9754, 3.8060, -2.5453, 0.8811, -0.1254}, b[FILTER_SIZE]={0.0013, 0.0064, 0.0128, 0.0128, 0.0064, 0.0013}; 5th order, 0.25 double a[FILTER_SIZE]={1.0, -2.4744, 2.8110, -1.7038, 0.5444, -0.0723}, b[FILTER_SIZE]={0.0033, 0.0164, 0.0328, 0.0328, 0.0164, 0.0033}; */ memset(dFilteredMS, 0, iArraySize); memcpy(dTmpFilter, dOrigMS, iNumMSScans*sizeof(double)); /* * Pass MS profile through IIR low pass filter: * y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) * - a(2)*y(n-1) - ... - a(na+1)*y(n-na) */ for (i=0; i=0) { dFilteredMS[i] += b[ii]*dTmpFilter[i-ii]; dFilteredMS[i] -= a[ii]*dFilteredMS[i-ii]; } } } /* * Filtered sequence is reversed and re-filtered resulting * in zero-phase distortion and double the filter order. */ for (i=0; i=0) { dFilteredMS[i] += b[ii]*dTmpFilter[i-ii]; dFilteredMS[i] -= a[ii]*dFilteredMS[i-ii]; } } } /* * Filtered sequence is reversed again */ dTmpMax=0.001; for (i=0; i=iPlotStartScan && i<=iPlotEndScan) if (dTmpFilter[i]>dTmpMax) dTmpMax=dTmpFilter[i]; } if (dMaxInten>0.0) { for (i=iPlotStartScan; i<=iPlotEndScan; i++) { dTmpFilter[i] = dTmpFilter[i] * dMaxInten / dTmpMax; } } memcpy(dFilteredMS, dTmpFilter, iArraySize); } /*FILTER_MS*/ void UPDATE_QUAN() { char szNewLink[4096]; /* * replace text starting with first ? in the cgixpress tag with szNewLink */ sprintf(szNewLink , "LightFirstScan=%d&", pQuan.iLightFirstScan); sprintf(szNewLink+strlen(szNewLink), "LightLastScan=%d&", pQuan.iLightLastScan); sprintf(szNewLink+strlen(szNewLink), "LightMass=%0.6lf&", pQuan.dLightPeptideMass); sprintf(szNewLink+strlen(szNewLink), "HeavyFirstScan=%d&", pQuan.iHeavyFirstScan); sprintf(szNewLink+strlen(szNewLink), "HeavyLastScan=%d&", pQuan.iHeavyLastScan); sprintf(szNewLink+strlen(szNewLink), "HeavyMass=%0.6f&", pQuan.dHeavyPeptideMass); sprintf(szNewLink+strlen(szNewLink), "DatFile=%s&", szDatFile); sprintf(szNewLink+strlen(szNewLink), "ChargeState=%d&", pQuan.iChargeState); sprintf(szNewLink+strlen(szNewLink), "OutFile=%s&", szOutputFile); sprintf(szNewLink+strlen(szNewLink), "MassTol=%0.6lf&", pQuan.dMassTol); sprintf(szNewLink+strlen(szNewLink), "bXpressLight1=%d&", bXpressLight1); sprintf(szNewLink+strlen(szNewLink), "InteractDir=%s&", szInteractDir); sprintf(szNewLink+strlen(szNewLink), "InteractBaseName=%s", szInteractBaseName); printf("
"); printf("\n", pQuan.iLightFirstScan); printf("\n", pQuan.iLightLastScan); printf("\n",pQuan.dLightPeptideMass ); printf("\n",pQuan.iHeavyFirstScan ); printf("\n", pQuan.iHeavyLastScan); printf("\n", pQuan.dHeavyPeptideMass); printf("\n", szDatFile); printf("\n", pQuan.iChargeState); printf("\n", szOutputFile); printf("\n", pQuan.dMassTol); printf("\n", bXpressLight1); printf("\n", pQuan.iquantitation_id); printf("\n", pQuan.dLightQuanValue); printf("\n", pQuan.dHeavyQuanValue); printf("\n", szNewLink); printf("\n", pQuan.szNewQuan); printf("\n", szInteractDir); printf("\n", szInteractBaseName); printf("\n", szOutputFile); printf("

"); } /*UPDATE_QUAN*/ void BAD_QUAN() { char szBadQuan[4096]; /* Link to bad quantitation */ printf("
"); /* * first quick button for bad quantitation */ sprintf(szBadQuan , "LightFirstScan=%d&", pQuan.iLightFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "LightLastScan=%d&", pQuan.iLightFirstScan-1); sprintf(szBadQuan+strlen(szBadQuan), "LightMass=%0.6lf&", pQuan.dLightPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "HeavyFirstScan=%d&", pQuan.iHeavyFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "HeavyLastScan=%d&", pQuan.iHeavyFirstScan-1); sprintf(szBadQuan+strlen(szBadQuan), "HeavyMass=%0.6lf&", pQuan.dHeavyPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "DatFile=%s&", szDatFile); sprintf(szBadQuan+strlen(szBadQuan), "ChargeState=%d&", pQuan.iChargeState); sprintf(szBadQuan+strlen(szBadQuan), "OutFile=%s&", szOutputFile); sprintf(szBadQuan+strlen(szBadQuan), "MassTol=%0.6lf&", pQuan.dMassTol); sprintf(szBadQuan+strlen(szBadQuan), "bXpressLight1=%d&", bXpressLight1); sprintf(szBadQuan+strlen(szBadQuan), "InteractDir=%s&", szInteractDir); sprintf(szBadQuan+strlen(szBadQuan), "InteractBaseName=%s", szInteractBaseName); printf("
"); printf("\n", pQuan.iLightFirstScan); printf("\n", pQuan.iLightLastScan); printf("\n",pQuan.dLightPeptideMass ); printf("\n",pQuan.iHeavyFirstScan ); printf("\n", pQuan.iHeavyLastScan); printf("\n", pQuan.dHeavyPeptideMass); printf("\n", szDatFile); printf("\n", pQuan.iChargeState); printf("\n", szOutputFile); printf("\n", pQuan.dMassTol); printf("\n", bXpressLight1); printf("\n", pQuan.iquantitation_id); printf("\n", 0.0); printf("\n", 0.0); printf("\n", szBadQuan); printf("\n", "?"); printf("\n", szInteractDir); printf("\n", szInteractBaseName); printf("\n", szOutputFile); printf("

"); printf("
"); /* * second quick button */ sprintf(szBadQuan , "LightFirstScan=%d&", pQuan.iLightFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "LightLastScan=%d&", pQuan.iLightLastScan); sprintf(szBadQuan+strlen(szBadQuan), "LightMass=%0.6lf&", pQuan.dLightPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "HeavyFirstScan=%d&", pQuan.iHeavyFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "HeavyLastScan=%d&", 0); sprintf(szBadQuan+strlen(szBadQuan), "HeavyMass=%0.6lf&", pQuan.dHeavyPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "DatFile=%s&", szDatFile); sprintf(szBadQuan+strlen(szBadQuan), "ChargeState=%d&", pQuan.iChargeState); sprintf(szBadQuan+strlen(szBadQuan), "OutFile=%s&", szOutputFile); sprintf(szBadQuan+strlen(szBadQuan), "MassTol=%0.6lf&", pQuan.dMassTol); sprintf(szBadQuan+strlen(szBadQuan), "bXpressLight1=%d&", bXpressLight1); sprintf(szBadQuan+strlen(szBadQuan), "InteractDir=%s&", szInteractDir); sprintf(szBadQuan+strlen(szBadQuan), "InteractBaseName=%s", szInteractBaseName); printf("
"); printf("\n", pQuan.iLightFirstScan); printf("\n", pQuan.iLightLastScan); printf("\n",pQuan.dLightPeptideMass ); printf("\n",pQuan.iHeavyFirstScan ); printf("\n", pQuan.iHeavyLastScan); printf("\n", pQuan.dHeavyPeptideMass); printf("\n", szDatFile); printf("\n", pQuan.iChargeState); printf("\n", szOutputFile); printf("\n", pQuan.dMassTol); printf("\n", bXpressLight1); printf("\n", pQuan.iquantitation_id); printf("\n", pQuan.dLightQuanValue); printf("\n", 0.0); printf("\n", szBadQuan); printf("\n", "1:0.00"); printf("\n", szInteractDir); printf("\n", szInteractBaseName); printf("\n", szOutputFile); printf("

"); printf("
"); /* * third quick button */ sprintf(szBadQuan , "LightFirstScan=%d&", pQuan.iLightFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "LightLastScan=%d&", 0); sprintf(szBadQuan+strlen(szBadQuan), "LightMass=%0.6lf&", pQuan.dLightPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "HeavyFirstScan=%d&", pQuan.iHeavyFirstScan); sprintf(szBadQuan+strlen(szBadQuan), "HeavyLastScan=%d&", pQuan.iHeavyLastScan); sprintf(szBadQuan+strlen(szBadQuan), "HeavyMass=%0.6lf&", pQuan.dHeavyPeptideMass); sprintf(szBadQuan+strlen(szBadQuan), "DatFile=%s&", szDatFile); sprintf(szBadQuan+strlen(szBadQuan), "ChargeState=%d&", pQuan.iChargeState); sprintf(szBadQuan+strlen(szBadQuan), "OutFile=%s&", szOutputFile); sprintf(szBadQuan+strlen(szBadQuan), "MassTol=%0.6lf&", pQuan.dMassTol); sprintf(szBadQuan+strlen(szBadQuan), "bXpressLight1=%d&", bXpressLight1); sprintf(szBadQuan+strlen(szBadQuan), "InteractDir=%s&", szInteractDir); sprintf(szBadQuan+strlen(szBadQuan), "InteractBaseName=%s", szInteractBaseName); printf("
"); printf("\n", pQuan.iLightFirstScan); printf("\n", pQuan.iLightLastScan); printf("\n",pQuan.dLightPeptideMass ); printf("\n",pQuan.iHeavyFirstScan ); printf("\n", pQuan.iHeavyLastScan); printf("\n", pQuan.dHeavyPeptideMass); printf("\n", szDatFile); printf("\n", pQuan.iChargeState); printf("\n", szOutputFile); printf("\n", pQuan.dMassTol); printf("\n", bXpressLight1); printf("\n", pQuan.iquantitation_id); printf("\n", 0.0); printf("\n", pQuan.dHeavyQuanValue); printf("\n", szBadQuan); printf("\n", "0.00:1"); printf("\n", szInteractDir); printf("\n", szInteractBaseName); printf("\n", szOutputFile); printf("

"); printf("
\n"); } /*BAD_QUAN*/