MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mainWidget = new QWidget(); mainLayout = new QVBoxLayout(); horizLayout = new QHBoxLayout(); insertButton = new QPushButton("Insert Value"); deleteKeyButton = new QPushButton("Delete Key"); deleteKeyButton->setVisible(false); sortButton = new QPushButton("Sort Values"); sortButton->setVisible(false); sortedValues = new QLabel(); sortedValues->setVisible(false); sortedValues->setAlignment(Qt::AlignBottom | Qt::AlignCenter); searchButton = new QPushButton("Search!"); searchButton->setVisible(false); found = false; foundVal = 0; valuesSpinBox = new QSpinBox(this); valuesSpinBox->setMaximum(999); valuesSpinBox->setMinimum(-999); valuesSpinBox->setValue(42); QFont f; f.setPointSize(17); f.setBold(true); titleLabel = new QLabel("Jasper and Samuel David's\n Super-Cool Cartesian Tree Thingy"); titleLabel->setAlignment(Qt::AlignTop | Qt::AlignCenter); titleLabel->setFont(f); horizLayout->addWidget(insertButton); horizLayout->addWidget(valuesSpinBox); horizLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); horizLayout->addWidget(searchButton); horizLayout->addWidget(deleteKeyButton); mainLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); mainLayout->addWidget(titleLabel); mainLayout->addLayout(horizLayout); mainLayout->addWidget(sortButton); mainWidget->setLayout(mainLayout); setCentralWidget(mainWidget); connect(insertButton,SIGNAL(clicked()),this,SLOT(insert())); connect(deleteKeyButton, SIGNAL(clicked()), this, SLOT(removeKey())); connect(sortButton, SIGNAL(clicked()), this, SLOT(sortem())); connect(searchButton, SIGNAL(clicked()), this, SLOT(searchVal())); treeWidget = new QWidget(); srand (time(NULL)); }
int main() { srand(time(0)); for(int n=0;n<25;n++) { x[n]=rand()%11; } sortem(); find_median(); find_mode(); histogram(); sortem(); cout<<"To see the data scroll, "<<endl; system("pause"); scroll(); return 0; }
int main(int argc, char **argv) { ScopedMPIComm< BamSortOptions > world(argc, argv); Cleanup::prepare(); try { int rank = world.rank(), size = world.size(); BamVector reads; BamHeaderPtr header; std::string outputBam = BamSortOptions::getOptions().getOutputBam(); std::string outputBamTmp = outputBam + ".tmp"; OptionsBaseInterface::FileListType inputBams = BamSortOptions::getOptions().getInputBams(); int partitions = BamSortOptions::getOptions().getNumPartitions(); if (partitions > 1) { if (size != (int) inputBams.size()) { if (rank == 0) std::cerr << "The number of files is a mismatch to the job size. When merging partitions, this is necessary." << BamSortOptions::getDesc() << std::endl; exit(1); } if (size % partitions != 0) { if (rank == 0) std::cerr << "The partitions " << partitions << " is not a factor of the size " << size << BamSortOptions::getDesc() << std::endl; exit(1); } } if (world.rank() == 0) unlink(outputBamTmp.c_str()); world.barrier(); LOG_VERBOSE_GATHER(1, "Reading input files"); if (partitions > 1) { std::string myInputFile = inputBams[rank]; int color = rank / partitions; mpi::communicator partitionWorld = world.split(color); LOG_VERBOSE_GATHER(1, "Input: " << myInputFile << " split color: " << color << " rank: " << partitionWorld.rank() << " of " << partitionWorld.size()); SamUtils::MPIMergeSam mergeSam(partitionWorld, myInputFile, reads); if (color == 0) mergeSam.outputMergedHeader(outputBamTmp); world.barrier(); } else { header = BamStreamUtils::readBamFile(world, inputBams, reads); } bool needsCollapse = false; bool keepUnmappedPairedRead = BamSortOptions::getOptions().getKeepUnmappedPairedRead(); std::string unmappedReadPairFile = BamSortOptions::getOptions().getUnmappedReadPairs(); std::string unmappedReadsFile = BamSortOptions::getOptions().getUnmappedReads(); BamVector unmappedReadSingles, unmappedReadPairs, unmappedPairedReads; if (!unmappedReadPairFile.empty() || !unmappedReadsFile.empty()) { std::string tmpFile(unmappedReadPairFile + ".tmp"); std::string tmpFile2(unmappedReadsFile + ".tmp"); if (world.rank() == 0) { unlink(tmpFile.c_str()); unlink(tmpFile2.c_str()); } world.barrier(); SamUtils::splitUnmapped(reads, unmappedReadSingles, unmappedReadPairs, unmappedPairedReads, keepUnmappedPairedRead); if (!unmappedReadSingles.empty() || !unmappedReadPairs.empty() || (!keepUnmappedPairedRead && !unmappedPairedReads.empty())) { needsCollapse = true; } LOG_VERBOSE(1, "Purging unmapped read pairs: " << unmappedReadPairs.size()); if (!unmappedReadPairFile.empty() && unmappedReadPairFile.compare("/dev/null") != 0) { LOG_VERBOSE(1, "Writing unmappedReadPairs " << unmappedReadPairs.size() << " to " << unmappedReadPairFile << " (" << tmpFile << ")"); ScopedMPIFile pairedReads(world, tmpFile); SamUtils::writeFastqGz(world, unmappedReadPairs, pairedReads, true); world.barrier(); } assert(unmappedReadPairs.empty()); LOG_VERBOSE(1, "Purging unmapped read singles: " << unmappedPairedReads.size() << " and " << unmappedReadSingles.size()); if (!unmappedReadsFile.empty() && unmappedReadsFile.compare("/dev/null") != 0) { LOG_VERBOSE(1, "Writing unmappedPairedReads " << unmappedPairedReads.size() << " to " << unmappedReadsFile << " (" << tmpFile2 << ")"); ScopedMPIFile singleReads(world, tmpFile2); SamUtils::writeFastqGz(world, unmappedPairedReads, singleReads, !keepUnmappedPairedRead); LOG_VERBOSE(1, "Writing unmappedReadSingles " << unmappedReadSingles.size() << " to " << unmappedReadsFile << " (" << tmpFile2 << ")"); SamUtils::writeFastqGz(world, unmappedReadSingles, singleReads, true); world.barrier(); } assert(unmappedReadSingles.empty()); assert(keepUnmappedPairedRead || unmappedPairedReads.empty()); if (world.rank() == 0) { unlink(unmappedReadsFile.c_str()); unlink(unmappedReadPairFile.c_str()); rename(tmpFile.c_str(), unmappedReadPairFile.c_str()); if (tmpFile.compare(tmpFile2) != 0) { rename(tmpFile2.c_str(), unmappedReadsFile.c_str()); } } } if (needsCollapse) { LOG_DEBUG(1, "Collapsing read vector"); long removed = SamUtils::collapseVector(reads); LOG_DEBUG(1, "Collapsed: " << removed); } BamManager::destroyOrRecycleBamVector(unmappedReadSingles); BamManager::destroyOrRecycleBamVector(unmappedReadPairs); if (keepUnmappedPairedRead) { unmappedPairedReads.clear(); } else { BamManager::destroyOrRecycleBamVector(unmappedPairedReads); } { LOG_VERBOSE_GATHER(1, "Redistributing reads before the sort:" << reads.size()); BamStreamUtils::distributeReadsFinal(world, reads); LOG_VERBOSE_GATHER(1, "Sorting myreads: " << reads.size()); SamUtils::MPISortBam sortem(world, reads, outputBamTmp, header.get()); world.barrier(); if (world.rank() == 0) { unlink(outputBam.c_str()); rename(outputBamTmp.c_str(), outputBam.c_str()); } } header.reset(); BamManager::clearRecycledReads(); LOG_VERBOSE_GATHER(1, "Finished"); return 0; } catch (std::exception &e) { LOG_ERROR(1, "BamSort-P threw an exception! Aborting...\n\t" << e.what()); world.abort(1); } catch (...) { LOG_ERROR(1, "BamSort-P threw an error! Aborting...\n"); world.abort(1); } }