// Constructor to create a playlist gui gui::gui(QWidget *parent) : QWidget(parent) { /***** Initialize Data Structures *****/ load_song_info(); load_playlist_info(); build_trie(); /***** Set Theme ******/ text.setColor(QPalette::WindowText, Qt::white); win.setColor(QPalette::Window, QColor::fromRgb(84, 163, 0, 255)); this->setPalette(win); /***** Generate GUI *****/ generate_main_page(); generate_help_page(); generate_add_page(); main_page = new QWidget(this); main_page->setLayout(main_layout); help_page = new QWidget(this); help_page->setLayout(help_layout); add_page = new QWidget(this); add_page->setLayout(add_layout); window = new QStackedWidget(this); window->addWidget(main_page); window->addWidget(help_page); window->addWidget(add_page); window_layout = new QVBoxLayout; window_layout->addWidget(window); setLayout(window_layout); }
// Button handler for saving manually added playlists void gui::add_save_playlist_button_handler() { // Try getting popularity as an integer int popularity; popularity = atoi(add_popularity->text().toStdString().c_str()); std::stringstream out; out << popularity; // Verify that popularity is an integer and its greater than 0 if (add_popularity->text().length() == (int)out.str().length() && popularity >= 0) { // Create a temporary playlist object playlist_obj temp; temp.songs = add_songs; temp.popularity = popularity; // Try saving the playlist if (list_of_playlists->insert_playlist(temp)) { // If successful, reset add page and return to main page add_songs.clear(); add_displayed_song = NULL; add_selected_songs_list->clear(); add_popularity->setText("0"); add_search_song->setText(""); add_load_file->setText(""); add_selected_song_label->setText("-- No song selected --"); window->setCurrentIndex(0); // Rebuild the trie to update all preprocessed values // - Four suggested songs // - Eight most popular playlists delete trie; build_trie(); // Update the playlist widget to reflect changes playslists->clear(); update_playlists(); } else { // If not successful with saving playlist, show error message QMessageBox messageBox; messageBox.setWindowTitle("Error"); messageBox.setText("Error Adding Playlist. Playlist Not Added"); messageBox.exec(); } } else { // If popularity entry is invalid, show error message QMessageBox messageBox; messageBox.setWindowTitle("Error"); messageBox.setText("Please Enter A Valid Popularity (Integer Greater Than or Equal to 0)"); messageBox.exec(); } }
static enum STATE xml_post_processing ( struct xml_element* elem ) { if ( !elem ) return OK; enum STATE state; reverse_son_list( elem ); state = build_trie( elem->son, (void*)&elem->sons_trie ); if ( state != OK ) return state; state = build_trie( elem->attr, (void*)&elem->attr_trie ); if ( state != OK ) return state; state = xml_post_processing ( elem->next ); if ( state != OK ) return state; state = xml_post_processing ( elem->son ); return state; }
std::vector<std::string> find_words(std::vector<std::vector<char>>& board, std::vector<std::string>& dictionary) { std::vector<std::string> result; for (int i = 0; i < board.size(); ++i) { for (int j = 0; j < board[0].size(); ++j) { TrieNode* root = build_trie(dictionary); backtrack(board, root, i, j, result); } } return result; }
// Button handler for loading playlists from a file void gui::add_load_file_button_handler() { // Get filename from LineEdit string file_name = add_load_file->text().toStdString(); // Attempt to add playlists in the file if(list_of_playlists->insert_playlists(file_name)) { // If successful, reset add page and return to main page add_songs.clear(); add_displayed_song = NULL; add_selected_songs_list->clear(); add_popularity->setText("0"); add_search_song->setText(""); add_load_file->setText(""); add_selected_song_label->setText("-- No song selected --"); window->setCurrentIndex(0); // Rebuild the trie to update all preprocessed values // - Four suggested songs // - Eight most popular playlists delete trie; build_trie(); // Update the playlist widget to reflect changes playslists->clear(); update_playlists(); } else { // If not successful, show error message QMessageBox messageBox; messageBox.setWindowTitle("Error"); messageBox.setText("One Or More Playlists Not Added. Check File Name and Contents."); messageBox.exec(); } }
/*! \brief The main function of the **rm_reads** tool. */ int main(int argc, char ** argv) { Node root('0'); std::vector <std::pair<std::string, Node::Type> > patterns; std::string kmers, reads, out_dir; std::string reads1, reads2; char rez = 0; int length = 0; int polyG = 0; int dust_k = 4; int dust_cutoff = 0; int errors = 0; const struct option long_options[] = { {"fragments",required_argument,NULL,'f'}, {"errors",required_argument,NULL,'e'}, {NULL,0,NULL,0} }; while ((rez = getopt_long(argc, argv, "1:2:f:i:o:", long_options, NULL)) != -1) { switch (rez) { case 'f': kmers = optarg; break; case 'i': reads = optarg; break; case '1': reads1 = optarg; break; case '2': reads2 = optarg; break; case 'o': out_dir = optarg; break; case '?': print_help(); return -1; } } if (errors < 0 || errors > 2) { std::cerr << "possible errors count are 0, 1, 2" << std::endl; return -1; } if (kmers.empty() || out_dir.empty() || ( reads.empty() && (reads1.empty() || reads2.empty()))) { print_help(); return -1; } if (!verify_directory(out_dir)) { std::cerr << "Output directory does not exist, failed to create" << std::endl; return -1; } std::ifstream kmers_f (kmers.c_str()); if (!kmers_f.good()) { std::cerr << "Cannot open kmers file" << std::endl; print_help(); return -1; } init_type_names(length, polyG, dust_k, dust_cutoff); build_patterns(kmers_f, patterns); /* for (std::vector <std::string> ::iterator it = patterns.begin(); it != patterns.end(); ++it) { std::cout << *it << std::endl; } */ if (patterns.empty()) { std::cerr << "patterns are empty" << std::endl; return -1; } std::cerr << "Building trie..." << std::endl; build_trie(root, patterns, errors); add_failures(root); if (!reads.empty()) { std::string reads_base = basename(reads); std::ifstream reads_f (reads.c_str()); std::ofstream ok_f((out_dir + "/" + reads_base + ".ok.fastq").c_str(), std::ofstream::out); std::ofstream bad_f((out_dir + "/" + reads_base + ".filtered.fastq").c_str(), std::ofstream::out); if (!reads_f.good()) { std::cerr << "Cannot open reads file" << std::endl; print_help(); return -1; } if (!ok_f.good() || !bad_f.good()) { std::cerr << "Cannot open output file" << std::endl; print_help(); return -1; } Stats stats(reads); filter_single_reads(reads_f, ok_f, bad_f, stats, &root, patterns, length, dust_k, dust_cutoff, errors); std::cout << stats; ok_f.close(); bad_f.close(); reads_f.close(); } else { std::string reads1_base = basename(reads1); std::string reads2_base = basename(reads2); std::ifstream reads1_f(reads1.c_str()); std::ifstream reads2_f(reads2.c_str()); std::ofstream ok1_f((out_dir + "/" + reads1_base + ".ok.fastq").c_str(), std::ofstream::out); std::ofstream ok2_f((out_dir + "/" + reads2_base + ".ok.fastq").c_str(), std::ofstream::out); std::ofstream se1_f((out_dir + "/" + reads1_base + ".se.fastq").c_str(), std::ofstream::out); std::ofstream se2_f((out_dir + "/" + reads2_base + ".se.fastq").c_str(), std::ofstream::out); std::ofstream bad1_f((out_dir + "/" + reads1_base + ".filtered.fastq").c_str(), std::ofstream::out); std::ofstream bad2_f((out_dir + "/" + reads2_base + ".filtered.fastq").c_str(), std::ofstream::out); if (!reads1_f.good() || !reads2_f.good()) { std::cerr << "reads file is bad" << std::endl; print_help(); return -1; } if (!ok1_f.good() || !ok2_f.good() || !bad1_f.good() || !bad2_f.good() || !se1_f.good() || !se2_f.good()) { std::cerr << "out file is bad" << std::endl; print_help(); return -1; } Stats stats1(reads1); Stats stats2(reads2); filter_paired_reads(reads1_f, reads2_f, ok1_f, ok2_f, bad1_f, bad2_f, se1_f, se2_f, stats1, stats2, &root, patterns, length, dust_k, dust_cutoff, errors); std::cout << stats1; std::cout << stats2; ok1_f.close(); ok2_f.close(); bad1_f.close(); bad2_f.close(); reads1_f.close(); reads2_f.close(); } }