bool analyzeSimpleParseFile(const char* file_path, 
	std::map<std::string,std::vector<Array<int,4>>>& p_samples)
{
	std::ifstream in_file_stream(file_path);
	if (!in_file_stream)
	{
		EAGLEEYE_ERROR("couldn't parse training samples file\n");
		return false;
	}

	while(in_file_stream.peek()!=EOF)
	{
		std::string label_name;
		in_file_stream>>label_name;
		if (in_file_stream.peek() == EOF)
		{
			//find there is no data to read, we have to exit
			break;
		}

		if (label_name == "P")
		{
			std::string file_name;
			in_file_stream>>file_name;

			Array<int,4> pos;
			in_file_stream>>pos[0];
			in_file_stream>>pos[1];
			in_file_stream>>pos[2];
			in_file_stream>>pos[3];

			p_samples[file_name].push_back(pos);
		}
		else
		{
Exemple #2
0
// Helper function to read CSV files into 'matrix' of strings.
static StringMatrix loadCSV(std::string file_name) {
  // Open file stream and check that it is error free.
  std::ifstream in_file_stream(file_name.c_str());
  CHECK(in_file_stream.good()) << "error opening input file " << file_name;
  StringMatrix string_matrix;
  // Loop over lines (rows) of CSV file.
  std::string line;
  while(std::getline(in_file_stream, line)) {
    std::istringstream ss(line);
    StringRow str_row;
    // Loop over comma separated fields of CSV line.
    std::string field;
    while (getline(ss, field,',')) {
      str_row.push_back(field);
    }
    string_matrix.push_back(str_row);
  }
  in_file_stream.close();
  return string_matrix;
}
      processors::GetFile::Directory.getName(), in_dir);
  plan->setProperty(
      get_file,
      processors::GetFile::KeepSourceFile.getName(),
      "true");
  plan->addProcessor(
      "LogAttribute",
      "Log",
      core::Relationship("success", "description"),
      true);

  // Write test input
  REQUIRE(0 == mkfifo(in_file.c_str(), 0777));

  // Run test flow
  std::thread write_thread([&] {
    std::ofstream in_file_stream(in_file);
    in_file_stream << "The quick brown fox jumps over the lazy dog" << std::endl;
  });

  plan->runNextProcessor();  // Get
  plan->runNextProcessor();  // Log

  write_thread.join();

  // Check log output
  REQUIRE(LogTestController::getInstance().contains("key:flow.id"));
  REQUIRE(LogTestController::getInstance().contains("Size:44 Offset:0"));
}

Exemple #4
0
int StatTool::processInputFile(const char * inputFile)
{
    try {
        crispr::xml::reader xml_parser;
        std::ifstream in_file_stream(inputFile);
        if (in_file_stream.good()) {
            in_file_stream.close();
        } else {
            throw crispr::input_exception("cannot open input file");
        }
        xercesc::DOMDocument * input_doc_obj = xml_parser.setFileParser(inputFile);
        xercesc::DOMElement * root_elem = input_doc_obj->getDocumentElement();
        if (!root_elem) {
            throw crispr::xml_exception(__FILE__, 
                                        __LINE__, 
                                        __PRETTY_FUNCTION__, 
                                        "problem when parsing xml file");
        }
        int num_groups_to_process = static_cast<int>(ST_Groups.size());
        //std::cout<<num_groups_to_process<<std::endl;
        for (xercesc::DOMElement * currentElement = root_elem->getFirstElementChild();
             currentElement != NULL; 
             currentElement = currentElement->getNextElementSibling()) {

            if (ST_Subset && num_groups_to_process == 0) {
                break;
            }
            // is this a group element
            if (xercesc::XMLString::equals(currentElement->getTagName(), xml_parser.tag_Group())) {
                char * c_gid = tc(currentElement->getAttribute(xml_parser.attr_Gid()));
                std::string group_id = c_gid;
                if (ST_Subset) {
                    // we only want some of the groups look at DT_Groups
                    if (ST_Groups.find(group_id.substr(1)) != ST_Groups.end() ) {
                        parseGroup(currentElement, xml_parser);

                        // decrease the number of groups left
                        // if we are only using a subset
                        if(ST_Subset) num_groups_to_process--;
                    }
                } else {
                    parseGroup(currentElement, xml_parser);   
                }
                xr(&c_gid);
            }
        }
        AStats agregate_stats;
        agregate_stats.total_groups = 0;
        agregate_stats.total_spacers = 0;
        agregate_stats.total_dr = 0;
        agregate_stats.total_flanker = 0;
        agregate_stats.total_spacer_length = 0;
        agregate_stats.total_spacer_cov = 0;
        agregate_stats.total_dr_length = 0;
        agregate_stats.total_flanker_length = 0;
        agregate_stats.total_reads = 0;
        // go through each of the groups and print out a pretty picture
        std::vector<StatManager *>::iterator iter = this->begin();
        int longest_consensus = 0;
        int longest_gid = 0;
        if (ST_OutputStyle == veryPretty) {
            while (iter != this->end()) {
                if(static_cast<int>((*iter)->getConcensus().length()) > longest_consensus) {
                    longest_consensus = static_cast<int>((*iter)->getConcensus().length());
                }
                if (static_cast<int>((*iter)->getGid().length()) > longest_gid) {
                    longest_gid = static_cast<int>((*iter)->getGid().length());
                }
            }
            iter = this->begin();
        }
        
        while (iter != this->end()) {
            switch (ST_OutputStyle) {
                case tabular:
                    printTabular(*iter);
                    break;
                case pretty:
                    prettyPrint(*iter);
                    break;
                case veryPretty:
                    veryPrettyPrint(*iter, longest_consensus, longest_gid);
                    break;
                case coverage:
                    printCoverage(*iter);
                    break;
                default:
                    break;
            }
            iter++;
        }
        if (ST_AggregateStats) {
            calculateAgregateSTats(&agregate_stats);
            printAggregate(&agregate_stats);
        }
    } catch (xercesc::DOMException& e ) {
        char * c_msg = tc(e.getMessage());
        std::cerr<<c_msg<<std::endl;
        xr(&c_msg);
        return 1;
    }  catch (crispr::exception& e) {
        std::cerr<<e.what()<<std::endl;
        return 1;
    }
    return 0;
}