Exemplo n.º 1
0
///////////////////////////////////////////////////////
///
/// Read a string from a stream. The string is following
/// by its size
///
inline string ReadStringFromStream(CNcbiIstream& is)
{
    string str;
    if (!is.good() || is.eof())
        return str;

    size_t size;
    is >> size;
    if (!is.good() || is.eof())
        return str;
    vector<char> buf(size+1, 0);
    is.read(&*buf.begin(), size+1);
    size_t count = is.gcount();
    if (count > 0)
        str.append((&*buf.begin())+1, count-1);

    return str;
}
Exemplo n.º 2
0
 /**
  **\brief Object constructor.
  **
  **\param newInputStream input stream to read data from.
  **\param is_nucl true if the input is DNA, false if it is protein
  **\param parse_seqids false to disable parsing of deflines
  **
  **/
 CMaskFastaReader( CNcbiIstream & newInputStream, bool is_nucl = true,
                   bool parse_seqids = false )
     : CMaskReader( newInputStream ), is_nucleotide_(is_nucl),
       parse_seqids_(parse_seqids), 
       fasta_reader_( newInputStream,
                      CONST_FLAGS | 
                      (is_nucl ? objects::CFastaReader::fAssumeNuc 
                               : objects::CFastaReader::fAssumeProt) |
                      (parse_seqids ? 0 
                                    : objects::CFastaReader::fNoParseID) )
 {
     if( !newInputStream && !newInputStream.eof() ) {
         NCBI_THROW( Exception, eBadStream, 
                 "bad stream state at fasta mask reader initialization" );
     }
 }
Exemplo n.º 3
0
// Helper function for loading alignments. Returns number of alignments loaded
// into the container. The expected format is:
// <int-number-of-alignments>
// <Seq-align>+
size_t LoadAligns(CNcbiIstream& in,
                  CAlnContainer& aligns,
                  size_t limit = 0)
{
    size_t num_aligns = 0;
    while ( !in.eof() ) {
        try {
            CRef<CSeq_align> align(new CSeq_align);
            in >> MSerial_AsnText >> *align;
            align->Validate(true);
            aligns.insert(*align);
            num_aligns++;
            if (limit > 0  &&  num_aligns >= limit) break;
        }
        catch (CIOException e) {
            break;
        }
    }
    return num_aligns;
}
Exemplo n.º 4
0
//  ----------------------------------------------------------------------------
void CMultiReaderApp::xProcessNewick(
    const CArgs& args,
    CNcbiIstream& istr,
    CNcbiOstream& ostr)
//  ----------------------------------------------------------------------------
{
    string strTree;
    char c = istr.get();
    while (!istr.eof()) {
        strTree += c;
        if (c == ';') {
            CNcbiIstrstream istrstr(strTree.c_str());
            auto_ptr<TPhyTreeNode>  pTree(ReadNewickTree(istrstr) );
            CRef<CBioTreeContainer> btc = MakeBioTreeContainer(pTree.get());
            xWriteObject(*btc, ostr);
            strTree.clear();
        }
        c = istr.get();
    }
}