コード例 #1
0
    void x_LoadSequences(const string& filename, bool parse_id)
    {
        CNcbiIfstream instream(filename.c_str());
        BOOST_REQUIRE(instream);

        CStreamLineReader line_reader(instream);
        CFastaReader::TFlags flags = 0;
        if (!parse_id) {
            flags |= CFastaReader::fNoParseID;
        }

        CFastaReader fasta_reader(line_reader, flags);
        fasta_reader.IgnoreProblem(
                          ILineError::eProblem_ModifierFoundButNoneExpected);
        while (!line_reader.AtEOF()) {

            CRef<CSeq_entry> entry = fasta_reader.ReadOneSeq();

            if (entry == 0) {
                NCBI_THROW(CObjReaderException, eInvalid, 
                           "Could not retrieve seq entry");
            }
            m_Scope->AddTopLevelSeqEntry(*entry);
            CTypeConstIterator<CBioseq> itr(ConstBegin(*entry));
        }
    }
コード例 #2
0
ファイル: asn2fasta.cpp プロジェクト: jackgopack4/pico-blast
//  --------------------------------------------------------------------------
bool CAsn2FastaApp::HandleSeqEntry(CRef<CSeq_entry>& se)
//  --------------------------------------------------------------------------
{
    CSeq_entry_Handle seh = m_Scope->AddTopLevelSeqEntry(*se);
    bool ret = HandleSeqEntry(seh);
    m_Scope->RemoveTopLevelSeqEntry(seh);
    return ret;
}
コード例 #3
0
ファイル: asn2fasta.cpp プロジェクト: jackgopack4/pico-blast
//  --------------------------------------------------------------------------
CSeq_entry_Handle CAsn2FastaApp::ObtainSeqEntryFromBioseqSet(
    CObjectIStream& is)
//  --------------------------------------------------------------------------
{
    try {
        CRef<CSeq_entry> entry(new CSeq_entry);
        is >> entry->SetSet();
        return m_Scope->AddTopLevelSeqEntry(*entry);
    }
    catch (CException& e) {
        if (! (is.GetFailFlags() & is.eEOF)) {
            ERR_POST(Error << e);
        }
    }
    return CSeq_entry_Handle();
}
コード例 #4
0
int ReadFastaQueries(const string& filename,
                      vector< CRef<objects::CSeq_loc> >& seqs,
                      CRef<objects::CScope>& scope,
                      bool parse_deflines /* = false*/,
                      objects::CSeqIdGenerator* id_generator /* = NULL*/)
{
    seqs.clear();
    CNcbiIfstream instream(filename.c_str());
    if (!instream) {
        return -1;
    }

    CStreamLineReader line_reader(instream);
    CFastaReader::TFlags flags =  CFastaReader::fAssumeProt |
        CFastaReader::fForceType;
    
    if (!parse_deflines) {
        flags |= CFastaReader::fNoParseID;
    }

    CFastaReader fasta_reader(line_reader, flags);

    if (id_generator) {
        fasta_reader.SetIDGenerator(*id_generator);
    }

    scope->AddDefaults();
    while (!line_reader.AtEOF()) {

        CRef<CSeq_entry> entry = fasta_reader.ReadOneSeq();

        if (entry == 0) {
            return -1;
        }
        scope->AddTopLevelSeqEntry(*entry);
        CTypeConstIterator<CBioseq> itr(ConstBegin(*entry));
        CRef<CSeq_loc> seqloc(new CSeq_loc());
        seqloc->SetWhole().Assign(*itr->GetId().front());
        seqs.push_back(seqloc);
    }

    return 0;
}
コード例 #5
0
int ReadMsa(const string& filename, CRef<CSeq_align>& align,
            CRef<CScope> scope, bool parse_deflines /* = false*/,
            objects::CSeqIdGenerator* id_generator /* = NULL*/)
{
    if (scope.Empty()) {
        return -1;
    }

    CNcbiIfstream instream(filename.c_str());
    if (!instream) {
        return -1;
    }
    CStreamLineReader line_reader(instream);

    CFastaReader::TFlags flags =  CFastaReader::fAssumeProt |
        CFastaReader::fForceType | CFastaReader::fValidate;
    
    if (!parse_deflines) {
        flags |= CFastaReader::fNoParseID;
    }

    CFastaReader fasta_reader(line_reader, flags);

    if (id_generator) {
        fasta_reader.SetIDGenerator(*id_generator);
    }

    CRef<CSeq_entry> entry = fasta_reader.ReadAlignedSet(-1);
    if (entry.Empty()) {
        return -1;
    }
    scope->AddTopLevelSeqEntry(*entry);

    // notify of a problem if the whole file was not read
    if (!line_reader.AtEOF()) {
        return -1;
    }

    align = entry->GetAnnot().front()->GetData().GetAlign().front();

    return 0;
}
コード例 #6
0
ファイル: asn2fasta.cpp プロジェクト: jackgopack4/pico-blast
//  --------------------------------------------------------------------------
CSeq_entry_Handle CAsn2FastaApp::ObtainSeqEntryFromSeqEntry(
    CObjectIStream& is)
//  --------------------------------------------------------------------------
{
    try {
        CRef<CSeq_entry> se(new CSeq_entry);
        is >> *se;
        if (se->Which() == CSeq_entry::e_not_set) {
            NCBI_THROW(CException, eUnknown,
                       "provided Seq-entry is empty");
        }
        return m_Scope->AddTopLevelSeqEntry(*se);
    }
    catch (CException& e) {
        if (! (is.GetFailFlags() & is.eEOF)) {
            ERR_POST(Error << e);
        }
    }
    return CSeq_entry_Handle();
}