예제 #1
0
// put contigs from contfile into contlist
void Contiglist::add_contigs( std::string contigsfiles ){
  std::stringstream ss;
  ss.str( contigsfiles );
  std::string filename;
  std::string buffer("");
  std::string line("");
  std::string contig_id("");

  while( getline( ss, filename, ',' )){
    Log::Inst()->log_it( "contigsfile: " + filename );

    // open contig file
    std::ifstream cont( filename );

    // read in contig objects
    while( getline( cont, line ) ){
      if( line[0] == '>' && buffer.length() != 0 ){
        if( buffer.length() > 2*initial_trim + contig_sub_len ){
          buffer = buffer.substr( initial_trim, buffer.length() - 2*initial_trim );
          contigs.push_back( Contig( reads, buffer, contig_id ));
          if( verbose ){
            Log::Inst()->log_it( "Added contig: " + contig_id );
          }
        }
        else if( buffer.length() > contig_sub_len ){
          int trim = (buffer.length() - contig_sub_len) / 2;
          buffer = buffer.substr( trim, buffer.length() - 2*trim );
          contigs.push_back( Contig( reads, buffer, contig_id ));
          if( verbose ){
            Log::Inst()->log_it( "Added contig: " + contig_id );
          }
        }

        buffer = "";
        contig_id = line.substr(1);
      }
      else if ( line[0] == '>' ){
        contig_id = line.substr(1);
      }
      else{
        buffer += line;
      }
    }

    // close contig file
    cont.close();
  }

  // insert last line into contigs list
  if( buffer.length() != 0 ){
    contigs.push_back( Contig( reads, buffer, contig_id ) );
  }
}
예제 #2
0
//JEREMIAH
bool SGVisitorContig::visit(StringGraph* /*pGraph*/, Vertex* pVertex)
{
  
  //m_ct.push_back(Contig(pVertex->getID(), pVertex->getParentID(), pVertex->getSeq().toString(), 
  //	  pVertex->getSeq().length()));
  m_ct.push_back(Contig(pVertex->getID(), pVertex->getSeq().toString()));
  return false;
}
예제 #3
0
Contig
read_contig(const std::string& filename,
            const std::string& name)
{
  SeqType sequence=read_fasta(filename,name);

  return Contig(name,sequence);
}
예제 #4
0
Contig
read_contig(const std::string& fasta_filename,
            const std::string& quality_filename, const std::string& name)
{
  SeqType sequence=read_fasta(fasta_filename,name);
  QualSeqType quality=read_quality(quality_filename,name);

  return Contig(name,sequence,quality);
}
예제 #5
0
int CopyNumEstimator::run(const Properties& options, const Arguments& arguments) {
    int r = 0;

    if ((r = checkOptions(options)) != 0) {
        return r;
    }

    double lambda = options.get< double >("lambda");

    LOG4CXX_DEBUG(logger, "copy_num_estimator begin");

    ContigList contigs;
    // read contigs
    {
        std::istream* is = &std::cin;
        if (options.find("i") != options.not_found()) {
            std::string file = options.get< std::string >("i");
            is = new std::ifstream(file.c_str());
        }
        if (is == &std::cin) {
            std::cin.sync_with_stdio(false);
        }

        size_t edge_num = 0;
        CondensedDeBruijnGraphReader reader(*is);
        CondensedDeBruijnGraphEdge edge;
        while (reader.read(edge)) {
            int copy_num = (int)std::round(edge.coverage / lambda);
            if (copy_num >= 0) {
                contigs.push_back(Contig(edge.seq, copy_num));
            }
            ++edge_num;
        }

        LOG4CXX_DEBUG(logger, boost::format("Number of condensed edges = %d") % edge_num);
        LOG4CXX_DEBUG(logger, boost::format("Number of Contigs = %d") % contigs.size());

        if (is != &std::cin) {
            delete is;
        }
    }
    // write contigs
    {
        std::string file = options.get< std::string >("G");
        if (!WriteContigs(file, contigs)) {
            return 1;
        }
    }
    // write components
    {
        std::string file = options.get< std::string >("C");
        std::ofstream stream(file.c_str());
        if (!stream) {
            return 1;
        }

        size_t contig_idx = 0, component_idx = 0;
        BOOST_FOREACH(const Contig& contig, contigs) {
            if (contig.copy_num <= 1) {
                stream << boost::format(">component\t%d\n%d\n\n") % component_idx % contig_idx;
                ++component_idx;
            }
            ++contig_idx;
        }

        LOG4CXX_DEBUG(logger, boost::format("Number of Uniques = %d") % component_idx);
    }

    LOG4CXX_DEBUG(logger, "copy_num_estimator end");
    return r;
}