void BLAPDBImpl::write2PDB() { string proteinName; int subjectStart; string subject; int subjectEnd; int queryStart; string query; int queryEnd; int length; for (int i = 0; i < blaPDBResultVector.size(); i++) { proteinName = blaPDBResultVector[i].getProteinName(); queryStart = blaPDBResultVector[i].getQueryStart(); query = blaPDBResultVector[i].getQuery(); queryEnd = blaPDBResultVector[i].getQueryEnd(); subjectStart = blaPDBResultVector[i].getSubjectStart(); subject = blaPDBResultVector[i].getSubject(); subjectEnd = blaPDBResultVector[i].getSubjectEnd(); int queryHeadMore = queryStart - 1; int queryTailMore = proteinSeqLength - queryEnd; vector<float> Xs = blaPDBResultVector[i].getXCoords(); vector<float> Ys = blaPDBResultVector[i].getYCoords(); vector<float> Zs = blaPDBResultVector[i].getZCoords(); vector<char> templateSeq = blaPDBResultVector[i].getTemplateSeq(); length = blaPDBResultVector[i].getLength(); int subjectHeadMore = subjectStart - 1; int subjectTailMore = length - subjectEnd; int headMore = 0; if (queryHeadMore > subjectHeadMore) { headMore = subjectHeadMore; } else { headMore = queryHeadMore; } int tailMore = 0; if (queryTailMore > subjectTailMore) { tailMore = subjectTailMore; } else { tailMore = queryTailMore; } string protein3DCorrdsFilename(outputFileLocation); protein3DCorrdsFilename += "/"; protein3DCorrdsFilename += rootName; protein3DCorrdsFilename += "/BLAPDB/pdbFiles/"; protein3DCorrdsFilename += proteinName; protein3DCorrdsFilename += "_"; protein3DCorrdsFilename += subject; protein3DCorrdsFilename += ".pdb"; ofstream pdbFile((char*) protein3DCorrdsFilename.c_str(), ios::out); while (headMore > 0) { if (Xs[subjectStart - headMore - 1] != 10000 && Ys[subjectStart - headMore - 1] != 10000 && Zs[subjectStart - headMore - 1] != 10000) { pdbFile << "ATOM "; //record name pdbFile << right << setw(5) << subjectStart - headMore; // atom serial number pdbFile << " CA "; //atom name pdbFile << setw(3) << convertResidueName( originalProteinSeq[queryStart - headMore - 1]); //pdbFile<<templateSeq[subjectStart - headMore];//for debug pdbFile << right << setw(6) << subjectStart - headMore; // atom serial number pdbFile << " "; pdbFile << right << setw(8.3) << Xs[subjectStart - headMore - 1]; pdbFile << right << setw(8.3) << Ys[subjectStart - headMore - 1]; pdbFile << right << setw(8.3) << Zs[subjectStart - headMore - 1]; pdbFile << " 1.00 0.00\n"; } headMore--; } int queryPos = 1; int subjectPos = 1; for (int j = 0; j < subject.size(); j++) { if (subject[j] == '-' || query[j] != '-') { queryPos++; continue; //outJsonFile << "\"" << subject[j] << "\":\"" // << "10000,10000,10000\"\n"; } else if (subject[j] != '-' || query[j] == '-') { subjectPos++; continue; } else if (subject[j] == '-' || query[j] == '-') { continue; } else { if (Xs[subjectStart + subjectPos - 2] != 10000 && Ys[subjectStart + subjectPos - 2] != 10000 && Zs[subjectStart + subjectPos - 2] != 10000) { pdbFile << "ATOM "; //record name pdbFile << right << setw(5) << subjectStart + subjectPos - 1; // atom serial number pdbFile << " CA "; //atom name pdbFile << setw(3) << convertResidueName(query[j]); //pdbFile<<query[ j - 1]; //for dubug pdbFile << right << setw(6) << subjectStart + subjectPos - 1; // atom serial number pdbFile << " "; pdbFile << right << setw(8.3) << Xs[subjectStart + subjectPos - 2]; pdbFile << right << setw(8.3) << Ys[subjectStart + subjectPos - 2]; pdbFile << right << setw(8.3) << Zs[subjectStart + subjectPos - 2]; pdbFile << " 1.00 0.00\n"; } subjectPos++; queryPos++; } } //cout<<"Tailmore"<<tailMore<<endl;; if (tailMore > 0) { for (int k = 0; k < tailMore; k++) { if (Xs[subjectEnd + k] != 10000 && Ys[subjectEnd + k] != 10000 && Zs[subjectEnd + k] != 10000) { pdbFile << "ATOM "; //record name pdbFile << right << setw(5) << subjectEnd + k; // atom serial number pdbFile << " CA "; //atom name pdbFile << setw(3) << convertResidueName( originalProteinSeq[queryEnd + k]); pdbFile << right << setw(6) << subjectEnd + k; // atom serial number pdbFile << " "; pdbFile << right << setw(8.3) << Xs[subjectEnd + k]; pdbFile << right << setw(8.3) << Ys[subjectEnd + k]; pdbFile << right << setw(8.3) << Zs[subjectEnd + k]; pdbFile << " 1.00 0.00\n"; } } } pdbFile << "TER\n"; pdbFile.close(); } }
// -------------------------------------------------------- // ---------- ReloadDB ------------------------------------ // -------------------------------------------------------- void MIViewBrowser::ReloadDB() { int i; wxString msg; /* before anything, clear the tree control */ treeFileList->DeleteAllItems(); /* read in the database file */ wxString line; wxString patient, study, series, filename; wxString date,time, dob; wxDateTime studyDateTime; int numLines; wxTextFile pdbFile("browsedb.txt"); pdbFile.Open(); rootID = treeFileList->AddRoot("Root"); wxTreeItemId curPatientID, curStudyID, curSeriesID, curFileID; /* loop through, line by line */ numLines = (int)pdbFile.GetLineCount(); /* setup the progress dialog */ wxProgressDialog progDlg(wxT("Loading Database..."), wxT(" "), numLines, this, wxPD_SMOOTH | wxPD_ELAPSED_TIME | wxPD_CAN_ABORT); for (i=0;i<numLines;i++) { if (!progDlg.Update(i,msg.Format("Reading entry %d of %d",i,numLines))) break; line = pdbFile[i]; if (line[0] != '\t') { /* its a new patient/DOB item */ /* add a node to the root, set current patient node ID */ patient = line.Trim(true).Trim(false); dob = patient.AfterFirst('&'); dob = ParseDate(dob); patient = patient.BeforeFirst('&'); patient.Replace("^",","); patient += " (DOB: " + dob + ")"; curPatientID = treeFileList->AppendItem(rootID,patient,0); treeFileList->SetItemBackgroundColour(curPatientID,wxColour(200,200,200)); treeFileList->SetItemBold(curPatientID); } if ((line[0] == '\t') && (line[1] != '\t')) { /* add a new studyDate node, set current studyDate node ID */ study = line.Trim(true).Trim(false); date = study.BeforeFirst('&'); time = study.AfterFirst('&'); study = ParseDateAndTime(date,time); curStudyID = treeFileList->AppendItem(curPatientID,study,1); treeFileList->SetItemBackgroundColour(curStudyID,wxColour(225,225,225)); } if ((line[0] == '\t') && (line[1] == '\t') && (line[2] != '\t')) { /* add a new seriesNumber node, set current seriesNumber node ID */ series = line.Trim(true).Trim(false); curSeriesID = treeFileList->AppendItem(curStudyID,series,2); } if ((line[0] == '\t') && (line[1] == '\t') && (line[2] == '\t')) { /* add a new filename node */ filename = line.Trim(true).Trim(false); curFileID = treeFileList->AppendItem(curSeriesID,filename); } ::wxSafeYield(); } ExpandAllPatients(); }