// vera_samDlg.cpp : implementation file // #include "stdafx.h" #include "vera_sam.h" #include "vera_samDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif UINT WorkerThread(LPVOID pParam); ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVera_samDlg dialog CVera_samDlg::CVera_samDlg(CWnd* pParent /*=NULL*/) : CDialog(CVera_samDlg::IDD, pParent) { //{{AFX_DATA_INIT(CVera_samDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CVera_samDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CVera_samDlg) DDX_Control(pDX, IDC_PROGRESS1, m_progressbar); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CVera_samDlg, CDialog) //{{AFX_MSG_MAP(CVera_samDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDEXECUTE, OnExecute) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2) ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3) ON_BN_CLICKED(IDC_BUTTON6, OnButton6) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_ENDPROG, OnEndprog) ON_BN_CLICKED(IDC_CHECK2, OnCheck2) ON_BN_CLICKED(IDC_CHECK1, OnCheck1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVera_samDlg message handlers BOOL CVera_samDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_progressbar.SetRange32(0,250); m_progressbar.SetStep(1); m_progressbar.SetPos(0); m_EndProg = false; CheckDlgButton(IDC_CHECK2,true); CheckDlgButton(IDC_CHECK1,true); return TRUE; // return TRUE unless you set the focus to a control } void CVera_samDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CVera_samDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CVera_samDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CVera_samDlg::OnButton1() { CFileDialog findfile(true, NULL, NULL, OFN_FILEMUSTEXIST, NULL, NULL); findfile.DoModal(); CString mergefilename = findfile.GetPathName();//get path of input file CString fileextname = findfile.GetFileExt(); int stringlen = mergefilename.GetLength(); int extlen = fileextname.GetLength();//get length of string and copy it, minus the .txt UpdateEDITONE(mergefilename);//Update IDC_EDIT1..do before cutting off extension if(extlen == 0) mergefilename = mergefilename.Left(stringlen-extlen);//+1 to get rid of the "." else mergefilename = mergefilename.Left(stringlen-(extlen+1));//+1 to get rid of the "." UpdateEDITTWO(mergefilename);//Update IDC_EDIT2 UpdateEDITTHREE(mergefilename);//Update IDC_EDIT3 VERA_input = mergefilename; } void CVera_samDlg::OnButton2() { CString tempname; GetDlgItemText(IDC_EDIT2, tempname); CFileDialog savefile(false, NULL, tempname, OFN_HIDEREADONLY, NULL, NULL); savefile.DoModal(); CString modfilename = savefile.GetPathName(); if (modfilename != _T("")){ CString fileextname = savefile.GetFileExt(); int stringlen = modfilename.GetLength(); int extlen = fileextname.GetLength(); if (extlen == 0) modfilename = modfilename.Left(stringlen-extlen); else modfilename = modfilename.Left(stringlen-(extlen+1)); UpdateEDITTWO(modfilename); } } void CVera_samDlg::OnButton3() { CString tempname; GetDlgItemText(IDC_EDIT3, tempname); CFileDialog savefile(false, NULL, tempname, OFN_HIDEREADONLY, NULL, NULL); savefile.DoModal(); CString sigfilename = savefile.GetPathName(); CString fileextname = savefile.GetFileExt(); if (sigfilename != _T("")){ int stringlen = sigfilename.GetLength(); int extlen = fileextname.GetLength(); if (extlen == 0) sigfilename = sigfilename.Left(stringlen-extlen); else sigfilename = sigfilename.Left(stringlen-(extlen+1)); UpdateEDITTHREE(sigfilename); } } void CVera_samDlg::OnButton4() { // Try ShellExecute() LPCTSTR url = "http://www.systemsbiology.org/VERAandSAM"; HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL,SW_SHOWNORMAL ); } void CVera_samDlg::OnButton5() //Options button { Options_dlg options; options.DoModal(); return; } void CVera_samDlg::OnButton6() { CAboutDlg about; about.DoModal(); return; } void CVera_samDlg::OnCancel() { CDialog::OnCancel(); return; } void CVera_samDlg::OnEndprog() { UpdateUI("Terminating Program..."); m_EndProg = true; return; } void CVera_samDlg::UpdateUI() { CString InputFileString, VERAFileString,SAMFileString; GetDlgItemText(IDC_EDIT1, InputFileString); //File Information GetDlgItemText(IDC_EDIT2, VERAFileString); GetDlgItemText(IDC_EDIT3, SAMFileString); GetDlgItem(IDEXECUTE)->EnableWindow(InputFileString != _T("") && VERAFileString != _T("") && SAMFileString != _T("")); return; } void CVera_samDlg::UpdateUI(CString newitem) { newitem = "Status:\r\n"+newitem; LPCTSTR item = newitem; SetDlgItemText(IDC_EDIT4, item); return; } void CVera_samDlg::UpdateSummary(CString temp) { CString current; GetDlgItemText(IDC_SUMMARY, current); if (current != _T("")){ current = current + temp; SetDlgItemText(IDC_SUMMARY, current); } else{ SetDlgItemText(IDC_SUMMARY, temp); } return; } void CVera_samDlg::UpdateEDITONE(CString base) { SetDlgItemText(IDC_EDIT1, base); UpdateUI(); return; } void CVera_samDlg::UpdateEDITTWO(CString base) { if (base != _T("")){ base += ".mod"; CString input_name; GetDlgItemText(IDC_EDIT1, input_name); if (input_name == base) base+="file2"; } SetDlgItemText(IDC_EDIT2, base); UpdateUI(); return; } void CVera_samDlg::UpdateEDITTHREE(CString base) { if (base != _T("")){ base += ".sig"; CString input_name, mod_name; GetDlgItemText(IDC_EDIT1, input_name); GetDlgItemText(IDC_EDIT1, mod_name); if (input_name == base || mod_name == base) base+="file2"; } SetDlgItemText(IDC_EDIT3, base); UpdateUI(); return; } void CVera_samDlg::OnChangeEdit2() { UpdateUI(); CString temp; GetDlgItemText(IDC_EDIT2, temp); return; } void CVera_samDlg::OnChangeEdit3() { UpdateUI(); CString temp; GetDlgItemText(IDC_EDIT3, temp); return; } void CVera_samDlg::OnCheck2() { if (RunSAM == 1) RunSAM = false; else RunSAM = true; if(RunSAM == false){ GetDlgItem(IDC_BUTTON3)->ShowWindow(false); GetDlgItem(IDC_STATIC_STEP3A)->ShowWindow(false); GetDlgItem(IDC_STATIC_STEP3B)->ShowWindow(false); GetDlgItem(IDC_STATIC_STEP3C)->ShowWindow(false); GetDlgItem(IDC_EDIT3)->ShowWindow(false); } else{ GetDlgItem(IDC_BUTTON3)->ShowWindow(true); GetDlgItem(IDC_STATIC_STEP3A)->ShowWindow(true); GetDlgItem(IDC_STATIC_STEP3B)->ShowWindow(true); GetDlgItem(IDC_STATIC_STEP3C)->ShowWindow(true); GetDlgItem(IDC_EDIT3)->ShowWindow(true); } } void CVera_samDlg::OnCheck1() { if (RunVERA == 1) RunVERA = false; else RunVERA = true; } void CVera_samDlg::reset_variables() { m_EndProg = false; m_progressbar.SetPos(0); } void CVera_samDlg::OnExecute() { reset_variables(); CWinThread* pWThread = AfxBeginThread(WorkerThread, this); return; } UINT WorkerThread(LPVOID pParam) { CVera_samDlg* pDlg = (CVera_samDlg*)pParam; CString InputFileString, VERAFileString,SAMFileString; pDlg->GetDlgItemText(IDC_EDIT1, InputFileString); //File Information pDlg->GetDlgItemText(IDC_EDIT2, VERAFileString); pDlg->GetDlgItemText(IDC_EDIT3, SAMFileString); LPCTSTR InputFile = InputFileString; //File Names as char* LPCTSTR VERAFile = VERAFileString; LPCTSTR SAMFile = SAMFileString; LPCTSTR ALT_SAMFile = ALT_SAM_INPUT; //Disable all buttons & lock in text fields pDlg->GetDlgItem(IDC_CHECK1)->EnableWindow(false); //"Run VERA" checkbox pDlg->GetDlgItem(IDC_CHECK2)->EnableWindow(false); //"Run SAM" checkbox pDlg->GetDlgItem(IDEXECUTE)->EnableWindow(false); //execute button pDlg->GetDlgItem(IDC_BUTTON5)->EnableWindow(false); //options button pDlg->GetDlgItem(IDCANCEL)->EnableWindow(false); //exit button pDlg->GetDlgItem(IDC_ENDPROG)->EnableWindow(true); //abort button pDlg->GetDlgItem(IDC_BUTTON1)->EnableWindow(false); //find initial file button pDlg->GetDlgItem(IDC_BUTTON2)->EnableWindow(false); //vera file button pDlg->GetDlgItem(IDC_BUTTON3)->EnableWindow(false); //sam file button pDlg->GetDlgItem(IDC_BUTTON6)->EnableWindow(false); //"About" button pDlg->GetDlgItem(IDC_ENDPROG)->ShowWindow(SW_SHOW); pDlg->GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE); if (RunVERA) pDlg->VERA(InputFile, VERAFile, evolution, start_mod,disp_iter, stop_crit); if (RunSAM && !alt_sam) pDlg->SAM (InputFile, VERAFile, SAMFile, s_disp_iter); if (RunSAM && alt_sam) pDlg->SAM (ALT_SAMFile, VERAFile, SAMFile, s_disp_iter); //Re-enable all buttons and unlock text fields pDlg->GetDlgItem(IDC_CHECK1)->EnableWindow(true); //"Run VERA" checkbox pDlg->GetDlgItem(IDC_CHECK2)->EnableWindow(true); //"Run SAM" checkbox pDlg->GetDlgItem(IDEXECUTE)->EnableWindow(true); //execute button pDlg->GetDlgItem(IDC_BUTTON5)->EnableWindow(true); //options button pDlg->GetDlgItem(IDCANCEL)->EnableWindow(true); //exit button pDlg->GetDlgItem(IDC_ENDPROG)->EnableWindow(false); //abort button pDlg->GetDlgItem(IDC_BUTTON1)->EnableWindow(true); //find initial file button pDlg->GetDlgItem(IDC_BUTTON2)->EnableWindow(true); //vera file button pDlg->GetDlgItem(IDC_BUTTON3)->EnableWindow(true); //sam file button pDlg->GetDlgItem(IDC_BUTTON6)->EnableWindow(true); //"About" button pDlg->GetDlgItem(IDC_ENDPROG)->ShowWindow(SW_HIDE); pDlg->GetDlgItem(IDCANCEL)->ShowWindow(SW_SHOW); pDlg->m_progressbar.SetPos(0); pDlg->SetDlgItemText(IDC_EDIT4, "Execution Complete."); return 0; } /********************************************************************************************/ /** **/ /** VERA.c - Optimize least squares fit to paramaters of an error model **/ /** distribution from two-channel expression data **/ /** **/ /** Error model **/ /** X = mu_x epsilon_x + delta_x **/ /** Y = mu_y epsilon_y + delta_y **/ /** Bivariate normal distribution parameters **/ /** beta[1] = sigma_epsilon_x **/ /** beta[2] = sigma_epsilon_y **/ /** beta[3] = rho_epsilon (correlation) **/ /** beta[4] = sigma_delta_x **/ /** beta[5] = sigma_delta_y **/ /** beta[6] = rho_delta (correlatio n) **/ /** **/ /** Reference: **/ /** T. E. Ideker, V. Thorsson, A. F. Siegel, and L. E. Hood **/ /** Testing for Differentially-expressed Genes by **/ /** Maximum Likelihood Analysis of Microarray Data **/ /** Journal of Computational Biology, 2001, Vol. 7, No. 6, pp.805-817 **/ /** Implementation: Vesteinn Thorsson thorsson@systemsbiology.org **/ /** Version: February, 2001 **/ /********************************************************************************************/ #define NRANSI #include #define FTOL_HIGH 1.e-6 /* high fractional functional tolerance change for frprmn */ #define FTOL_LOW 1.e-10 /* low fractional functional tolerance change for frprmn */ #define LINMIN_TOL_HIGH 1.e-6 /* high tolerance for line minimization */ #define LINMIN_TOL_LOW 1.e-10 /* low tolerance for line minimization */ #define MAX_MASTER 250 /* maximum number of master loop iterations */ #define MIN_MASTER 5 /* minimum number of master loop iterations */ #define MAX_QUICK 10 /* number of high tolerance subloop iterations */ double EPS_BETA=0.0005; /* stop criterion: abs(beta_increment) < EPS_BETA */ void CVera_samDlg::VERA ( const char *file, const char *mod, bool evolution, bool start_mod, bool disp_iter, bool stop_crit){ CString temp, temp2; UpdateUI("Beginning VERA...\r\n"); int i, j, k, l, iter, internal_index; double fret; double *p, *del, *p_old, abs_dev, Z_old, Z_diff; LPCTSTR pass_in_model = temp_in_model;//temp_in_model from globals const char *in_model = pass_in_model; const char *in_data = file; const char *out_model = mod; FILE *fp_in_data, *fp_in_model, *fp_out_model, *fp_evolution, *fp_debug; char evolution_file_name[100] ; char debug_file_name[100]; double *mu_vec, *grad_mu; double mu_x, mu_y; double FTOL; if (stop_crit){ EPS_BETA = new_eps_beta; } /* output version number and compilation parameters */ //printf("VERA version: %s\n", __DATE__); #ifdef USERHOD UpdateUI("rho_delta may be non-zero, "); #else UpdateUI("rho_delta forced to zero, "); #endif #ifdef MUNONNEG UpdateUI("non-negative mus only.\n "); #else UpdateUI("mus may be negative.\n "); #endif /* initialize command line variables */ //verbose = false; //start_mod = false; //in_model = NULL; start_time(); /* start timer */ /* parse command line for (i=1; i (sigma,rho)) */ if ( p[1] < 0 ){ p[1] = -p[1]; p[3] = -p[3]; } if ( p[2] < 0 ){ p[2] = -p[2]; p[3] = -p[3]; } #ifdef USERHOD if ( p[4] < 0 ){ p[4] = -p[4]; p[6] = -p[6]; } if ( p[5] < 0 ){ p[5] = -p[5]; p[6] = -p[6]; } #endif /* summarize result of beta optimization */ if ( disp_iter == true ){ fprintf(fp_debug,"Beta after master loop iteration %d", k); for (j=1 ;j<=NDIM ; j++){ fprintf(fp_debug," %6.4f ", p[j]); } } if ( evolution == true ){ /* print results of master loop iteration in parameter evolution file */ fprintf ( fp_evolution, "%4d ", k+1); for ( j=1 ; j<= NDIM; j++ ){ fprintf ( fp_evolution," %9.4f ", p[j]); fflush( fp_evolution ); } } /* master loop if maximum absolute increment is below threshold */ abs_dev = 0.; for ( j=1 ; j<=NDIM ; j++ ){ if ( fabs(p[j]-p_old[j]) > abs_dev ) abs_dev = fabs(p[j]-p_old[j]); } Z_diff = fabs(Z(p)-Z_old); if ( Z_diff > abs_dev ) abs_dev = Z_diff ; if ( abs_dev < EPS_BETA && k > MIN_MASTER ) break; } /* close master loop */ /* shift intensities by mus for this evaluation below */ for( i=0 ; iShowWindow(true); return; } /********************************************************************************************/ /** **/ /** SAM.c - Given parameters of covariant error model, find **/ /** significantly differentially expressed genes in two-channel expression data set **/ /** **/ /** evaluates lambda = **/ /** -2*Log( (max unconstrained likelihood)/(max constrained likelihood) ) **/ /** constrained: mu=mu_x=mu_y unconstrained mu_x != mu_y **/ /** **/ /** Reference: **/ /** T. E. Ideker, V. Thorsson, A. F. Siegel, and L. E. Hood **/ /** Testing for Differentially-expressed Genes by **/ /** Maximum Likelihood Analysis of Microarray Data **/ /** Journal of Computational Biology, 2001, Vol. 7, No. 6, pps. 805-817 **/ /** Implementation: Vesteinn Thorsson thorsson@systemsbiology.org **/ /** Version: February, 2001 **/ /********************************************************************************************/ #define NRANSI #define FTOL_HIGH 1.e-8 /* high fractional functional tolerance change for frprmn */ #define FTOL_LOW 1.e-10 /* low fractional functional tolerance change for frprmn */ #define LINMIN_TOL_HIGH 1.e-9 /* high tolerance for line minimization */ #define LINMIN_TOL_LOW 1.e-10 /* low tolerance for line minimization */ void CVera_samDlg::SAM (const char *infile, const char *modfile, const char *outfile,bool s_disp_iter){ if(m_EndProg == true) return; CString temp; int i, j, k, iter, num_sig=0; double result, fret; double *p, *del; FILE *fpin, *fpmod, *fpout, *fp_debug; double *mu_vec, *grad_mu; double mu_x, mu_y; double frac_change_1, frac_change_2 ; double ax, bx, xx, fa, fx, fb, xmin, xmin2; double numerator, denominator, llr, *loglr, numerator2; double mu_x_from_avg, mu_y_from_avg, mu_x_from_cns, mu_y_from_cns; double denominator_from_avg, denominator_from_cns; char debug_file_name[100]; /* output version number and compilation parameters */ // printf("SAM version: %s\n", __DATE__); #ifdef USERHOD UpdateUI("rho_delta may be non-zero, "); #else UpdateUI("rho_delta forced to zero, "); #endif #ifdef MUNONNEG UpdateUI("non-negative mus only.\n "); #else UpdateUI("mus may be negative.\n "); #endif /* initialize command line variables */ //verbose = false; //disp_iter = false; /* start_time(); start timer */ /* parse command line, check to see if verbose and/or display iterations flag is on */ /* for (i=1; i 200. ) llr = 0. ; /* single instance observed of astronomical lambda, for now set to 0*/ loglr[i] = llr; /* if ( llr > 3.84145882 ) num_sig++; */ } UpdateUI("updating files..."); write_llr( fpin, fpout, loglr); close_files2: fclose(fpmod); if(s_disp_iter == true) fclose(fp_debug); free(loglr); return; } void CVera_samDlg::die(CString reason) { m_EndProg = true; UpdateSummary(reason); return; } /* generic error handling function */ //DEL void CVera_samDlg::die (int error_code) { //DEL CString temp; //DEL //mj char usage_bmo[600], usage_sig[600]; //DEL //mj char usage_sig2[300]; /* core dump may result if these are too large */ //DEL //DEL /* sprintf(usage_bmo, "%s%s%s%s%s", //DEL "Usage: VERA \n", //DEL "Options: -init Use an input model to initiate optimization\n", //DEL " -crit Optimization ceases when all changes are less than (Default=0.0005)\n", //DEL " -evol Output file showing model approach to optimum\n", //DEL " -iter Display iterations (Use for debugging only)\n" ); //DEL //DEL sprintf(usage_sig, "%s%s", //DEL "Usage: SAM \n", //DEL " -iter Display iterations (Use for debugging only)\n"); //DEL //DEL sprintf(usage_sig2, "%s%s", //DEL "Usage: SAM2 \n", //DEL " -iter Display iterations (Use for debugging only)\n"); */ //DEL //DEL switch (error_code) { //DEL //DEL case 0: //DEL UpdateUI("Memory allocation failure."); //DEL break; //DEL case 1: //DEL UpdateUI("Command line error"); //DEL //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_bmo); //DEL break; //DEL case 2: //DEL UpdateUI("Cannot read input file."); //DEL //fprintf(stderr, "\nCannot read input file.\n"); //DEL break; //DEL case 3: //DEL UpdateUI("Number out of range"); //DEL //fprintf(stderr, "\nNumber out of range.\n"); //DEL break; //DEL case 5: //DEL UpdateUI("Command line error"); //DEL //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_sig); //DEL break; //DEL case 6: //DEL UpdateUI("Command Line error"); //DEL //fprintf(stderr, "\nCommand line error.\n\n%s\n\n", usage_sig2); //DEL break; //DEL case 7: //DEL UpdateSummary("Unable to Open Input File.\r\n"); //DEL break; //DEL case 8: //DEL UpdateSummary("Unable to Open Model File."); //DEL break; //DEL case 9: //DEL UpdateSummary("Unable to Open Evolution File."); //DEL break; //DEL default: //DEL UpdateUI("Unknown error."); //DEL //fprintf(stderr, "\nUnknown error.\n"); //DEL break; //DEL } //DEL UpdateUI("Aborting pogram execution."); //DEL //fprintf(stderr, "Aborting program execution.\n"); //DEL //DEL m_EndProg = true; //DEL } void CVera_samDlg::read_data(FILE *fpin){ #define MAXGENES 50000 /* maximum no. genes for temporary storage */ #define MAXREPS 100 /* maxiumum no. replicates for temporary storage */ #define Mkeep 1 /* keep only genes with replicates Mkeep or greater */ #define MAXLENGTH 30 /* maximum length of gene name strings */ int i, j, k, l, Norig, col_count; char line[10000], word[100], save_line[10000]; float **Xtemp, **Ytemp; char **yorf_temp, **gene_name_temp; int mstore[MAXGENES], internal2full_temp[MAXGENES] ; int Nkeep=0, mtemp=0; int N_col, Xcol[MAXREPS], Ycol[MAXREPS], Fcol[MAXREPS], index_to_find; int file_position, line_length, nXcols, nYcols, nFcols, npairs; char index_to_find_string[MAXREPS], full_string[MAXREPS]; char yorf_word[MAXLENGTH], gene_name_word[MAXLENGTH], *token; /* allocate temporary memory */ Xtemp = (float **) calloc( MAXGENES ,sizeof(float*)); Ytemp = (float **) calloc( MAXGENES ,sizeof(float*)); yorf_temp = (char **) calloc( MAXGENES ,sizeof(char*)); gene_name_temp = (char **) calloc( MAXGENES ,sizeof(char*)); for ( i=0 ; i string was not found */ break; } } if ( file_position == line_length && index_to_find == 0 ){ die("Error: No X0 column in data file\r\n"); return; } rewind(fpin); file_position = ftell(fpin ); /*************************** find Y fields **********************************/ nYcols=0; for( index_to_find=0 ; index_to_find string was not found */ break; } } if ( file_position == line_length && index_to_find == 0 ){ die("Error: No Y0 column in data file\r\n"); return; } rewind(fpin); file_position = ftell(fpin ); if( nXcols != nYcols ){ CString nx, ny; nx.Format("%d", nXcols); ny.Format("%d", nYcols); nx = "Numbers of X columns("+nx+") and Y columns ("+ny+") don't agree\r\n"; die(nx); return; } npairs = nXcols; /******************************* Look for flag, F, fields *****************************************************/ nFcols=0; for( index_to_find=0 ; index_to_find string was not found */ break; } } if ( file_position == line_length && index_to_find == 0 ){ /* did not find F0 string */ nFcols = -1; /* denotes that there are no qualitity flags on the replicates */ } rewind(fpin); file_position = ftell(fpin ); if( (nXcols != nFcols) && (nFcols != -1 )){ //printf("Error: Numbers of data pairs (%d) and F columns (%d) don't agree\n", npairs, nFcols ); CString np, nFc; np.Format("%d", npairs); nFc.Format("%d", nFcols); np = "Error: Numbers of data pairs ("+np+") and F columns ("+nFc+") don't agree\r\n"; die(np); return; } /*** Print out summary on column detection */ //printf("Maximum %d (X,Y) pairs from column headings: ", npairs); //for ( i=0 ; i= Mkeep ){ strcpy( yorf_temp[Nkeep], yorf_word ); strcpy( gene_name_temp[Nkeep], gene_name_word ); full2internal[i] = Nkeep; internal2full_temp[Nkeep] = i; mstore[Nkeep] = mtemp ; Nkeep++ ; /* increment kept gene counter */ } else { /* store excluded genes as -1 in indexing array */ full2internal[i] = -1; } } else if ( mtemp >= Mkeep && N_col != -1 ){ /* if N column is used for true no of samples and number of samples >= no required */ mstore[Nkeep] = mtemp; for ( j=0 ; j