Ejemplo n.º 1
0
bool CBasicFastaWrapper::ReadFile(CNcbiIstream& iStream) 
{
    bool result = (iStream.good());

    if (!result) {
        m_error = "Read Error:  invalid stream.\n";
    } else {

        CNcbiOstrstream oss;
        oss << iStream.rdbuf();
        iStream.seekg(0);  

        m_activeFastaString = CNcbiOstrstreamToString(oss);
        if (m_cacheRawFasta) m_rawFastaString = m_activeFastaString;

        //  temporarily turn off warning messages (in case of '.' in *.a2m files)
        EDiagSev originalDiagSev = SetDiagPostLevel(eDiag_Error);  

	    try{
            CStreamLineReader lineReader(iStream);
            CFastaReader fastaReader(lineReader, m_readFastaFlags);
            //CCounterManager counterMgr(reader.SetIDGenerator(), NULL);
            m_seqEntry = fastaReader.ReadSet();

            //  If there is only one sequence in the fasta, the Seq-entry returned is a Bioseq and not a Bioseq-set.
            //  In that case, change the Bioseq to a Bioseq-set so caller doesn't have to manage multiple Seq-entry choices.
            if (m_seqEntry->IsSeq() && m_useBioseqSet) {
                CRef<CSeq_entry> bioseqFromFasta(new CSeq_entry);
                bioseqFromFasta->Assign(*m_seqEntry);

                m_seqEntry->Select(CSeq_entry::e_Set);
                m_seqEntry->SetSet().SetSeq_set().push_back(bioseqFromFasta);
            }

	    } catch (...) {
            result = false;
            m_seqEntry.Reset();
        }

        if (m_seqEntry.Empty()) {
            result = false;
            m_error = "Read Error:  empty seq entry.\n";
        }
        SetDiagPostLevel(originalDiagSev);

    }
    return result;
}
Ejemplo n.º 2
0
void CAlnMrgApp::LoadSeqEntry(CNcbiIstream& is)
{
    string se_asn_type;
    {{
         auto_ptr<CObjectIStream> obj_is
             (CObjectIStream::Open(eSerial_AsnText, is));
         
         se_asn_type = obj_is->ReadFileHeader();
         obj_is->Close();
         is.seekg(0);
    }}
        
    auto_ptr<CObjectIStream> obj_is
        (CObjectIStream::Open(eSerial_AsnText, is));
    
    if (se_asn_type == "Seq-entry") {
        CRef<CSeq_entry> se (new CSeq_entry);
        *obj_is >> *se;
        GetScope().AddTopLevelSeqEntry(*se);
    } else {