예제 #1
0
int CSeq_id_Handle::CompareOrdered(const CSeq_id_Handle& id) const
{
    // small optimization to avoid creation of temporary CSeq_id objects
    if ( int diff = Which() - id.Which() ) {
        return diff;
    }
    if ( IsGi() && id.IsGi() ) {
        return GetGi() - id.GetGi();
    }
    return GetSeqId()->CompareOrdered(*id.GetSeqId());
}
예제 #2
0
static TReadId sx_GetReadId(const CSeq_id_Handle& idh)
{
    if ( idh.Which() != CSeq_id::e_General ) {
        return TReadId();
    }
    CConstRef<CSeq_id> id = idh.GetSeqId();
    const CDbtag& general = id->GetGeneral();
    if ( general.GetDb() != "SRA") {
        return TReadId();
    }
    return sx_GetReadId(general.GetTag().GetStr(), true);
}
예제 #3
0
int 
CLocalBlastDbAdapter::GetTaxId(const CSeq_id_Handle& idh)
{
    int retval = static_cast<int>(kInvalidSeqPos);
    CConstRef<CSeq_id> id = idh.GetSeqId();
    if (id.NotEmpty()) {
        int oid = 0;
        if (SeqidToOid(*id, oid)) {
            map<int, int> gi_to_taxid;
            m_SeqDB->GetTaxIDs(oid, gi_to_taxid);
            if (idh.IsGi()) {
                retval = gi_to_taxid[GI_TO(int, idh.GetGi())];
            } else {
예제 #4
0
Uint4 GetSequenceType(const CBioseq_Handle& bsh)
{
    if (bsh.IsAa()) {
        return CSeq_id::fAcc_prot;
    }

    const CMolInfo* info = sequence::GetMolInfo(bsh);
    if (info) {
        if (info->GetBiomol() == CMolInfo::eBiomol_mRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_pre_RNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_tRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_snRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_scRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_cRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_snoRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_ncRNA  ||
            info->GetBiomol() == CMolInfo::eBiomol_tmRNA) {
            return (CSeq_id::fAcc_nuc | CSeq_id::eAcc_mrna);
        }

        if (info->GetBiomol() == CMolInfo::eBiomol_genomic) {
            return (CSeq_id::fAcc_nuc | CSeq_id::fAcc_genomic);
        }
    }

    CSeq_id_Handle idh = sequence::GetId(*bsh.GetSeqId(), bsh.GetScope(),
                                         sequence::eGetId_Best);
    CSeq_id::EAccessionInfo id_info = idh.GetSeqId()->IdentifyAccession();

    if ((id_info & CSeq_id::eAcc_division_mask) == CSeq_id::eAcc_est  ||
        id_info == CSeq_id::eAcc_refseq_mrna  ||
        id_info == CSeq_id::eAcc_refseq_mrna_predicted  ||
        id_info == CSeq_id::eAcc_gpipe_mrna) {
        return (CSeq_id::fAcc_nuc | CSeq_id::eAcc_mrna);
    }
    if (id_info == CSeq_id::eAcc_refseq_chromosome  ||
        id_info == CSeq_id::eAcc_refseq_contig  ||
        id_info == CSeq_id::eAcc_refseq_genomic  ||
        id_info == CSeq_id::eAcc_refseq_genome  ||
        id_info == CSeq_id::eAcc_refseq_wgs_intermed) {
        return (CSeq_id::fAcc_nuc | CSeq_id::fAcc_genomic);
    }

    return (CSeq_id::eAcc_unknown);
}
예제 #5
0
    //----------------------------------------------------------------
void CEditsSaver::AddId(const CBioseq_Handle& handle, 
                        const CSeq_id_Handle& id, 
                        ECallMode mode)
{
    
    CRef<CSeqEdit_Cmd> cmd;
    SCmdCreator<CSeqEdit_Cmd::e_Add_id>::CreateCmd(handle,cmd).
        SetAdd_id(const_cast<CSeq_id&>(*id.GetSeqId()));
    GetDBEngine().SaveCommand(*cmd); 
    GetDBEngine().NotifyIdChanged(id, cmd->GetBlobId());
}
예제 #6
0
void CEditsSaver::RemoveId(const CBioseq_Handle& handle, 
                                const CSeq_id_Handle& id, 
                                ECallMode mode)
{
    CRef<CSeqEdit_Cmd> cmd;
    SCmdCreator<CSeqEdit_Cmd::e_Remove_id>::CreateCmd(handle,
                                                      CBioObjectId(id),
                                                      cmd).
        SetRemove_id(const_cast<CSeq_id&>(*id.GetSeqId()));
    GetDBEngine().SaveCommand(*cmd); 
    GetDBEngine().NotifyIdChanged(id,"");
}
예제 #7
0
Int8 CLDS2_Database::x_GetLdsSeqId(const CSeq_id_Handle& id)
{
    CSQLITE_Statement* st = NULL;
    if ( id.IsGi() ) {
        // Try to use integer index
        st = &x_GetStatement(eSt_GetLdsSeqIdForIntId);
        st->Bind(1, id.GetGi());
    }
    else {
        // Use text index
        st = &x_GetStatement(eSt_GetLdsSeqIdForTxtId);
        st->Bind(1, id.AsString());
    }
    if ( st->Step() ) {
        Int8 ret = st->GetInt8(0);
        st->Reset();
        return ret;
    }

    // Id not in the database yet -- add new entry.
    st = &x_GetStatement(eSt_AddLdsSeqId);
    st->Bind(1, id.AsString());
    if ( id.IsGi() ) {
        st->Bind(2, id.GetGi());
    }
    else {
        // HACK: reset GI to null if not available.
        st->Bind(2, (void*)NULL, 0);
    }
    CNcbiOstrstream out;
    out << MSerial_AsnBinary << *id.GetSeqId();
    string buf = CNcbiOstrstreamToString(out);
    st->Bind(3, buf.size());
    st->Bind(4, buf.data(), buf.size());

    st->Execute();
    Int8 ret = st->GetLastInsertedRowid();
    st->Reset();
    return ret;
}
예제 #8
0
static inline CRef<CSeq_id> s_ConvertId(const CSeq_id_Handle& handle)
{
    return CRef<CSeq_id>(const_cast<CSeq_id*>(&*handle.GetSeqId()));
}
예제 #9
0
CAlignSort::SSortKey
CAlignSort::SAlignExtractor::operator()(const CSeq_align& align)
{
    SSortKey key;
    ITERATE (vector<string>, iter, key_toks) {
        SSortKey::TItem item;

        if (NStr::EqualNocase(*iter, "query")) {
            CSeq_id_Handle idh =
                CSeq_id_Handle::GetHandle(align.GetSeq_id(0));
            idh = sequence::GetId(idh, *scope,
                                  sequence::eGetId_Canonical);
            item.first = idh.GetSeqId()->AsFastaString();
        }
        else if (NStr::EqualNocase(*iter, "subject")) {
            CSeq_id_Handle idh =
                CSeq_id_Handle::GetHandle(align.GetSeq_id(1));
            idh = sequence::GetId(idh, *scope,
                                  sequence::eGetId_Canonical);
            item.first = idh.GetSeqId()->AsFastaString();
        }

        else if (NStr::EqualNocase(*iter, "query_start")) {
            item.second = align.GetSeqStart(0);
        }
        else if (NStr::EqualNocase(*iter, "subject_start")) {
            item.second = align.GetSeqStart(1);
        }

        else if (NStr::EqualNocase(*iter, "query_end")) {
            item.second = align.GetSeqStop(0);
        }
        else if (NStr::EqualNocase(*iter, "subject_end")) {
            item.second = align.GetSeqStop(1);
        }

        else if (NStr::EqualNocase(*iter, "query_strand")) {
            item.second = align.GetSeqStrand(0);
        }
        else if (NStr::EqualNocase(*iter, "subject_strand")) {
            item.second = align.GetSeqStrand(1);
        }

        else if (NStr::EqualNocase(*iter, "query_align_len")) {
            item.second = align.GetSeqRange(0).GetLength();
        }
        else if (NStr::EqualNocase(*iter, "subject_align_len")) {
            item.second = align.GetSeqRange(1).GetLength();
        }
        else if (NStr::EqualNocase(*iter, "query_traceback")) {
            CScoreBuilder builder;
            item.first = builder.GetTraceback(*scope, align, 0);
        }
        else if (NStr::EqualNocase(*iter, "subject_traceback")) {
            CScoreBuilder builder;
            item.first = builder.GetTraceback(*scope, align, 1);
        }

        else {
            /// assume it is a score
            CScoreLookup lookup;
            lookup.SetScope(*scope);
            item.second = lookup.GetScore(align, *iter);
        }
        key.items.push_back(item);
    }
예제 #10
0
void CGenbankGatherer::x_DoSingleSection(CBioseqContext& ctx) const
{
    CConstRef<IFlatItem> item;
    const CFlatFileConfig& cfg = ctx.Config();

    // these macros make the code easier to read and less repetitive
#define GATHER_BLOCK(BlockType, ItemClassName) \
    if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \
        item.Reset( new ItemClassName(ctx) ); \
        ItemOS() << item; \
    }

#define GATHER_ANCHOR(BlockType, block_str) \
    if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \
        item.Reset( new CHtmlAnchorItem(ctx, (block_str) ) ); \
        ItemOS() << item; \
    }

#define GATHER_VIA_FUNC(BlockType, FuncName) \
    if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \
        FuncName(); \
    }

    // if there's a callback, let it know we've entered another bioseq
    if( cfg.GetGenbankBlockCallback() ) {
        CFlatFileConfig::CGenbankBlockCallback::EBioseqSkip eBioseqSkip =
            cfg.GetGenbankBlockCallback()->notify_bioseq( ctx );
        if( eBioseqSkip == CFlatFileConfig::CGenbankBlockCallback::eBioseqSkip_Yes ) {
            return;
        }
    }

    // gather needed blocks
    GATHER_BLOCK(Head, CStartSectionItem);
    GATHER_ANCHOR(Locus, "locus");
    GATHER_BLOCK(Locus, CLocusItem);
    GATHER_BLOCK(Defline, CDeflineItem);
    GATHER_BLOCK(Accession, CAccessionItem);
    GATHER_BLOCK(Version, CVersionItem);
    GATHER_BLOCK(Project, CGenomeProjectItem);

    if ( ctx.IsProt() ) {
        bool show_dbsource = true;
        CBioseq_Handle& bsh = ctx.GetHandle();
        FOR_EACH_SEQID_ON_BIOSEQ_HANDLE (sid_itr, bsh) {
            CSeq_id_Handle sid = *sid_itr;
            switch (sid.Which()) {
                case NCBI_SEQID(Other):
                {
                    CConstRef<CSeq_id> id = sid.GetSeqId();
                    const CTextseq_id& tsid = *id->GetTextseq_Id ();
                    if (tsid.IsSetAccession()) {
                        const string& acc = tsid.GetAccession ();
                        if (NStr::StartsWith (acc, "WP_")) {
                            show_dbsource = false;
                        }
                    }
                    break;
                }
                default:
                    break;
           }
        }