bool GenomicRegionCollection<T>::ReadVCF(const std::string & file, const BamHeader& hdr) {

  m_sorted = false;
  idx = 0;

  gzFile fp = NULL;
  fp = strcmp(file.c_str(), "-")? gzopen(file.c_str(), "r") : gzdopen(fileno(stdin), "r");
  
  if (file.empty() || !fp) {
    std::cerr << "VCF file not readable: " << file << std::endl;
    return false;
  }

  // http://www.lemoda.net/c/gzfile-read/
  while (1) {

    int err;                    
    char buffer[GZBUFFER];
    gzgets(fp, buffer, GZBUFFER);
    int bytes_read = strlen(buffer);

    // get one line
    if (bytes_read < GZBUFFER - 1) {
      if (gzeof (fp)) break;
      else {
	const char * error_string;
	error_string = gzerror (fp, &err);
	if (err) {
	  fprintf (stderr, "Error: %s.\n", error_string);
	  exit (EXIT_FAILURE);
	}
      }
    }

    // prepare to loop through each field of BED line
    std::string chr, pos;
    std::string line(buffer);
    std::istringstream iss_line(line);
    std::string val;
    if (line.empty() || line.at(0) == '#')
      continue;

    // read first two columnes
    iss_line >> chr >> pos;

    // construct the GenomicRegion
    T gr;
    try {
      gr = T(chr, pos, pos, hdr);
    } catch (...) {
      std::cerr << "...Could not parse pos: " << pos << std::endl << std::endl
		<< "...on line " << line << std::endl;
      
    }
    if (gr.chr >= 0) 
      m_grv->push_back(gr);
  }

  return true;
}
bool GenomicRegionCollection<T>::ReadBED(const std::string & file, const BamHeader& hdr) {

  m_sorted = false;
  idx = 0;

  gzFile fp = NULL;
  fp = strcmp(file.c_str(), "-")? gzopen(file.c_str(), "r") : gzdopen(fileno(stdin), "r");

  if (file.empty() || !fp) {
    std::cerr << "BED file not readable: " << file << std::endl;
    return false;
  }

  // http://www.lemoda.net/c/gzfile-read/
  while (1) {

    int err;                    
    char buffer[GZBUFFER];
    gzgets(fp, buffer, GZBUFFER);
    int bytes_read = strlen(buffer);

    // get one line
    if (bytes_read < GZBUFFER - 1) {
      if (gzeof (fp)) break;
      else {
	const char * error_string;
	error_string = gzerror (fp, &err);
	if (err) {
	  fprintf (stderr, "Error: %s.\n", error_string);
	  exit (EXIT_FAILURE);
	}
      }
    }

    // prepare to loop through each field of BED line
    //size_t counter = 0;
    std::string chr, pos1, pos2;
    std::string line(buffer);
    std::istringstream iss_line(line);
    std::string val;
    if (line.find("#") != std::string::npos) 
      continue;
    
    // read first three BED columns
    iss_line >> chr >> pos1 >> pos2;

    // construct the GenomicRegion
    T gr(chr, pos1, pos2, hdr);
    
    if (gr.chr >= 0)
      m_grv->push_back(gr);
  }

  return true;
}
Пример #3
0
name_value_pairs::name_value_pairs(std::string const& filename)
{
    std::ifstream is(filename.c_str());
    std::string line;
    while(std::getline(is, line))
        {
        std::istringstream iss_line(line);
        if(std::string::npos == line.find_first_of('='))
            {
            continue;
            }

        std::string name;
        std::getline(iss_line, name, '=');
        std::string value;
        std::getline(iss_line, value);
        map_[name] = value;
        }
}
Пример #4
0
/**
 * \brief Initialise the item.
 */
void bear::rolling_credits::build()
{
  super::build();

  std::stringstream iss;

  engine::resource_pool::get_instance().get_file(m_file, iss);
  if ( m_fading_frac < 0 )
    m_fading_frac = 1.0 / 4;
  else
    // initially, m_fading_frac contains the duration of the fading
    m_fading_frac /= m_movement_duration;

  std::string line;
  visual::font font;
  double font_size(12);
  double red(1), green(1), blue(1), opacity(1);
  visual::text_align::horizontal_align horizontal_align
    ( visual::text_align::align_center );
  visual::size_type width( get_width() );

  while ( claw::text::getline(iss, line) )
    if ( line.empty() )
      m_lines.push_back
        ( credit_line
          ( line, font, red, green, blue, opacity,  get_bottom_left(), width,
            horizontal_align ) );
    else if ( line[0] == '#' )
      {
        std::string s;
        std::istringstream iss_line(line);
        iss_line >> s;

        if ( s == "#color" )
          {
            red = green = blue = opacity = 1;
            iss_line >> red >> green >> blue >> opacity;
          }