void basics::copy_folder(const bfs::path& frompath, const bfs::path& topath) { // Check whether the function call is valid if (!bfs::exists(frompath) || !bfs::is_directory(frompath)) { std::stringstream err; err << "Source directory " << frompath.string() << " does not exist or is not a directory."; throw std::runtime_error(err.str()); } if(bfs::exists(topath)) { std::stringstream err; err << "Destination directory " << topath.string() << " already exists."; throw std::runtime_error(err.str()); } // Create the destination directory if(!bfs::create_directory(topath)) { std::stringstream err; err << "Unable to create destination directory " << topath.string(); throw std::runtime_error(err.str()); } // Iterate through the source directory for(bfs::directory_iterator file(frompath); file != bfs::directory_iterator(); ++file) { bfs::path current(file->path()); if(bfs::is_directory(current)) { // Found directory: Recursion copy_folder(current, topath / current.filename()); } else { // Found file: Copy bfs::copy_file(current, topath / current.filename()); } } }
void World::saveToFile(const bfs::path & path) const { Logger::get().debug("Сохранение объектов в файл %1%") % path.string(); json::Object jworld(json::Object::Hash); // Local rect { b2AABB combinedAABB; combinedAABB.lowerBound.Set( FLT_MAX, FLT_MAX); combinedAABB.upperBound.Set(-FLT_MAX, -FLT_MAX); for(const b2Body * b2body = getB2World()->GetBodyList(); b2body; b2body = b2body->GetNext()) { const Body * body = static_cast<const Body *>(b2body->GetUserData()); if(body->isDynamic()) combinedAABB.Combine(body->getB2AABB()); } jworld.add("aabb", Rectf::fromB2AABB(combinedAABB).toJson()); } // Bodies { json::Object jentities(json::Object::Array); for(auto it = getBodyIterator(); it; ++it) if(it.get()->isDynamic()) jentities.add(it.get()->getEntity()->toJson()); jworld.add("entities", std::move(jentities)); } std::ofstream file(path.string()); assert(file.good()); file << std::move(jworld.toString(false)); }
void BamReaderPool::openBamFile(const bfs::path& file) { if (file.empty()) { throw BamReaderPoolException("No BAM file specified."); } std::lock_guard<std::mutex> lock(poolmtx_); // GUARD closeBamFile_nolock(); if (!open_) { // try to open all readers for (BamTools::BamReader& reader : readers_) { if (!reader.Open(file.c_str())) { throw BamReaderPoolException( "Unable to open BAM file " + file.string() + ":\n\t" + reader.GetErrorString()); } } // try to open index for (BamTools::BamReader& reader : readers_) { if (!reader.LocateIndex()) { throw BamReaderPoolException( "Unable to open BAM index file " + file.string() + ":\n\t" + reader.GetErrorString()); } } // all are open, now push them onto the queue for (BamTools::BamReader& reader : readers_) { pushReader(reader); } file_ = file; open_ = true; } else { throw BamReaderPoolException("Failed to close BAM reader pool."); } }
void find(const bfs::path& cdb_path, const options& opt) { config cfg = load_config(cdb_path / "config"); const bfs::path cdb_root = cdb_path.parent_path(); const bfs::path search_root = bfs::initial_path(); std::size_t prefix_size = 0; std::string file_match; if(opt.m_options.count("-a") == 0 && search_root != cdb_root) { file_match = "^" + escape_regex( search_root.generic_string().substr(cdb_root.string().size() + 1) + "/") + ".*"; prefix_size = search_root.string().size() - cdb_root.string().size(); } file_lock lock(cdb_path / "lock"); lock.lock_sharable(); const char* find_regex_options = opt.m_options.count("-i") ? "i" : ""; const char* file_regex_options = cfg.get_value("nocase-file-match") == "on" ? "i" : ""; bool trim = cfg.get_value("find-trim-ws") == "on"; unsigned thread_count = get_thread_count(cfg); unsigned buffer_count = get_buffer_count(thread_count); for(unsigned i = 0; i != opt.m_args.size(); ++i) { database_ptr db = open_database(cdb_path / "db"); std::string pattern = opt.m_args[i]; if(opt.m_options.count("-v")) pattern = escape_regex(pattern); mt_search mts(*db, trim, prefix_size, buffer_count); auto worker = [&] { mts.search_db(compile_regex(pattern, 0, find_regex_options), compile_regex(file_match, 0, file_regex_options)); }; boost::thread_group workers; for(unsigned i = 0; i != thread_count-1; ++i) workers.create_thread(worker); worker(); workers.join_all(); } }
void RunFolderGenerator::generateRunInfo() const { using boost::property_tree::ptree; ptree pt; pt.put("RunInfo.<xmlattr>.xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); pt.put("RunInfo.<xmlattr>.xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); pt.put("RunInfo.<xmlattr>.Version", "2"); pt.put("RunInfo.Run.<xmlattr>.Id", runFolder_); pt.put("RunInfo.Run.<xmlattr>.Number", runInfo_.runNumber); pt.put("RunInfo.Run.<xmlattr>.TileNameMethod", runInfo_.tileNameMethod); ptree &run = pt.get_child("RunInfo.Run"); run.put("Flowcell", flowcell_); run.put("Date", runFolderDate_); run.put("FlowcellLayout.<xmlattr>.LaneCount", runInfo_.laneCount); run.put("FlowcellLayout.<xmlattr>.SurfaceCount", runInfo_.surfaceCount); run.put("FlowcellLayout.<xmlattr>.SwathCount", runInfo_.swathCount); run.put("FlowcellLayout.<xmlattr>.TileCount", runInfo_.tileCount); run.put("Reads", ""); ptree &reads = run.get_child("Reads"); int readNum = 1; BOOST_FOREACH(const eagle::io::ReadDescription &rd, runInfo_.reads) { ptree read; // Attributes for recent RunInfo.xml format read.put("<xmlattr>.Number", readNum++); read.put("<xmlattr>.IsIndexedRead", rd.isIndex?"Y":"N"); read.put("<xmlattr>.NumCycles", rd.lastCycle - rd.firstCycle + 1); // Attributes for older RunInfo.xml format read.put("<xmlattr>.FirstCycle", rd.firstCycle); read.put("<xmlattr>.LastCycle", rd.lastCycle); if (rd.isIndex) { read.put("Index", ""); } reads.add_child("Read", read); } const boost::property_tree::xml_writer_settings<string> w(' ', 2); const bfs::path runInfoPath = runFolderPath_ / "RunInfo.xml"; // DEBUG std::clog << "Writing RunInfo file " << runInfoPath.string() << std::endl; write_xml(runInfoPath.string(), pt, std::locale(), w); }
DistributedObject::DistributedObject(const bfs::path& file) : persistence_enabled_(false), path_(bfs::path()), file_(!path_.string().empty() && !file.string().empty() ? (path_ / file) : bfs::path()), timestamp_(0) { }
VideoAsset::VideoAsset(bfs::path videoFile, bfs::path path, bool copy) : path(path) { try { name = path.filename().string(); if(!bfs::exists(videoFile)) throw VideoAssetException("video File doesn't exist!"); if(!bfs::exists(path) || !bfs::is_directory(path)) throw VideoAssetException("Destination folder doesn't exist"); if(copy) { video_path = path; video_path /= videoFile.filename(); bfs::copy_file(videoFile, video_path, bfs::copy_option::overwrite_if_exists); } else video_path = videoFile; isExternal = !copy; loadPlayerSync(); writeInfoFile(); hasTimetable = false; hasShotBoundaries = false; hasHistograms = false; hasMeans = false; isReady = false; } catch (const bfs::filesystem_error& ex) { (*Tobago.log)(Log::ERROR) << "Error creating video asset " << path.string() << ": " << ex.what(); throw VideoAssetException(ex.what()); } }
void create_file(const bfs::path& ph, const string& contents) { ofstream f(ph.string().c_str()); if (!f) throw bfs::filesystem_error("create_file", ph, error_code(errno, SYSTEMCATEGORY)); if (!contents.empty()) f << contents; }
void testDefaultTabHandler(const bfs::path& datafile) { const char* alphabet = "abcd"; const char* numbers = "1234"; TabReader tr; VectorTabHandler vth; tr.setHandler(&vth); tr.process(datafile.string().c_str()); VectorTabHandler::const_iterator it = vth.begin(); cout << (* (*it).begin()) << endl; size_t y=0; for (; it != vth.end(); it++) { size_t x=0; for (vector<string>::const_iterator it2=(*it).begin(); it2!=(*it).end();it2++) { const char* value = (*it2).c_str(); unit_assert(value[0] == alphabet[x]); unit_assert(value[1] == numbers[y]); x++; } cerr << endl; y++; } }
PWIZ_API_DECL void expand_pathmask(const bfs::path& pathmask, vector<bfs::path>& matchingPaths) { using bfs::path; #ifdef WIN32 path maskParentPath = pathmask.branch_path(); WIN32_FIND_DATA fdata; HANDLE srcFile = FindFirstFileEx(pathmask.string().c_str(), FindExInfoStandard, &fdata, FindExSearchNameMatch, NULL, 0); if (srcFile == INVALID_HANDLE_VALUE) return; // no matches do { if (strcmp(fdata.cFileName, ".") != 0 && strcmp(fdata.cFileName, "..") != 0) matchingPaths.push_back( maskParentPath / fdata.cFileName ); } while (FindNextFile(srcFile, &fdata)); FindClose(srcFile); #else glob_t globbuf; int rv = glob(pathmask.string().c_str(), 0, NULL, &globbuf); if(rv > 0 && rv != GLOB_NOMATCH) throw runtime_error("FindFilesByMask(): glob() error"); DIR* curDir = opendir("."); struct stat curEntryData; for (size_t i=0; i < globbuf.gl_pathc; ++i) { stat(globbuf.gl_pathv[i], &curEntryData); if (S_ISDIR(curEntryData.st_mode) || S_ISREG(curEntryData.st_mode) || S_ISLNK(curEntryData.st_mode)) matchingPaths.push_back(globbuf.gl_pathv[i]); } closedir(curDir); globfree(&globbuf); #endif }
/** * @brief Returns file type. * * Determinates file type based on its name. */ condor2nav::TPathType condor2nav::PathType(const bfs::path &fileName) { std::string str{fileName.string()}; if(str.size() > 2 && str[0] == '\\' && str[1] != '\\') return TPathType::ACTIVE_SYNC; else return TPathType::LOCAL; }
void testMSIHandler(const bfs::path& datafile) { TabReader tr; MSIHandler mh; tr.setHandler(&mh); tr.process(datafile.string().c_str()); }
void WiiPlatform::ConvertSound(bfs::path filename, SoundResource *obj) { std::ostringstream cmd; cmd << this->GetName() << PLATFORM_PATH_SEPARATOR_STR << "sox "; cmd << filename.string().c_str() << " -b 16 "; cmd << obj->GetInputPath().string().c_str(); RUN_COMMAND(cmd); }
bfs::path request_new_project_path( bfs::path default_path ) { if( default_path.empty() ) default_path = path::DEFAULT_PROJECTS_DIR; return bfs::path( QFileDialog::getExistingDirectory( nullptr , QObject::tr("New AOS Designer Project Location") , QString::fromStdString( default_path.string() ) ).toStdString() ); }
void World::loadFromFile(const bfs::path & path, const Vec2f & posModifier) { Logger::get().debug("Загрузка объектов из файла %1%") % path.string(); json::Parser jparser; jparser.readFile(path.string()); const json::Object & jroot = jparser.getRoot(); // Local rect Rectf aabb = Rectf::fromJson(jroot.get("aabb")); // Entities for(const json::Object & jentity : jroot.get("entities").getArray()) { Entity * entity = Entity::fromJson(this, jentity); entity->getBody()->setPos( entity->getBody()->getPos() + Vec2f(-aabb.x + posModifier.x, -aabb.y + posModifier.y)); } }
bfs::path request_project_path( bfs::path default_path ) { if( default_path.empty() ) default_path = path::DEFAULT_PROJECTS_DIR; return bfs::path( QFileDialog::getOpenFileName( nullptr , QObject::tr( "Open AOS Designer Project" ) , QString::fromStdString( default_path.string() ) , QObject::tr( "AOS Designer Project (*.aosp)" ) ).toStdString() ); }
/** * @brief Checks if file exists in current directory * * Function checks if specified file exists. * * @param fileName File name to search for * * @return Check status */ bool condor2nav::FileExists(const bfs::path &fileName) { bool activeSync = false; const auto str = fileName.string(); if(str.size() > 2 && str[0] == '\\' && str[1] != '\\') activeSync = true; if(activeSync) return CActiveSync::Instance().FileExists(fileName); else return bfs::exists(fileName); }
void PointcloudPublisherNode::publish_pointcloud(const bfs::path &pointcloud_file_path) { pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2); if (pcl::io::loadPCDFile(pointcloud_file_path.string(), *cloud) == -1) { ROS_ERROR("Could not open %s", pointcloud_file_path.string().c_str()); return; } double frames_per_second = 0.0; sensor_msgs::PointCloud2 ros_output_cloud; pcl_conversions::fromPCL(*cloud, ros_output_cloud); std::string frame_id; if (nh_.getParam("frame_id", frame_id)) { ros_output_cloud.header.frame_id = frame_id; } if (!nh_.getParam("frames_per_second", frames_per_second)) { ros_output_cloud.header.stamp = ros::Time::now(); pointcloud_publisher_.publish(ros_output_cloud); ROS_INFO("Published pointcloud. Exiting"); ros::shutdown(); return; } ros::Rate loop_rate(frames_per_second); ROS_INFO("Going to publish pointcloud at %.2f fps", frames_per_second); while(ros::ok()) { ros_output_cloud.header.stamp = ros::Time::now(); pointcloud_publisher_.publish(ros_output_cloud); loop_rate.sleep(); } }
// Analysis routine void Crawler::analyse_image(const bfs::path& path) { std::ostringstream msg; msg << "Running image analysis on " << path; logger->message(msg.str(), traceLevel); // Construct and segment picture std::auto_ptr<ImageAnalyst> \ analyst(new ImageAnalyst(bfs::absolute(path.filename()), analyst_settings)); analyst->segment(); // Get centroids and dump to file if required if (settings.output) { std::ostringstream msg; msg << "Dumping segment centroids to " << settings.outputfile; logger->message(msg.str(), traceLevel); // Get segmentation window size blitz::TinyVector<int, 4> wsize = analyst->get_window_size(); // Open dumpfile as stream, add path, altered path and image and // window sizes std::fstream dumpFileStream; dumpFileStream.open(settings.outputfile.string().c_str(), std::fstream::out | std::fstream::app); dumpFileStream << "{'original_file': '" << path.string() << "', 'segmented_file': '" << path.stem() << "_segments" << bfs::extension(path) << "', 'image_size': (" << analyst->columns() << ", " << analyst->rows() << "), 'window_size': (" << wsize[0] << ", " << wsize[1] << ", " << wsize[2] << ", " << wsize[3] << "), "; // Get centroids, push to file std::vector<Index> centroids; analyst->get_centroids(centroids); dumpFileStream << "'centroids': ["; foreach(Index index, centroids) dumpFileStream << "(" << index[0] << "," << index[1] << "), "; dumpFileStream << "]}" << std::endl; // Clean up dumpFileStream.flush(); dumpFileStream.close(); } // Exit logger->message("Done!", traceLevel); }
ReadCameraParameter::ReadCameraParameter(boost::filesystem::path p){ ifstream camera; std::string ignore; double tmp ; BFS::path txt = p/ "camera.txt"; camera.open(txt.string().c_str()); if( !camera.is_open() ) cout << "Cannot open cameraParameter!" << endl; else cout << "Success!!!!" << endl; if( !camera.eof()){ for (int i = 0; i< 5; ++i) getline(camera, ignore, '\n'); // ignore words camera >> no_frame; // number of frames cout << "There are " << no_frame << " frames." << endl; getline(camera, ignore, '\n'); // ignore for(int s = 0; s < no_frame; s++){ // read camera_para of frames /* read matrix for K */ CvMat* k = cvCreateMat(3, 3, CV_64FC1); for(int i = 0; i < 9; i++){ camera >> tmp; cvmSet(k, (int) (i/3), i%3, tmp); //cout << i << " " << tmp[i] << endl; } K.push_back(k); /* read matrix for R */ CvMat* r = cvCreateMat(3, 3, CV_64FC1); for(int i = 0; i < 9; i++){ camera >> tmp; cvmSet(r, (int) (i/3), i%3, tmp); //cout << i << " " << tmp[i] << endl; } R.push_back(r); /* read matrix for T */ CvMat* t = cvCreateMat(3, 1, CV_64FC1); for(int i = 0; i < 3; i++){ camera >> tmp; cvmSet(t, i%3, 0, tmp); //cout << i << " " << tmp[i] << endl; } T.push_back(t); for (int i =0; i< 3; ++i) getline(camera, ignore, '\n'); // ignore } } camera.close(); }
void serve_init(const bfs::path& serve_path) { // Make sure the directory exists, or create it if(exists(serve_path)) { if(!is_directory(serve_path)) throw std::runtime_error(serve_path.string() + " already exists"); } else { create_directory(serve_path); } write_file(serve_path / "style.css", file_style_css, sizeof(file_style_css) - 1); write_file(serve_path / "logo.js", file_logo_js, sizeof(file_logo_js) - 1); }
void rotate_stores() { std::cout << "Rotating store " << store_file << "..." << std::endl; std::cout << "Rotating store call flush " << store_file << "..." << std::endl; fflush(stdout); try { store->flush(true); } catch (klio::StoreException const& ex) { std::cout << "Failed to flush the buffers : " << ex.what() << std::endl; } std::cout << "Rotating store flushed " << store_file << "..." << std::endl; fflush(stdout); std::cout << "Reopening store" << std::endl; const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); std::string s; s= str( format("%04d%02d%02d-%02d%02d") % now.date().year_month_day().year % now.date().year_month_day().month.as_number() % now.date().year_month_day().day.as_number() % now.time_of_day().hours() % now.time_of_day().minutes()); std::string name(store_file.string()); name+="."; name+=s; bfs::path dbname(name); std::cout << "===> renaming to: "<< name<<std::endl; fflush(stdout); try { store->rotate(dbname); } catch (klio::StoreException const& ex) { std::cout << "Failed to rotate the klio-databse : " << ex.what() << std::endl; } #if KLIO_AUTOCOMMIT store->start_transaction(); #endif std::cout << "Rotation done" << std::endl; }
VideoAsset::VideoAsset(bfs::path path) : path(path) { try { name = path.filename().string(); readInfoFile(); readTimetable(); readShotBoundaries(); readHistograms(); readMeans(); isReady = false; if(hasTimetable && hasShotBoundaries && hasHistograms && hasMeans) { if(frame2Timestamp.size() != histograms.size() || frame2Timestamp.size() != rgbMeans.size()) { throw VideoAssetException("Info files have wrong format."); } isReady = true; } loadPlayerSync(); } catch (const bfs::filesystem_error& ex) { (*Tobago.log)(Log::ERROR) << "Error loading video asset " << path.string() << ": " << ex.what(); throw VideoAssetException(ex.what()); } }
/** * @brief Creates specified directory * * Function creates given directory recursively. * * @param dirName Directory name to created. * * @exception std::runtime_error Operation did not succeed */ void condor2nav::DirectoryCreate(const bfs::path &dirName) { bool activeSync = false; const std::string str = dirName.string(); if(str.size() > 2 && str[0] == '\\' && str[1] != '\\') activeSync = true; if(!dirName.empty()) { if(!activeSync) { bfs::create_directories(dirName); } else { auto path = dirName; std::vector<bfs::path> dirs; while(path.parent_path() != "\\") { dirs.emplace_back(path); path = path.parent_path(); } auto &activeSync = CActiveSync::Instance(); std::for_each(dirs.crbegin(), dirs.crend(), [&](const bfs::path &d){ activeSync.DirectoryCreate(d); }); } } }
// load a Protein Data Bank file. Each line corresponds to a single atom bool ProteinComplex::LoadPDB2(bfs::path filename) { bfs::ifstream infile(filename); std::string current_line; if(!infile.is_open()) { std::cout << "File not found: " << filename.string() <<"\n"; return false; } while (!infile.eof()) { std::getline(infile, current_line); if (!infile.eof()) { if(current_line.substr(0, 4) == "ATOM") break; } } while (!infile.eof()) { if(current_line.substr(0, 4) == "ATOM") { AtomData current_atom; std::istringstream current_val(current_line.substr(6, 5)); current_val >> current_atom.atom_num; current_val.clear(); current_val.str(current_line.substr(12, 4)); current_val >> current_atom.atom_type; current_val.clear(); current_val.str(current_line.substr(17, 3)); current_val >> current_atom.residue_type; current_val.clear(); current_val.str(current_line.substr(21, 1)); current_val >> current_atom.chain_id; current_val.clear(); current_val.str(current_line.substr(22, 4)); current_val >> current_atom.residue_num; current_val.clear(); current_val.str(current_line.substr(30, 8)); current_val >> current_atom.x_cd; current_val.clear(); current_val.str(current_line.substr(38, 8)); current_val >> current_atom.y_cd; current_val.clear(); current_val.str(current_line.substr(46, 8)); current_val >> current_atom.z_cd; current_val.clear(); current_val.str(current_line.substr(54, 6)); current_val >> current_atom.occupancy; current_val.clear(); current_val.str(current_line.substr(60, 6)); current_val >> current_atom.temp_factor; current_val.clear(); current_val.str(current_line.substr(76, 2)); current_val >> current_atom.atom_element; current_val.clear(); InsertAtomData(current_atom); std::getline(infile, current_line); } else
basics::Persistable_blog basics::Persistor_blog::read_blog(bfs::path content_storage_file) { // Parsing content from file rapidxml::xml_document<> content; rapidxml::file<> content_file(content_storage_file.string().c_str()); // Retreiving root node content.parse<0>(content_file.data()); rapidxml::xml_node<> *blog_root = content.first_node("blog"); // Retreiving config rapidxml::xml_node<> *conf = blog_root->first_node("config"); basics::Configuration_blog config(nv(conf, "meta-desc"), nv(conf, "meta-author"), nv(conf, "meta-title"), nv(conf, "meta-conf-bootstrap"), nv(conf, "meta-conf-css"), nvs(conf, "nav-items"), nv(conf, "home-link"), nv(conf, "title"), nv(conf, "subtitle"), nv(conf, "about"), av(conf, "about", "line"), nvs(conf, "links"), av(conf, "links", "line"), nv(conf, "philosophy"), nv(conf, "backtotop"), std::stoi(nv(conf, "post-per-page"))); // Iterating over "post" nodes rapidxml::xml_node<> *post_node = blog_root->first_node("posts"); std::vector<basics::Post> posts; rapidxml::xml_node<> *post; for (post = post_node->first_node("post"); post; post = post->next_sibling("post")) { // Attributes std::string timestamp_str = post->first_attribute("date")->value(); std::string author = post->first_attribute("author")->value(); // title child node rapidxml::xml_node<> *title_node = post->first_node("title"); std::string title = title_node->value(); // mylife child node rapidxml::xml_node<> *life_node = post->first_node("mylife"); std::string life = basics::unescape_string(life_node->value()); // Reading editions rapidxml::xml_node<> *eds = post->first_node("editions"); std::vector<std::string> editions; rapidxml::xml_node<> *ed; for (ed = eds->first_node("edition"); ed; ed = ed->next_sibling("edition")) { std::string edition = ed->value(); editions.push_back(edition); } // Creating a new Post object from all infos basics::Post another_post(title, author, life, timestamp_str); another_post.set_editions(editions); posts.push_back(another_post); } basics::Persistable_blog blog_ptr(posts, config); return blog_ptr; }
void basics::Persistor_blog::write_blog(bfs::path content_storage_file, basics::Persistable_blog blog) { // Getting containers std::vector<basics::Post> posts = blog.posts(); basics::Configuration_blog config = blog.config(); // Declaration rapidxml::xml_document<> content; rapidxml::xml_node<> *decl = content.allocate_node(rapidxml::node_declaration); decl->append_attribute(content.allocate_attribute("version", "1.0")); decl->append_attribute(content.allocate_attribute("encoding", "utf-8")); content.append_node(decl); // Blog root <blog> rapidxml::xml_node<> *blog_root = content.allocate_node(rapidxml::node_element, "blog"); content.append_node(blog_root); // Configuration <config> rapidxml::xml_node<> *conf = content.allocate_node(rapidxml::node_element, "config"); blog_root->append_node(conf); wn(conf, "meta-desc", config.meta_desc_); wn(conf, "meta-author", config.meta_author_); wn(conf, "meta-title", config.meta_title_); wn(conf, "meta-conf-bootstrap", config.bootstrap_); wn(conf, "meta-conf-css", config.css_); wns(conf, "nav-items", "href", "item", config.menu_); wn(conf, "home-link", config.home_link_); wn(conf, "title", config.title_); wn(conf, "subtitle", config.subtitle_); wn(conf, "about", config.about_, "line", config.about_headline_); wns(conf, "links", "href", "item", config.links_, "line", config.links_headline_); wn(conf, "philosophy", config.philosophy_); wn(conf, "backtotop", config.back_to_top_); wn(conf, "post-per-page", std::to_string(config.post_per_page_)); // Post root <post prev="#" next="#"> rapidxml::xml_node<> *post_node = content.allocate_node(rapidxml::node_element, "posts"); rapidxml::xml_attribute<> *prev_attr = content.allocate_attribute("prev", "#"); post_node->append_attribute(prev_attr); rapidxml::xml_attribute<> *next_attr = content.allocate_attribute("next", "#"); post_node->append_attribute(next_attr); blog_root->append_node(post_node); for (std::vector<basics::Post>::iterator it = posts.begin(); it != posts.end(); ++it) { char *timestamp_str = content.allocate_string(it->get_timestamp_str().c_str()); char *author = content.allocate_string(it->get_author().c_str()); char *title = content.allocate_string(it->get_title().c_str()); std::string escaped_life = basics::escape_string(it->get_life()); char *life = content.allocate_string(escaped_life.c_str()); // Building new post node rapidxml::xml_node<> *another_post = content.allocate_node(rapidxml::node_element, "post"); rapidxml::xml_attribute<> *date_attr = content.allocate_attribute("date", timestamp_str); another_post->append_attribute(date_attr); rapidxml::xml_attribute<> *author_attr = content.allocate_attribute("author", author); another_post->append_attribute(author_attr); rapidxml::xml_node<> *title_child = content.allocate_node(rapidxml::node_element, "title", title); another_post->append_node(title_child); rapidxml::xml_node<> *mylife_child = content.allocate_node(rapidxml::node_element, "mylife", life); another_post->append_node(mylife_child); // Adding edition dates rapidxml::xml_node<> *eds_node = content.allocate_node(rapidxml::node_element, "editions"); std::vector<std::string> editions = it->editions(); for (std::vector<std::string>::iterator it = editions.begin(); it != editions.end(); ++it) { char *edition = content.allocate_string(it->c_str()); rapidxml::xml_node<> *ed_node = content.allocate_node(rapidxml::node_element, "edition", edition); eds_node->append_node(ed_node); } another_post->append_node(eds_node); // Adding node to post root post_node->append_node(another_post); } std::string content_string; rapidxml::print(std::back_inserter(content_string), content); std::ofstream content_output_stream(content_storage_file.string()); content_output_stream << content_string; content_output_stream.close(); }
void testIdpQonvert(const string& idpQonvertPath, const bfs::path& testDataPath) { // clean up existing intermediate files vector<bfs::path> intermediateFiles; pwiz::util::expand_pathmask(testDataPath / "*.idpDB", intermediateFiles); pwiz::util::expand_pathmask(testDataPath / "broken.pepXML", intermediateFiles); BOOST_FOREACH(const bfs::path& intermediateFile, intermediateFiles) bfs::remove(intermediateFile); vector<bfs::path> idFiles; pwiz::util::expand_pathmask(testDataPath / "*.pep.xml", idFiles); pwiz::util::expand_pathmask(testDataPath / "*.pepXML", idFiles); pwiz::util::expand_pathmask(testDataPath / "*.mzid", idFiles); pwiz::util::expand_pathmask(testDataPath / "*.dat", idFiles); if (idFiles.empty()) throw runtime_error("[testIdpQonvert] No identification files found in test path \"" + testDataPath.string() + "\""); // <idpQonvertPath> <matchPaths> string command = (format("%1%\"%2%\" \"%3%\" -DecoyPrefix \"\"%1%") % commandQuote % idpQonvertPath % bal::join(idFiles | boost::adaptors::transformed(path_stringer()), "\" \"")).str(); unit_assert_operator_equal(0, testCommand(command)); vector<bfs::path> idpDbFiles; BOOST_FOREACH(const bfs::path& idFile, idFiles) { idpDbFiles.push_back(idFile); string idpDbFilepath = bal::replace_all_copy(idpDbFiles.back().string(), ".pep.xml", ".pepXML"); idpDbFiles.back() = bfs::path(idpDbFilepath).replace_extension(".idpDB"); unit_assert(bfs::exists(idpDbFiles.back())); sqlite3pp::database db(idpDbFiles.back().string()); unit_assert_does_not_throw(sqlite3pp::query(db, "SELECT * FROM IntegerSet").begin(), sqlite3pp::database_error); // test analysis name differentiation string softwareName = sqlite3pp::query(db, "SELECT SoftwareName FROM Analysis").begin()->get<string>(0); string analysisName = sqlite3pp::query(db, "SELECT Name FROM Analysis").begin()->get<string>(0); if (softwareName == "MyriMatch") { unit_assert(bal::contains(analysisName, "MinTerminiCleavages")); if (bal::contains(analysisName, "MinTerminiCleavages=1")) unit_assert_operator_equal("MyriMatch 2.2.140 (MinTerminiCleavages=1, MonoPrecursorMzTolerance=50ppm, PrecursorMzToleranceRule=mono, parent tolerance minus value=50.0 ppm, parent tolerance plus value=50.0 ppm)", analysisName); else unit_assert_operator_equal("MyriMatch 2.2.140 (MinTerminiCleavages=0, MonoPrecursorMzTolerance=20ppm, PrecursorMzToleranceRule=auto, parent tolerance minus value=20.0 ppm, parent tolerance plus value=20.0 ppm)", analysisName); } else if (softwareName == "MS-GF+") { unit_assert(bal::contains(analysisName, "Instrument")); if (bal::contains(analysisName, "Instrument=LowRes")) unit_assert_operator_equal("MS-GF+ Beta (v10072) (FragmentMethod=As written in the spectrum or CID if no info, Instrument=LowRes, NumTolerableTermini=0, parent tolerance minus value=20.0 ppm, parent tolerance plus value=20.0 ppm)", analysisName); else unit_assert_operator_equal("MS-GF+ Beta (v10072) (FragmentMethod=HCD, Instrument=QExactive, NumTolerableTermini=1, parent tolerance minus value=50.0 ppm, parent tolerance plus value=50.0 ppm)", analysisName); } else if (softwareName == "Comet") { unit_assert(bal::contains(analysisName, "fragment_bin_tol")); if (bal::contains(analysisName, "fragment_bin_tol=1.000500")) unit_assert_operator_equal("Comet 2014.02 (fragment tolerance minus value=1.000500 u, fragment tolerance plus value=1.000500 u, fragment_bin_offset=0.400000, fragment_bin_tol=1.000500, theoretical_fragment_ions=1)", analysisName); else unit_assert_operator_equal("Comet 2014.02 (fragment tolerance minus value=0.020000 u, fragment tolerance plus value=0.020000 u, fragment_bin_offset=0.020000, fragment_bin_tol=0.020000, theoretical_fragment_ions=0)", analysisName); } else if (softwareName == "Mascot") { unit_assert(bal::contains(analysisName, "fragment tolerance minus value")); if (bal::contains(analysisName, "fragment tolerance minus value=0.6 u")) unit_assert_operator_equal("Mascot 2.2.06 (fragment tolerance minus value=0.6 u, fragment tolerance plus value=0.6 u, parent tolerance minus value=20.0 ppm, parent tolerance plus value=20.0 ppm)", analysisName); else unit_assert_operator_equal("Mascot 2.2.06 (fragment tolerance minus value=0.1 u, fragment tolerance plus value=0.1 u, parent tolerance minus value=50.0 ppm, parent tolerance plus value=50.0 ppm)", analysisName); } else throw runtime_error("[testIdpQonvert] Software name is not one of the expected values."); }
result_type operator()(const bfs::path& x) const { return x.string(); }
void RunFolderGenerator::generateConfig() const { using boost::property_tree::ptree; ptree pt; pt.put("BaseCallAnalysis.Run.<xmlattr>.Name", "BaseCalls"); ptree &run = pt.get_child("BaseCallAnalysis.Run"); run.put("Cycles.<xmlattr>.First", 1); const unsigned int length = runInfo_.getClusterLength(); run.put("Cycles.<xmlattr>.Last", length); run.put("Cycles.<xmlattr>.Length", length); run.put("BaseCallParameters", ""); ptree &baseCallParameters = run.get_child("BaseCallParameters"); run.put("RunParameters", ""); ptree &runParameters = run.get_child("RunParameters"); baseCallParameters.put("ChastityThreshold", 0.6); // This entry is only needed to keep the structure of the xml file such that copyConfig.pl doesn't "optimise" things and generate a broken output file unsigned int r = 0; BOOST_FOREACH(const eagle::io::ReadDescription &rd, runInfo_.reads) { r++; ptree matrix; matrix.put("Read", r); matrix.put("AutoFlag", 2); matrix.put("AutoLane", 0); matrix.put("FirstCycle", rd.firstCycle); matrix.put("LastCycle", rd.lastCycle); ptree phasing = matrix; matrix.put("CycleOffset", 0); matrix.put("Cycle", rd.firstCycle); phasing.put("CycleOffset", 1); phasing.put("Cycle", rd.firstCycle + 1); phasing.put("PhasingRate", 0.02 + r / 100.0); phasing.put("PrephasingRate", 0.03 + r / 100.0); baseCallParameters.add_child("Matrix", matrix); baseCallParameters.add_child("Phasing", phasing); ptree reads; reads.put("<xmlattr>.Index", r); reads.put("FirstCycle", rd.firstCycle); reads.put("LastCycle", rd.lastCycle); runParameters.add_child("Reads", reads); } runParameters.put("Instrument", instrument_); runParameters.put("RunFolder", runFolder_); runParameters.put("RunFolderDate", runFolderDate_); runParameters.put("RunFolderId", runFolderId_); run.put("Software", ""); run.put("Software.<xmlattr>.Name", "RTA"); run.put("Software.<xmlattr>.Version", "1.9.35.0"); run.put("TileSelection", ""); ptree &tileSelection = run.get_child("TileSelection"); for (unsigned int l = 1; runInfo_.laneCount >= l; ++l) { ptree lane; lane.put("<xmlattr>.Index", l); lane.put("Sample", 's'); unsigned int tilesPerLane = runInfo_.tileCount * runInfo_.surfaceCount * runInfo_.swathCount; assert( tilesPerLane == options_.tileId.size() ); for (unsigned int t = 0; t < tilesPerLane; ++t) { lane.add("Tile", options_.tileId[t]); } tileSelection.add_child("Lane", lane); } const boost::property_tree::xml_writer_settings<string> w(' ', 2); const bfs::path configPath = baseCallsPath_ / "config.xml"; // DEBUG std::clog << "Writing config file " << configPath.string() << std::endl; write_xml(configPath.string(), pt, std::locale(), w); }