Example #1
0
void ASI::RemoveFromLayout(CRef& cref, CRef& layout)
{
    Component* pLayoutComponent = layout.GetInstance();
    if (pLayoutComponent != NULL)
    {
        int funcSet  = pLayoutComponent->GetFuncSet("{f742f223-bb7b-48f0-92a8-81702e14de16}");
        int emitter  = pLayoutComponent->GetEmitter("{b11a0db4-cb96-4bf6-9631-fd96f20ea6ab}");
        int receiver = pLayoutComponent->GetReceiver("{6a7ab00f-1ab4-4324-9eb4-e614bfca4a16}");

        if ((funcSet  != -1) &&
            (emitter  != -1) &&
            (receiver != -1))
        {
            Component* pComponent = cref.GetInstance();
            if (pComponent != NULL)
            {
                if (pComponent->m_pData->inLayout &&
                    IsParent(pLayoutComponent, pComponent))
                {
                    /*
                     * Tell the layout component to remove
                     * the item with the given CRef id.
                     */
                    DRef dref = NewData(BOI_STD_D(Int));
                    *dref.GetWriteInstance<int>() = cref.Id();
                    pLayoutComponent->CallFunc(funcSet, 2, dref, true);

                    DisconnectFromReceiver(pLayoutComponent, emitter, cref);
                    DisconnectFromReceiver(pComponent, BOI_STD_E(ParentBoundingBox), layout);

                    pComponent->m_pData->inLayout = false;

                    CRef invalidCRef;
                    pComponent->SetParent(invalidCRef);
                }

                cref.ReleaseInstance();
            }
        }

        layout.ReleaseInstance();
    }
}
void 
CBlastScopeSource::AddDataLoaders(CRef<objects::CScope> scope)
{
    const int blastdb_loader_priority = 
        kBlastDbLoaderPriority + (s_CountBlastDbDataLoaders() - 1);

    // Note that these priorities are needed so that the CScope::AddXXX methods
    // don't need a specific priority (the default will be fine).
    if (!m_BlastDbLoaderName.empty()) {
        _TRACE("Adding " << m_BlastDbLoaderName << " at priority " <<
               blastdb_loader_priority);
        scope->AddDataLoader(m_BlastDbLoaderName, blastdb_loader_priority);
    } 
    if (!m_GbLoaderName.empty()) {
        _TRACE("Adding " << m_GbLoaderName << " at priority " <<
               (int)CBlastScopeSource::kGenbankLoaderPriority);
        scope->AddDataLoader(m_GbLoaderName, kGenbankLoaderPriority);
    }
}
bool CPrefetchManager::IsActive(void)
{
    CThreadPool_Thread* thread = dynamic_cast<CThreadPool_Thread*>(
                                                CThread::GetCurrentThread());
    if ( !thread ) {
        return false;
    }

    CRef<CThreadPool_Task> req = thread->GetCurrentTask();
    if ( !req ) {
        return false;
    }
    
    if ( req->IsCancelRequested() && dynamic_cast<CPrefetchRequest*>(&*req) ) {
        throw prefetch::CCancelRequestException();
    }
    
    return true;
}
Example #4
0
void ASI::GetMenus(CRef& cref, MenuSet& menuSet)
{
    int type = cref.Type();

    if (!m_pMenuManager->GetMenus(type, menuSet))
    {
        menuSet.Clear();

        Component* pComponent = cref.GetInstance();
        if (pComponent != NULL)
        {
            const QStringList profile = pComponent->GetProfile();

            m_pMenuManager->GetMenus(profile, menuSet, type);

            cref.ReleaseInstance();
        }
    }
}
Example #5
0
void CExportStrategy::x_Process_SearchDb(CRef<CSearchDatabase> & db)
{
    if (db.Empty())
    {
        NCBI_THROW(CBlastException, eInvalidArgument,
                   "Empty reference for CSearchDatabase.");
    }

	if (db->GetDatabaseName().empty())
	{
	    NCBI_THROW(CBlastException, eInvalidArgument,
	               "Error: No database specified");
	}

	// Set database Name
	CRef<CBlast4_subject> subject_p(new CBlast4_subject);
	subject_p->SetDatabase(db->GetDatabaseName());
	m_QueueSearchRequest->SetSubject(*subject_p);

	// Set Entrez Query Limitation
	string entrez_query_limit = db->GetEntrezQueryLimitation();
	if(!entrez_query_limit.empty())
	{
		CRef<CBlast4_parameter> p(new CBlast4_parameter);
		p->SetName(CBlast4Field::GetName(eBlastOpt_EntrezQuery));

		CRef<CBlast4_value> v(new CBlast4_value);
		v->SetString().assign(entrez_query_limit);
		p->SetValue(*v);
		_ASSERT(CBlast4Field::Get(eBlastOpt_EntrezQuery).Match(*p));

		m_QueueSearchRequest->SetProgram_options().Set().push_back(p);
	}

    // Set the GI List Limitation
    const CSearchDatabase::TGiList& gi_list_limit = db->GetGiListLimitation();
    if (!gi_list_limit.empty())
    {
		#ifdef NCBI_STRICT_GI
       		vector<int> int_gi_list;
       		ITERATE ( vector<TGi>, it, gi_list_limit ) {
       			int_gi_list.push_back(GI_TO( int, *it));
       		}
Example #6
0
//  ----------------------------------------------------------------------------
bool 
CVcfReader::xProcessFilter(
    CVcfData& data,
    CRef<CSeq_feat> pFeature )
//  ----------------------------------------------------------------------------
{
    CSeq_feat::TExt& ext = pFeature->SetExt();
    ext.AddField( "filter", data.m_strFilter );
    return true;
}
Example #7
0
CBlastPrelimSearch::CBlastPrelimSearch(CRef<IQueryFactory> query_factory,
                                       CRef<CBlastOptions> options,
                                       CRef<CLocalDbAdapter> db)
    : m_QueryFactory(query_factory), m_InternalData(new SInternalData),
    m_Options(options), m_DbAdapter(db), m_DbInfo(NULL)
{
    BlastSeqSrc* seqsrc = db->MakeSeqSrc();
    x_Init(query_factory, options, CRef<CPssmWithParameters>(), seqsrc);
    m_InternalData->m_SeqSrc.Reset(new TBlastSeqSrc(seqsrc, 0));
}
Example #8
0
static CRef<CScope> s_InitScope(bool reset_loader = true)
{
    CRef<CObjectManager> om = CObjectManager::GetInstance();
    if ( reset_loader ) {
        CDataLoader* loader =
            om->FindDataLoader(CGBDataLoader::GetLoaderNameFromArgs());
        if ( loader ) {
            BOOST_CHECK(om->RevokeDataLoader(*loader));
        }
    }
#ifdef HAVE_PUBSEQ_OS
    DBAPI_RegisterDriver_FTDS();
    GenBankReaders_Register_Pubseq();
#endif
    CGBDataLoader::RegisterInObjectManager(*om);
    CRef<CScope> scope(new CScope(*om));
    scope->AddDefaults();
    return scope;
}
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;
}
Example #10
0
void ASI::AddToLayout(CRef& cref, CRef& layout)
{
    Component* pLayoutComponent = layout.GetInstance();
    if (pLayoutComponent != NULL)
    {
        int funcSet  = pLayoutComponent->GetFuncSet("{f742f223-bb7b-48f0-92a8-81702e14de16}");
        int emitter  = pLayoutComponent->GetEmitter("{b11a0db4-cb96-4bf6-9631-fd96f20ea6ab}");
        int receiver = pLayoutComponent->GetReceiver("{6a7ab00f-1ab4-4324-9eb4-e614bfca4a16}");

        if ((funcSet  != -1) &&
            (emitter  != -1) &&
            (receiver != -1))
        {
            Component* pComponent = cref.GetInstance();
            if (pComponent != NULL)
            {
                if ((!pComponent->m_pData->inLayout) &&
                    (pComponent != pLayoutComponent))
                {
                    pComponent->SetParent(layout);

                    /*
                     * Tell the layout component to add
                     * a new item with the given CRef id.
                     */
                    DRef dref = NewData(BOI_STD_D(Int));
                    *dref.GetWriteInstance<int>() = cref.Id();
                    pLayoutComponent->CallFunc(funcSet, 1, dref, true);

                    ConnectToReceiver(pLayoutComponent, emitter, cref, BOI_STD_R(SetPosition));
                    ConnectToReceiver(pComponent, BOI_STD_E(ParentBoundingBox), layout, receiver);

                    pComponent->m_pData->inLayout = true;
                }

                cref.ReleaseInstance();
            }
        }

        layout.ReleaseInstance();
    }
}
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;
}
Example #12
0
bool
CShortReadFastaInputSource::x_ReadFromTwoFiles(CBioseq_set& bioseq_set,
                            TSeqPos batch_size,
                            CShortReadFastaInputSource::EInputFormat format)
{
    if (format == eFastc) {
        NCBI_THROW(CInputException, eInvalidInput, "FASTC format cannot be "
                   "used with two files");
    }

    // tags to indicate paired sequences
    CRef<CSeqdesc> seqdesc_first(new CSeqdesc);
    seqdesc_first->SetUser().SetType().SetStr("Mapping");
    seqdesc_first->SetUser().AddField("has_pair", eFirstSegment);

    CRef<CSeqdesc> seqdesc_last(new CSeqdesc);
    seqdesc_last->SetUser().SetType().SetStr("Mapping");
    seqdesc_last->SetUser().AddField("has_pair", eLastSegment);

    m_BasesAdded = 0;
    while (m_BasesAdded < batch_size && !m_LineReader->AtEOF() &&
           !m_SecondLineReader->AtEOF()) {

        CRef<CSeq_entry> first;
        CRef<CSeq_entry> second;

        if (format == eFasta) {
            first = x_ReadFastaOneSeq(m_LineReader); 
            second = x_ReadFastaOneSeq(m_SecondLineReader);
        }
        else {
            first = x_ReadFastqOneSeq(m_LineReader);
            second = x_ReadFastqOneSeq(m_SecondLineReader);
        }

        if (first.NotEmpty()) {
            if (second.NotEmpty()) {
                first->SetSeq().SetDescr().Set().push_back(seqdesc_first);
            }
            bioseq_set.SetSeq_set().push_back(first);
        }

        if (second.NotEmpty()) {
            if (first.NotEmpty()) {
                second->SetSeq().SetDescr().Set().push_back(seqdesc_last);
            }
            bioseq_set.SetSeq_set().push_back(second);
        }
    }

    return true;
}
Example #13
0
//  ----------------------------------------------------------------------------
bool CGtfReader::x_MergeFeatureLocationMultiInterval(
    const CGff2Record& record,
    CRef< CSeq_feat > pFeature )
//  ----------------------------------------------------------------------------
{
    CRef<CSeq_id> pId = CReadUtil::AsSeqId(
        record.Id(), m_iFlags & fAllIdsAsLocal);

    CRef< CSeq_loc > pLocation( new CSeq_loc );
    pLocation->SetInt().SetId( *pId );
    pLocation->SetInt().SetFrom( record.SeqStart() );
    pLocation->SetInt().SetTo( record.SeqStop() );
    if ( record.IsSetStrand() ) {
        pLocation->SetInt().SetStrand( record.Strand() );
    }
    pLocation = pLocation->Add( 
        pFeature->SetLocation(), CSeq_loc::fSortAndMerge_All, 0 );
    pFeature->SetLocation( *pLocation );
    return true;
}
Example #14
0
void ASI::SetPosition(CRef cref, const QPointF& pos)
{
    Component* pComponent = cref.GetInstance();
    if (pComponent != NULL)
    {
        if (!pComponent->m_pData->inLayout)
        {
            GuiRequest request;

            request.cref = cref;
            request.data.point.x = pos.x();
            request.data.point.y = pos.y();
            request.type = GuiRequest::RequestType_SetPosition;

            m_pGuiRequestHandler->PostRequest(&request);
        }

        cref.ReleaseInstance();
    }
}
Example #15
0
static void s_LoadECNumberTable(const string& dir, const string& name,
                                const char* const *fallback,
                                size_t fallback_count,
                                CProt_ref::EECNumberStatus status)
{
    CRef<ILineReader> lr;
    if ( !dir.empty() ) {
        lr.Reset(ILineReader::New
                 (CDirEntry::MakePath(dir, "ecnum_" + name, "txt")));
    }
    if (lr.Empty()) {
        while (fallback_count--) {
            s_ProcessECNumberLine(*fallback++, status);
        }
    } else {
        do {
            s_ProcessECNumberLine(*++*lr, status);
        } while ( !lr->AtEOF() );
    }
}
Example #16
0
CScope& CAlnMrgApp::GetScope(void) const
{
    if (!m_Scope) {
        m_ObjMgr = CObjectManager::GetInstance();
        CGBDataLoader::RegisterInObjectManager(*m_ObjMgr);
        
        m_Scope = new CScope(*m_ObjMgr);
        m_Scope->AddDefaults();
    }
    return *m_Scope;
}
Example #17
0
CRef<CBlastOptionsHandle> 
CIgBlastnAppArgs::x_CreateOptionsHandle(CBlastOptions::EAPILocality locality,
                                      const CArgs& args)
{
    CRef<CBlastOptionsHandle> retval;
    SetTask("blastn");
    retval.Reset(CBlastOptionsFactory::CreateTask(GetTask(), locality));
    _ASSERT(retval.NotEmpty());

    retval->SetFilterString("F");
    //retval->SetEvalueThreshold(1e-15);  <- this will be overwritten anyway
    CBlastOptions &opts = retval->SetOptions();
    opts.SetMatchReward(1);
    opts.SetMismatchPenalty(-1);
    opts.SetWordSize(11);
    opts.SetGapOpeningCost(4);
    opts.SetGapExtensionCost(1);

    return retval;
}
Example #18
0
// Must be called under a lock
// When a client inactivity timeout is detected there is no need to touch the
// running or reading jobs. The only things to be done are:
// - cancel waiting
// - reset pref affinities
// - set reset affinity flag
// - log the event
void
CNSClientsRegistry::ClearOnTimeout(CNSClient &      client,
                                   const string &   client_node,
                                   bool             is_log,
                                   ECommandGroup    cmd_group)
{
    // Deregister preferred affinities
    bool    had_pref_affs = client.HasPreferredAffinities(cmd_group);
    if (had_pref_affs) {
        m_AffRegistry->RemoveClientFromAffinities(
                                    client.GetID(),
                                    client.GetPreferredAffinities(cmd_group),
                                    cmd_group);
        client.ClearPreferredAffinities(cmd_group);

        if (is_log) {
            string      aff_part = "get";
            if (cmd_group == eRead)
                aff_part = "read";

            CRef<CRequestContext>   ctx;
            ctx.Reset(new CRequestContext());
            ctx->SetRequestID();
            GetDiagContext().SetRequestContext(ctx);
            GetDiagContext().PrintRequestStart()
                            .Print("_type", "client_watch")
                            .Print("client_node", client_node)
                            .Print("client_session", client.GetSession())
                            .Print(aff_part + "_preferred_affinities_reset",
                                   "yes");
            ctx->SetRequestStatus(CNetScheduleHandler::eStatus_OK);
            GetDiagContext().PrintRequestStop();
        }

        client.SetAffinityReset(true, cmd_group);
    }

    CancelWaiting(client, cmd_group);
    if (had_pref_affs)
        x_BuildAffinities(cmd_group);
}
Example #19
0
CRef<CBioSource> MakeCommonBioSource(const objects::CBioSource& src1, const objects::CBioSource& src2)
{ 
    CRef<CBioSource> common(NULL);

    if (!src1.IsSetOrg() || !src2.IsSetOrg()) {
        return common;
    }
    int taxid1 = src1.GetOrg().GetTaxId();
    int taxid2 = src2.GetOrg().GetTaxId();
    if (taxid1 == 0 || taxid2 == 0) {
        return common;
    } else if (taxid1 == taxid2) {
        common = src1.MakeCommon(src2);
    } else {
        CRef<CT3Request> rq(new CT3Request());
        rq->SetJoin().Set().push_back(taxid1);
        rq->SetJoin().Set().push_back(taxid2);
        CTaxon3_request request;
        request.SetRequest().push_back(rq);
        CTaxon3 taxon3;
        taxon3.Init();
        CRef<CTaxon3_reply> reply = taxon3.SendRequest(request);
        if (reply) {
            CTaxon3_reply::TReply::const_iterator reply_it = reply->GetReply().begin();
            while (reply_it != reply->GetReply().end()) {
                if ((*reply_it)->IsData() 
                    && (*reply_it)->GetData().GetOrg().IsSetTaxname()) {
                    bool is_species_level = false, force_consult = false, has_nucleomorphs = false;
                    (*reply_it)->GetData().GetTaxFlags (is_species_level, force_consult, has_nucleomorphs);
                    if (is_species_level) {
                        common.Reset(new CBioSource());
                        common->SetOrg().Assign((*reply_it)->GetData().GetOrg());
                    }
                    break;
                }
                ++reply_it;
            }
        }
    }
    return common;
}
Example #20
0
BEGIN_NCBI_SCOPE


CRef<ILineReader> ILineReader::New(const string& filename)
{
    CRef<ILineReader> lr;
    if (filename != "-") {
        try {
            lr.Reset(new CMemoryLineReader(new CMemoryFile(filename),
                                           eTakeOwnership));
        } catch (exception& e) { // CFileException is the main concern
            ERR_POST_X(1, Info << "ILineReader::New: falling back from"
                       " CMemoryLineReader to CBufferedLineReader for "
                       << filename << " due to exception: " << e.what());
        }
    }
    if (lr.Empty()) {
        lr.Reset(new CBufferedLineReader(filename));
    }
    return lr;
}
Example #21
0
int
CSeqDBPerfApp::x_ScanDatabase()
{
    CStopWatch sw;
    sw.Start();
    Uint8 num_letters = m_BlastDb->GetTotalLength();
    const bool kScanUncompressed = GetArgs()["scan_uncompressed"];
    vector<int> oids2iterate;
    for (int oid = 0; m_DbHandles.front()->CheckOrFindOID(oid); oid++) {
        oids2iterate.push_back(oid);
    }
    LOG_POST(Info << "Will go over " << oids2iterate.size() << " sequences");

    #pragma omp parallel default(none) num_threads(m_DbHandles.size()) \
                         shared(oids2iterate) if(m_DbHandles.size() > 1)
    { 
        int thread_id = 0;
#ifdef _OPENMP
        thread_id = omp_get_thread_num();
#endif
        #pragma omp for schedule(static, (oids2iterate.size()/m_DbHandles.size())) nowait
        for (size_t i = 0; i < oids2iterate.size(); i++) {
            int oid = oids2iterate[i];
            const char* buffer = NULL;
            int seqlen = 0;
            if (m_DbIsProtein || kScanUncompressed) {
                int encoding = m_DbIsProtein ? 0 : kSeqDBNuclBlastNA8;
                m_DbHandles[thread_id]->GetAmbigSeq(oid, &buffer, encoding);
                seqlen = m_DbHandles[thread_id]->GetSeqLength(oid);
            } else {
                m_DbHandles[thread_id]->GetSequence(oid, &buffer);
                seqlen = m_DbHandles[thread_id]->GetSeqLength(oid) / 4;
            }
            for (int i = 0; i < seqlen; i++) {
                char base = buffer[i];
                base = base;    // dummy statement
            }
            if (m_DbIsProtein || kScanUncompressed) {
                m_DbHandles[thread_id]->RetAmbigSeq(&buffer);
            } else {
                m_DbHandles[thread_id]->RetSequence(&buffer);
            }
        }
        x_UpdateMemoryUsage(thread_id);
    } // end of omp parallel

    sw.Stop();
    Uint8 bases = static_cast<Uint8>(num_letters / sw.Elapsed());
    cout << "Scanning rate: " 
         << NStr::NumericToString(bases, NStr::fWithCommas) 
         << " bases/second" << endl;
    return 0;
}
Example #22
0
static CRef<CScope> s_MakeScope(const string& file_name = kEmptyStr)
{
    CRef<CObjectManager> om = CObjectManager::GetInstance();
    if ( !s_LoaderName.empty() ) {
        om->RevokeDataLoader(s_LoaderName);
        s_LoaderName.erase();
    }
    if ( file_name.empty() ) {
        s_LoaderName =
            CVDBGraphDataLoader::RegisterInObjectManager(*om)
            .GetLoader()->GetName();
    }
    else {
        s_LoaderName =
            CVDBGraphDataLoader::RegisterInObjectManager(*om, file_name)
            .GetLoader()->GetName();
    }
    CRef<CScope> scope(new CScope(*om));
    scope->AddDataLoader(s_LoaderName);
    return scope;
}
Example #23
0
bool SequenceTable::findSequence(CRef< CSeq_id > seqId, CRef< CSeq_entry >& seqEntry)const
{
	CRef< CBioseq > bioseq;
	if (findSequence(seqId, bioseq))
	{
		seqEntry = new CSeq_entry;
		seqEntry->SetSeq(*bioseq);
		return true;
	}
	else
		return false;
}
Example #24
0
//  ----------------------------------------------------------------------------
bool 
CVcfReader::xProcessScore(
    CVcfData& data,
    CRef<CSeq_feat> pFeature )
//  ----------------------------------------------------------------------------
{
    CSeq_feat::TExt& ext = pFeature->SetExt();
    if ( data.m_pdQual ) {
        ext.AddField( "score", *data.m_pdQual );
    }
    return true;
}
/// Auxiliary function to assign the split query's Seq-interval so that it's
/// constrained within the chunk boundaries
/// @param chunk Range for the chunk [in]
/// @param query_range Range of sequence data corresponding to the full query
/// [in]
/// @param split_query_loc Seq-loc for this query constrained by the chunk's
/// boundaries [out]
static void
s_SetSplitQuerySeqInterval(const TChunkRange& chunk, 
                           const TChunkRange& query_range, 
                           CRef<CSeq_loc> split_query_loc)
{
    _ASSERT(split_query_loc.NotEmpty());
    _ASSERT(chunk.IntersectingWith(query_range));
    CSeq_interval& interval = split_query_loc->SetInt();
    const int qstart = chunk.GetFrom() - query_range.GetFrom();
    const int qend = chunk.GetToOpen() - query_range.GetToOpen();

    interval.SetFrom(max(0, qstart));
    if (qend >= 0) {
        interval.SetTo(query_range.GetToOpen() - query_range.GetFrom());
    } else {
        interval.SetTo(chunk.GetToOpen() - query_range.GetFrom());
    }
    // Note subtraction, as Seq-intervals are assumed to be
    // open/inclusive
    interval.SetTo() -= 1;
}
Example #26
0
void CBlastHitMatrixCGIApplication::x_GetSeqAnnot(CCgiContext& ctx)
{
        const CNcbiRegistry & reg = ctx.GetConfig();
        string blastURL = reg.Get("NetParams", "BlastURL");
        string url = (string)blastURL + "?CMD=Get&RID=" + m_RID + "&FORMAT_TYPE=ASN.1&FORMAT_OBJECT=Alignment";
        
        SConnNetInfo* net_info = ConnNetInfo_Create(NULL);
        // create HTTP connection
        CConn_HttpStream inHttp(url,net_info);   

        try {
            m_Annot.Reset(new CSeq_annot);
            auto_ptr<CObjectIStream> is
                    (CObjectIStream::Open(eSerial_AsnText, inHttp));
            *is >> *m_Annot;                                    
        }
         catch (CException& e) {
              m_Annot.Reset();              
              NCBI_THROW(CBlastHitMatrixCGIException, eInvalidSeqAnnot, "Exception reading SeqAnnot via url " + url + ", exception message: " + e.GetMsg());              
        }               
}
Example #27
0
int CNgAlignTest::Run()
{
    //const CArgs& args = GetArgs();

    CRef<CObjectManager> obj_mgr = CObjectManager::GetInstance();
    CGBDataLoader::RegisterInObjectManager(*obj_mgr);
    m_Scope.Reset(new CScope(*obj_mgr));
    m_Scope->AddDefaults();


    //string TestCaseIni = "/home/boukn/code/toolkit/c++/src/algo/align/uberalign/test/testcases.ini";
    string TestCaseIni = "/panfs/pan1.be-md.ncbi.nlm.nih.gov/genome_maint/work/uberalign/test/testcases.ini";

    CNcbiIfstream TestCaseFile(TestCaseIni.c_str());
    CNcbiRegistry TestCases(TestCaseFile);

    string CasesStr = TestCases.Get("caselist", "cases");
    list<string> Cases;
    NStr::Split(CasesStr, " \t\r\n,", Cases);

    ITERATE(list<string>, CaseIter, Cases) {

        string Type = TestCases.Get(*CaseIter, "type");
        if(Type == "one_to_one") {
            x_OneToOneCase(&TestCases, *CaseIter);
        } else if(Type == "one_to_blastdb") {
            x_OneToBlastDbCase(&TestCases, *CaseIter);
        } else if(Type == "list_to_blastdb") {
            x_ListToBlastDbCase(&TestCases, *CaseIter);
        } else if(Type == "split_one_to_blastdb") {
            x_SplitOneToBlastDbCase(&TestCases, *CaseIter);
        } else if(Type == "split_list_to_blastdb") {
            x_SplitListToBlastDbCase(&TestCases, *CaseIter);
        } else if(Type == "overlap_one_to_blastdb") {
            x_OverlapOneToBlastDbCase(&TestCases, *CaseIter);
        } else if(Type == "overlap_list_to_blastdb") {
            x_OverlapListToBlastDbCase(&TestCases, *CaseIter);
        }

    }
SSeqLoc blast_sseq_loc_from_str::make(const std::string& seq_data, bool is_prot, int  seq_gi, const std::string& title,
				      ENa_strand strand, int from, int to) {
  
  if (seq_gi < 0) {
    throw std::runtime_error("seq_id cannot be negative.");
  }
  if (seq_data.empty()) {
    throw std::runtime_error("seq_data cannot be empty.");
  }
  if (title.empty()) {
    throw std::runtime_error("title cannot be empty.");
  }
  
  CRef<CScope> scope(new CScope(*_objmngr));
  scope->AddDefaults();

  from = std::max(from - 1, 0);
  to   = std::max(to - 1,   0);
  if (to <= 0 || to > seq_data.size()){
    to = seq_data.size() -1; // this is because is [from:to]  and NOT [from:to[
  }
  if (from > to) {
    from = to;
  }

  CRef<CSeq_entry> entry(new CSeq_entry);
  CRef<CBioseq> bioseq = build_bioseq(seq_data, is_prot, seq_gi, title);
  entry->SetSeq(*bioseq);
  scope->AddTopLevelSeqEntry(*entry);
  
  CRef<CSeq_loc> seqloc(new CSeq_loc());

  seqloc->SetInt().SetTo(to);
  seqloc->SetInt().SetFrom(from);
  seqloc->SetStrand(strand);
  seqloc->SetInt().SetId().Assign(*bioseq->GetId().front());
  
  SSeqLoc sl(seqloc, scope);
  return sl;
}
Example #29
0
const bool CMSPeak::ContainsFast(const int value,
                                 const EMSPeakListTypes Which) const
{

    int x(0), l, r;
    CRef <CMSPeakList> PeakList = GetPeakLists()[Which];

    l = 0;
    r = PeakList->GetNum() - 1;

    while(l <= r) {
        x = (l + r)/2;
        if (PeakList->GetMZI()[x].GetMZ() < value - tol) 
	    l = x + 1;
        else if (PeakList->GetMZI()[x].GetMZ() > value + tol)
	    r = x - 1;
        else return true;
    } 
    
    if (x < PeakList->GetNum() - 1 && 
        PeakList->GetMZI()[x+1].GetMZ() < value + tol &&
        PeakList->GetMZI()[x+1].GetMZ() > value - tol) 
        return true;
    return false;
}
void CExportStrategy::x_Process_SearchDb(CRef<CSearchDatabase> & db)
{
    if (db.Empty())
    {
        NCBI_THROW(CBlastException, eInvalidArgument,
                   "Empty reference for CSearchDatabase.");
    }

	if (db->GetDatabaseName().empty())
	{
	    NCBI_THROW(CBlastException, eInvalidArgument,
	               "Error: No database specified");
	}

	// Set database Name
	CRef<CBlast4_subject> subject_p(new CBlast4_subject);
	subject_p->SetDatabase(db->GetDatabaseName());
	m_QueueSearchRequest->SetSubject(*subject_p);

	// Set Entrez Query Limitation
	string entrez_query_limit = db->GetEntrezQueryLimitation();
	if(!entrez_query_limit.empty())
	{
		CRef<CBlast4_parameter> p(new CBlast4_parameter);
		p->SetName(CBlast4Field::GetName(eBlastOpt_EntrezQuery));

		CRef<CBlast4_value> v(new CBlast4_value);
		v->SetString().assign(entrez_query_limit);
		p->SetValue(*v);
		_ASSERT(CBlast4Field::Get(eBlastOpt_EntrezQuery).Match(*p));

		m_QueueSearchRequest->SetProgram_options().Set().push_back(p);
	}

    // Set the GI List Limitation
    const CSearchDatabase::TGiList& gi_list_limit = db->GetGiListLimitation();
    if (!gi_list_limit.empty())
    {
    	x_AddParameterToProgramOptions(CBlast4Field::Get(eBlastOpt_GiList), gi_list_limit);
    }

    // Set the negative GI list
    const CSearchDatabase::TGiList& neg_gi_list = db->GetNegativeGiListLimitation();
    if (!neg_gi_list.empty())
    {
    	x_AddParameterToProgramOptions(CBlast4Field::Get(eBlastOpt_NegativeGiList), neg_gi_list);
    }

    // Set the filtering algorithms
    int algo_id = db->GetFilteringAlgorithm();
    if (algo_id != -1)
    {
       	x_AddParameterToProgramOptions(CBlast4Field::Get(eBlastOpt_DbFilteringAlgorithmId), algo_id);
    }
}