void docItem::openItem(){ if (list.size() == 0){ ui.lineEdit_title->clear(); } else if (list.size() > 0){ QSqlQuery query(QString("select book_item.book, books.title, book_item.identifier " "from book_item,doc_item, books " "where doc_item.book_item = book_item.id and books.id = book_item.book " "and doc_item.id = \'%1\' ").arg(list.at(curr))); query.next(); ui.spinBox_id_book->setValue(query.value(0).toInt()); ui.lineEdit_title->setText(query.value(1).toString()); //ui.spinBox_coun->setValue(query.value(2).toInt()); ui.lineEdit_identifier->setText(query.value(2).toString()); } viewItems(); //test for deleting if (vid == 1){ QSqlQuery testRead(QString("select Count(card_read.id) " "from card_read, book_item " "where card_read.book_item = book_item.id and book_item.identifier = \'%1\'") .arg(ui.lineEdit_identifier->text())); testRead.next(); QSqlQuery testDoc(QString("select Count(doc_item.id) " "from doc_item, docs, book_item " "where doc_item.book_item = book_item.id and doc_item.doc = docs.id and docs.vid = 2 " "and book_item.identifier = \'%1\'") .arg(ui.lineEdit_identifier->text())); testDoc.next(); if (testRead.value(0).toInt() == 0 and testDoc.value(0).toInt() == 0){ ui.pushButton_del->setEnabled(true); } else if (testRead.value(0).toInt() > 0 or testDoc.value(0).toInt() > 0){ ui.pushButton_del->setEnabled(false); } } else if (vid == 2){ ui.pushButton_del->setEnabled(true); } // if (list.size() == 0){ ui.pushButton_toFirst->setEnabled(false); ui.pushButton_toLast->setEnabled(false); ui.pushButton_toNext->setEnabled(false); ui.pushButton_toPrev->setEnabled(false); } else if (list.size() > 0) { if (curr == 0){ ui.pushButton_toFirst->setEnabled(false); ui.pushButton_toPrev->setEnabled(false); } else { ui.pushButton_toFirst->setEnabled(true); ui.pushButton_toPrev->setEnabled(true); } if (curr == list.size() - 1){ ui.pushButton_toLast->setEnabled(false); ui.pushButton_toNext->setEnabled(false); } else { ui.pushButton_toLast->setEnabled(true); ui.pushButton_toNext->setEnabled(true); } } }
int main(int argc, char** argv) { printf("start\n"); ObjStoreContext* pContext = (ObjStoreContext*)malloc(sizeof(ObjStoreContext)); InitObjStore(pContext, "/tmp/objstore/"); if (argc == 1) { //for debug testWrite(pContext, 10, 0x5f, 9097); testRead(pContext, 10, 0x5f, 9097); testCheck(pContext, 10, 9097); testWriteRange(pContext, 10, 0x6f, 4096, 4096); testReadRange(pContext, 10, 0x6f, 4096, 4096); } else { if (argc == 5) { int maxobjid = atoi(argv[2]); int mask = atoi(argv[3]); int datasize = atoi(argv[4]); if(strcmp(argv[1],"-w") == 0) { printf("start write...\n"); testWrite(pContext, maxobjid, mask, datasize); } else if (strcmp(argv[1], "-r") == 0) { printf("start read...\n"); testRead(pContext, maxobjid, mask, datasize); } else { usage(); return 1; } } else if (argc == 4) { int maxobjid = atoi(argv[2]); int datasize = atoi(argv[3]); if (strcmp(argv[1], "-c") == 0) { printf("start check...\n"); testCheck(pContext, maxobjid, datasize); } else { usage(); return 1; } } else if (argc == 6) { int maxobjid = atoi(argv[2]); int mask = atoi(argv[3]); int startpos = atoi(argv[4]); int datasize = atoi(argv[5]); if (strcmp(argv[1], "-wp") == 0) { printf("start write range ...\n"); testWriteRange(pContext, maxobjid, mask, startpos, datasize); } else if (strcmp(argv[1], "-rp") == 0) { printf("start read range ... \n"); testReadRange(pContext, maxobjid, mask, startpos, datasize); } else if (strcmp(argv[1], "-cp") == 0) { printf("start check range ... \n"); testCheckRange(pContext, maxobjid, mask,startpos, datasize); } } else { usage(); return 1; } } system("pause"); return 0; }
/********************************************************************************************************************** This function reads the sdataset from FASTA/FASTQ files **********************************************************************************************************************/ bool Dataset::readDataset(string fileName, UINT64 minOverlap, UINT64 datasetNumber) { CLOCKSTART; cout << "Reading dataset: " << datasetNumber << " from file: " << fileName << endl; ifstream myFile; myFile.open (fileName.c_str()); if(myFile == NULL) MYEXIT("Unable to open file: "+fileName) UINT64 goodReads = 0, badReads = 0; vector<string> line; string line1, text, line1ReverseComplement,line2ReverseComplement; enum FileType { FASTA, FASTQ, UNDEFINED}; FileType fileType = UNDEFINED; while(!myFile.eof()) { if( (goodReads + badReads ) != 0 && (goodReads + badReads)%1000000 == 0) cout<< setw(10) << goodReads + badReads << " reads processed in dataset " << setw(2) << datasetNumber <<". " << setw(10) << goodReads << " good reads." << setw(10) << badReads << " bad reads." << endl; if(fileType == UNDEFINED) { getline (myFile,text); if(text[0] == '>') fileType = FASTA; else if(text[0] == '@') fileType = FASTQ; else MYEXIT("Unknown input file format."); myFile.seekg(0, ios::beg); } line.clear(); if(fileType == FASTA) // Fasta file { getline (myFile,text); line.push_back(text); getline (myFile,text,'>'); line.push_back(text); line.at(1).erase(std::remove(line.at(1).begin(), line.at(1).end(), '\n'), line.at(1).end()); line1 = line.at(1); // The first string is in the 2nd line. } else if(fileType == FASTQ) // Fastq file. { for(UINT64 i = 0; i < 4; i++) // Read the remaining 3 lines. Total of 4 lines represent one sequence in a fastq file. { getline (myFile,text); line.push_back(text); } line1 = line.at(1); // The first string is in the 2nd line. } for (std::string::iterator p = line1.begin(); line1.end() != p; ++p) // Change the case *p = toupper(*p); if(line1.length() > minOverlap && testRead(line1) ) // Test the read is of good quality. { Read *r1=new Read; line1ReverseComplement = reverseComplement(line1); if(line1.compare(line1ReverseComplement) < 0) // Store lexicographically smaller between the read and its reverse complement. r1->setRead(line1); else r1->setRead(line1ReverseComplement); UINT64 len = r1->getReadLength(); if(len > longestReadLength) longestReadLength = len; if(len < shortestReadLength) shortestReadLength = len; reads->push_back(r1); // Store the first string in the dataset. numberOfReads++; // Counter of the total number of reads. goodReads++; } else badReads++; } myFile.close(); cout << endl << "Dataset: " << setw(2) << datasetNumber << endl; cout << "File name: " << fileName << endl; cout << setw(10) << goodReads << " good reads in current dataset." << endl; cout << setw(10) << badReads << " bad reads in current dataset." << endl; cout << setw(10) << goodReads + badReads << " total reads in current dataset." << endl; cout << setw(10) << numberOfReads << " good reads in all datasets." << endl << endl;; CLOCKSTOP; return true; }
/********************************************************************************************************************** This function reads the file again and store matepair infromation. **********************************************************************************************************************/ bool Dataset::storeMatePairInformation(string fileName, UINT64 minOverlap, UINT64 datasetNumber) { CLOCKSTART; cout << "Store paired-end information of dataset: " << datasetNumber << " from file: " << fileName << endl; UINT64 goodMatePairs = 0, badMatePairs = 0; ifstream myFile; myFile.open (fileName.c_str()); if(myFile == NULL) MYEXIT("Unable to open file: "+fileName) vector<string> line; string line1, line2, text, line1ReverseComplement,line2ReverseComplement; Read r1, r2; enum FileType { FASTA, FASTQ, UNDEFINED}; FileType fileType = UNDEFINED; while(!myFile.eof()) { if(goodMatePairs+badMatePairs != 0 && (goodMatePairs+badMatePairs)%1000000 == 0) { cout << setw(10) << goodMatePairs + badMatePairs << " reads processed in store mate-pair information." << setw(10) << goodMatePairs << " reads in good mate-pairs." << setw(10) << badMatePairs << " reads in bad mate-pairs." << endl; } if(fileType == UNDEFINED) { getline (myFile,text); if(text[0] == '>') fileType = FASTA; else if(text[0] == '@') fileType = FASTQ; else MYEXIT("Unknown input file format."); myFile.seekg(0, ios::beg); } line.clear(); if(fileType == FASTA) // Fasta file { getline (myFile,text); line.push_back(text); getline (myFile,text,'>'); line.push_back(text); getline (myFile,text); line.push_back(text); getline (myFile,text,'>'); line.push_back(text); line.at(1).erase(std::remove(line.at(1).begin(), line.at(1).end(), '\n'), line.at(1).end()); line1 = line.at(1); // The first string is in the 2nd line. line.at(3).erase(std::remove(line.at(3).begin(), line.at(3).end(), '\n'), line.at(3).end()); line2 = line.at(3); // The second string is in the 4th line. } else if(fileType == FASTQ) // Fastq file. { for(UINT64 i = 0; i < 8; i++) // Read the remaining 7 lines. Total of 8 lines represent two sequence in a fastq file. { getline (myFile,text); line.push_back(text); } line1 = line.at(1); // The first string is in the 2nd line. line2 = line.at(5); // The second string is in the 6th lien. } for (std::string::iterator p = line1.begin(); line1.end() != p; ++p) // Change the case *p = toupper(*p); for (std::string::iterator p = line2.begin(); line2.end() != p; ++p) // Change the case *p = toupper(*p); if(line1.length() > minOverlap && line2.length() > minOverlap && testRead(line1) && testRead(line2)) // Test if both reads are of good quality. { Read * r1 = getReadFromString(line1),* r2 = getReadFromString(line2); if (r1->superReadID != 0) // This read is contained by the superRead r1 = getReadFromID(r1->superReadID); if (r2->superReadID != 0) // This read is contained by the superRead. r2 = getReadFromID(r2->superReadID); goodMatePairs += 2; UINT16 orient1, orient2; string read1Froward = r1->getStringForward(); string read2Froward = r2->getStringForward(); orient1 = read1Froward.find(line1) != string::npos ? 1 : 0; orient2 = read2Froward.find(line2) != string::npos ? 1 : 0; r1->addMatePair(r2, orient1 * 2 + orient2, datasetNumber); // Two bits are used to represent the orientation of the reads in a matepair. r2->addMatePair(r1, orient1 + orient2 * 2, datasetNumber); // 0 = 00 means the reverse of r1 and the reverse of r2 are matepairs. // 1 = 01 means the reverse of r1 and the forward of r2 are matepairs. // 2 = 10 means the forward of r1 and the reverse of r2 are matepairs. // 3 = 11 means the forward of r1 and the forward of r2 are matepairs. } else badMatePairs +=2; } cout << endl << "Dataset: " << setw(2) << datasetNumber << endl; cout << "File name: " << fileName << endl; cout << setw(10) << goodMatePairs << " reads in " << setw(10) << goodMatePairs/2 << " mate-pairs are good." << endl; cout << setw(10) << badMatePairs << " reads in " << setw(10) << badMatePairs/2 << " mate-pairs are discarded." << endl << endl; myFile.close(); CLOCKSTOP; return true; }
int main() { testWrite(); testRead(); return 0; }