Esempio n. 1
0
    /// Performs sanity checks to make sure that the sequence requested is of
    /// the expected type. If the tests fail, an exception is thrown.
    /// @param id Sequence id for this sequence [in]
    void x_ValidateMoleculeType(CConstRef<CSeq_id> id) 
    {
        _ASSERT(m_BioseqMaker.NotEmpty());

        if (id.Empty())
        {
            NCBI_THROW(CInputException, eInvalidInput,
                       "Empty SeqID passed to the molecule type validation");
        }

        bool isProtein = m_BioseqMaker->IsProtein(id);
        if (!isProtein && m_ReadProteins)
        {
            NCBI_THROW(CInputException, eSequenceMismatch,
               "GI/accession/sequence mismatch: protein input required but nucleotide provided");
        }
        if (isProtein && !m_ReadProteins)
        {
            NCBI_THROW(CInputException, eSequenceMismatch,
               "GI/accession/sequence mismatch: nucleotide input required but protein provided");
        }

        if (!isProtein)  // Never seen a virtual protein sequence.
        {
             if (m_BioseqMaker->HasSequence(id) == false)
             {
                  string message = "No sequence available for " + id->AsFastaString();
                  NCBI_THROW(CInputException, eInvalidInput, message);
             }
        }
    }
Esempio n. 2
0
//	----------------------------------------------------------------------------
CConstRef<CSeq_feat> CFeatTableEdit::xGetMrnaParent(
    const CSeq_feat& feat)
//	----------------------------------------------------------------------------
{
    CConstRef<CSeq_feat> pMrna;
    CSeq_feat_Handle sfh = mpScope->GetSeq_featHandle(feat);
    CSeq_annot_Handle sah = sfh.GetAnnot();
    if (!sah) {
        return pMrna;
    }

    size_t bestLength(0);
    CFeat_CI findGene(sah, CSeqFeatData::eSubtype_mRNA);
    for ( ; findGene; ++findGene) {
        Int8 compare = sequence::TestForOverlap64(
                           findGene->GetLocation(), feat.GetLocation(),
                           sequence::eOverlap_Contained);
        if (compare == -1) {
            continue;
        }
        size_t currentLength = sequence::GetLength(findGene->GetLocation(), mpScope);
        if (!bestLength  ||  currentLength > bestLength) {
            pMrna.Reset(&(findGene->GetOriginalFeature()));
            bestLength = currentLength;
        }
    }
    return pMrna;
}
Esempio n. 3
0
bool CBioseq_Handle::ContainsSegment(CSeq_id_Handle id,
                                     size_t resolve_depth,
                                     EFindSegment limit_flag) const
{
    CBioseq_Handle h = GetScope().GetBioseqHandle(id);
    CConstRef<CSynonymsSet> syns;
    if ( h ) {
        syns = h.GetSynonyms();
    }
    SSeqMapSelector sel;
    sel.SetFlags(CSeqMap::fFindRef);
    if ( limit_flag == eFindSegment_LimitTSE ) {
        sel.SetLimitTSE(GetTopLevelEntry());
    }
    sel.SetResolveCount(resolve_depth);
    CSeqMap_CI it = GetSeqMap().BeginResolved(&GetScope(), sel);
    for ( ; it; ++it) {
        if ( syns ) {
            if ( syns->ContainsSynonym(it.GetRefSeqid()) ) {
                return true;
            }
        }
        else {
            if (it.GetRefSeqid() == id) {
                return true;
            }
        }
    }
    return false;
}
Esempio n. 4
0
    void x_ValidatePssmVsGi7450545(CConstRef<CSeq_align> sa, int hsp_num) {
        BOOST_REQUIRE(sa->GetSegs().IsDenseg());

        const CDense_seg & denseg = sa->GetSegs().GetDenseg();

        if (hsp_num == 1)
        {
            // Validate the first HSP
            pair<TSeqRange, TSeqRange> first_hsp = 
                make_pair(TSeqRange(24, 29), TSeqRange(245, 250));
            TSeqRange hsp1_query = denseg.GetSeqRange(0);
            TSeqRange hsp1_subj = denseg.GetSeqRange(1);
            BOOST_REQUIRE_EQUAL(first_hsp.first.GetFrom(), hsp1_query.GetFrom());
            BOOST_REQUIRE_EQUAL(first_hsp.first.GetTo(), hsp1_query.GetTo());
            BOOST_REQUIRE_EQUAL(first_hsp.second.GetFrom(), hsp1_subj.GetFrom());
            BOOST_REQUIRE_EQUAL(first_hsp.second.GetTo(), hsp1_subj.GetTo());
        }
        else if (hsp_num == 2)
        {
            // Validate the second HSP
            const pair<TSeqRange, TSeqRange> second_hsp = 
                make_pair(TSeqRange(74, 86), TSeqRange(108, 120));
            TSeqRange hsp2_query = denseg.GetSeqRange(0);
            TSeqRange hsp2_subj = denseg.GetSeqRange(1);
            BOOST_REQUIRE_EQUAL(second_hsp.first.GetFrom(), hsp2_query.GetFrom());
            BOOST_REQUIRE_EQUAL(second_hsp.first.GetTo(), hsp2_query.GetTo());
            BOOST_REQUIRE_EQUAL(second_hsp.second.GetFrom(), hsp2_subj.GetFrom());
            BOOST_REQUIRE_EQUAL(second_hsp.second.GetTo(), hsp2_subj.GetTo());
        }

    }
Esempio n. 5
0
CConstRef<CGC_Sequence> CGC_Sequence::GetTopLevelParent() const
{
    CConstRef<CGC_Sequence> top = GetParent();
    for ( ;  top  &&  top->GetParent();  top = top->GetParent()) {
    }
    return top;
}
Esempio n. 6
0
//  ----------------------------------------------------------------------------
void CFeatTableEdit::GenerateLocusTags()
//  ----------------------------------------------------------------------------
{
    CRef<CGb_qual> pLocusTag;

    SAnnotSelector selGenes;
    selGenes.IncludeFeatSubtype(CSeqFeatData::eSubtype_gene);
    CFeat_CI itGenes(mHandle, selGenes);
    for ( ; itGenes; ++itGenes) {
        string locusTagVal = itGenes->GetNamedQual("locus_tag");
        if (!locusTagVal.empty()) {
            continue;
        }
        CSeq_feat_EditHandle feh(mpScope->GetObjectHandle(
                                     (itGenes)->GetOriginalFeature()));
        feh.AddQualifier("locus_tag", xNextLocusTag());
    }
    SAnnotSelector selOther;
    selOther.ExcludeFeatSubtype(CSeqFeatData::eSubtype_gene);
    CFeat_CI itOther(mHandle, selOther);
    for ( ; itOther; ++itOther) {
        const CSeq_feat& feat = itOther->GetOriginalFeature();
        CSeq_feat_EditHandle feh(mpScope->GetObjectHandle(
                                     (itOther)->GetOriginalFeature()));
        feh.RemoveQualifier("locus_tag");
        CConstRef<CSeq_feat> pGeneParent = xGetGeneParent(feat);
        if (!pGeneParent) {
            continue;
        }
        string locusTag = pGeneParent->GetNamedQual("locus_tag");
        feh.AddQualifier("locus_tag", locusTag);
    }
}
Esempio n. 7
0
bool CLocation_constraint :: x_DoesBioseqMatchSequenceType(CConstRef <CBioseq> bioseq, const ESeqtype_constraint& seq_type) const
{
  if (seq_type == eSeqtype_constraint_any
        || (bioseq->IsNa() && seq_type == eSeqtype_constraint_nuc)
        || (bioseq->IsAa() && seq_type == eSeqtype_constraint_prot)) {
      return true;
  }
  else return false;
};
Esempio n. 8
0
void CSeqMap_CI::x_Push(const CConstRef<CSeqMap>& seqMap,
                        const CTSE_Handle& tse,
                        TSeqPos from, TSeqPos length,
                        bool minusStrand,
                        TSeqPos pos)
{
    TSegmentInfo push;
    push.m_SeqMap = seqMap;
    push.m_TSE = tse;
    push.m_LevelRangePos = from;
    push.m_LevelRangeEnd = from + length;
    if (push.m_LevelRangeEnd < push.m_LevelRangePos) {
        // Detect (from + length) overflow
        NCBI_THROW(CSeqMapException, eDataError,
                   "Sequence position overflow");
    }
    push.m_MinusStrand = minusStrand;
    TSeqPos findOffset = !minusStrand? pos: length - 1 - pos;
    push.m_Index = seqMap->x_FindSegment(from + findOffset, GetScope());
    if ( push.m_Index == size_t(-1) ) {
        if ( !m_Stack.empty() ) {
            return;
        }
        push.m_Index = !minusStrand?
            seqMap->x_GetLastEndSegmentIndex():
            seqMap->x_GetFirstEndSegmentIndex();
    }
    else {
        _ASSERT(push.m_Index > seqMap->x_GetFirstEndSegmentIndex() &&
                push.m_Index < seqMap->x_GetLastEndSegmentIndex());
        if ( pos >= length ) {
            if ( !minusStrand ) {
                if ( seqMap->x_GetSegmentPosition(push.m_Index, 0) <
                     push.m_LevelRangeEnd ) {
                    ++push.m_Index;
                    _ASSERT(seqMap->x_GetSegmentPosition(push.m_Index, 0) >=
                            push.m_LevelRangeEnd);
                }
            }
            else {
                if ( seqMap->x_GetSegmentEndPosition(push.m_Index, 0) >
                     push.m_LevelRangePos ) {
                    --push.m_Index;
                    _ASSERT(seqMap->x_GetSegmentEndPosition(push.m_Index, 0) <=
                            push.m_LevelRangePos);
                }
            }
        }
    }
    // update length of current segment
    seqMap->x_GetSegmentLength(push.m_Index, GetScope());
    m_Stack.push_back(push);
    // update position
    m_Selector.m_Position += x_GetTopOffset();
    // update length
    m_Selector.m_Length = push.x_CalcLength();
}
pair<double, bool> CScoreUniqSeqCoverage::MakeScore(CBioseq_Handle const& query_handle, vector<CSeq_align const*>::const_iterator begin, vector<CSeq_align const*>::const_iterator end)
{
    CConstRef<CBioseq> bioseq = query_handle.GetCompleteBioseq();

    unsigned int qlen = 0;
    if ( !bioseq.Empty() && bioseq->IsSetLength()) {
        qlen = bioseq->GetLength();
    }

    if ( !qlen ) {
        return make_pair(0, false);
    }

    bool isDenDiag = ( (*begin)->GetSegs().Which() == CSeq_align::C_Segs::e_Dendiag) ?
                              true : false;

    CRangeCollection<TSeqPos> subj_rng_coll((*begin)->GetSeqRange(1));
    CRange<TSeqPos> q_rng((*begin)->GetSeqRange(0));
    
    CRangeCollection<TSeqPos> query_rng_coll(s_FixMinusStrandRange(q_rng));
    
    for( ++begin; begin != end; ++begin ) {
        const CRange<TSeqPos> align_subj_rng((*begin)->GetSeqRange(1));
        // subject range should always be on the positive strand
        assert(align_subj_rng.GetTo() > align_subj_rng.GetFrom());
        CRangeCollection<TSeqPos> coll(align_subj_rng);
        coll.Subtract(subj_rng_coll);

        if ( coll.empty() ) {
            continue;
        }

        if(coll[0] == align_subj_rng) {
            CRange<TSeqPos> query_rng ((*begin)->GetSeqRange(0));
            query_rng_coll += s_FixMinusStrandRange(query_rng);
            subj_rng_coll += align_subj_rng;
        }
        else {
            ITERATE (CRangeCollection<TSeqPos>, uItr, coll) {
                CRange<TSeqPos> query_rng;
                const CRange<TSeqPos> & subj_rng = (*uItr);
                CRef<CSeq_align> densegAln;
                if ( isDenDiag) {
                    densegAln = CreateDensegFromDendiag(**begin);
                }

                CAlnMap map( (isDenDiag) ? densegAln->GetSegs().GetDenseg() : (*begin)->GetSegs().GetDenseg());
                TSignedSeqPos subj_aln_start =  map.GetAlnPosFromSeqPos(1,subj_rng.GetFrom());
                TSignedSeqPos subj_aln_end =  map.GetAlnPosFromSeqPos(1,subj_rng.GetTo());
                query_rng.SetFrom(map.GetSeqPosFromAlnPos(0,subj_aln_start));
                query_rng.SetTo(map.GetSeqPosFromAlnPos(0,subj_aln_end));

                query_rng_coll += s_FixMinusStrandRange(query_rng);
                subj_rng_coll += subj_rng;
            }
        }
    }
Esempio n. 10
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);
}
Esempio n. 11
0
void
CCmdLineBlastXML2ReportData::x_InitSubjects(CConstRef<IBlastSeqInfoSrc> subjectsInfo)
{
	if(subjectsInfo->Size() == 0) {
		NCBI_THROW(CException, eUnknown, "blastxml2: Empty seq info src");
	}

	for(unsigned int i =0; i < subjectsInfo->Size(); i++) {
		list<CRef<objects::CSeq_id> > ids = subjectsInfo->GetId(i);
		m_SubjectIds.push_back(CAlignFormatUtil::GetSeqIdString(ids, true));
	}
}
Esempio n. 12
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 {
Esempio n. 13
0
    void x_ValidatePssmVsGi129295(CConstRef<CSeq_align> sa) {
        BOOST_REQUIRE(sa->GetSegs().IsDenseg());

        const CDense_seg & denseg = sa->GetSegs().GetDenseg();

        // Validate the first (and only) HSP, which is a self hit
        const TSeqRange hsp(0, 231);
        TSeqRange hsp1_query = denseg.GetSeqRange(0);
        TSeqRange hsp1_subj = denseg.GetSeqRange(1);
        BOOST_REQUIRE_EQUAL(hsp.GetFrom(), hsp1_query.GetFrom());
        BOOST_REQUIRE_EQUAL(hsp.GetTo(), hsp1_query.GetTo());
        BOOST_REQUIRE_EQUAL(hsp.GetFrom(), hsp1_subj.GetFrom());
        BOOST_REQUIRE_EQUAL(hsp.GetTo(), hsp1_subj.GetTo());

    }
Esempio n. 14
0
CRef<CBioseq> CBlastBioseqMaker::
        CreateBioseqFromId(CConstRef<CSeq_id> id, bool retrieve_seq_data)
{
    _ASSERT(m_scope.NotEmpty());

    // N.B.: this call fetches the Bioseq into the scope from its
    // data sources (should be BLAST DB first, then Genbank)
    TSeqPos len = sequence::GetLength(*id, m_scope);
    if (len == numeric_limits<TSeqPos>::max()) {
        NCBI_THROW(CInputException, eSeqIdNotFound,
                    "Sequence ID not found: '" + 
                    id->AsFastaString() + "'");
    }

    CBioseq_Handle bh = m_scope->GetBioseqHandle(*id);

    CRef<CBioseq> retval;
    if (retrieve_seq_data) {
        retval.Reset(const_cast<CBioseq*>(&*bh.GetCompleteBioseq()));
    } else {
        retval.Reset(new CBioseq());
        CRef<CSeq_id> idToStore(new CSeq_id);
        idToStore->Assign(*id);
        retval->SetId().push_back(idToStore);
        retval->SetInst().SetRepr(CSeq_inst::eRepr_raw);
        retval->SetInst().SetMol(bh.IsProtein() 
                                    ? CSeq_inst::eMol_aa
                                    : CSeq_inst::eMol_dna);
        retval->SetInst().SetLength(len);
    }
    return retval;
}
Esempio n. 15
0
void CSeqMap_CI::x_Select(const CConstRef<CSeqMap>& seqMap,
                          const SSeqMapSelector& selector,
                          TSeqPos pos)
{
    m_Selector = selector;
    if ( m_Selector.m_Length == kInvalidSeqPos ) {
        TSeqPos len = seqMap->GetLength(GetScope());
        len -= min(len, m_Selector.m_Position);
        m_Selector.m_Length = len;
    }
    if ( pos < m_Selector.m_Position ) {
        pos = m_Selector.m_Position;
    }
    else if ( pos > m_Selector.m_Position + m_Selector.m_Length ) {
        pos = m_Selector.m_Position + m_Selector.m_Length;
    }
    x_Push(seqMap, m_Selector.m_TopTSE,
           m_Selector.m_Position,
           m_Selector.m_Length,
           m_Selector.m_MinusStrand,
           pos - m_Selector.m_Position);
    while ( !x_Found() && GetPosition() < m_SearchEnd ) {
        if ( !x_Push(pos - m_Selector.m_Position) ) {
            x_SettleNext();
            break;
        }
    }
}
Esempio n. 16
0
CPsiBlast::CPsiBlast(CRef<IQueryFactory> query_factory,
                     CRef<CLocalDbAdapter> blastdb,
                     CConstRef<CPSIBlastOptionsHandle> options)
: m_Subject(blastdb), m_Impl(0)
{
    m_Impl = new CPsiBlastImpl(query_factory, m_Subject, 
         CConstRef<CBlastProteinOptionsHandle>(options.GetPointer()));
}
Esempio n. 17
0
//	----------------------------------------------------------------------------
string CFeatTableEdit::xCurrentTranscriptId(
    const CSeq_feat& cds)
//	----------------------------------------------------------------------------
{
    // format: mLocusTagPrefix|mrna.<locus tag of gene>[_numeric disambiguation]
    CConstRef<CSeq_feat> pGene = xGetGeneParent(cds);
    if (!pGene) {
        return "";
    }
    string locusTag = pGene->GetNamedQual("locus_tag");
    string disAmbig = "";
    map<string, int>::iterator it = mMapProtIdCounts.find(locusTag);
    if (it != mMapProtIdCounts.end()  &&  mMapProtIdCounts[locusTag] != 0) {
        disAmbig = string("_") + NStr::IntToString(mMapProtIdCounts[locusTag]);
    }
    return (mLocusTagPrefix + "|mrna." + locusTag + disAmbig);
}
Esempio n. 18
0
CSeq_id_Info::CSeq_id_Info(const CConstRef<CSeq_id>& seq_id,
                           CSeq_id_Mapper* mapper)
    : m_Seq_id_Type(seq_id->Which()),
      m_Seq_id(seq_id),
      m_Mapper(mapper)
{
    _ASSERT(mapper);
}
Esempio n. 19
0
void 
CPsiBlastIterationState::GetSeqIds(CConstRef<objects::CSeq_align_set> seqalign, 
                                   CConstRef<CPSIBlastOptionsHandle> opts, 
                                   TSeqIds& retval)
{
    retval.clear();
    CPsiBlastAlignmentProcessor proc;
    proc(*seqalign, opts->GetInclusionThreshold(), retval);
}
Esempio n. 20
0
string& CAlnVec::GetAlnSeqString(string& buffer,
                                 TNumrow row,
                                 const TSignedRange& aln_rng) const
{
    string buff;
    buffer.erase();

    CSeqVector& seq_vec      = x_GetSeqVector(row);
    TSeqPos     seq_vec_size = seq_vec.size();
    
    // get the chunks which are aligned to seq on anchor
    CRef<CAlnMap::CAlnChunkVec> chunk_vec = 
        GetAlnChunks(row, aln_rng, fSkipInserts | fSkipUnalignedGaps);
    
    // for each chunk
    for (int i=0; i<chunk_vec->size(); i++) {
        CConstRef<CAlnMap::CAlnChunk> chunk = (*chunk_vec)[i];
                
        if (chunk->GetType() & fSeq) {
            // add the sequence string
            if (IsPositiveStrand(row)) {
                seq_vec.GetSeqData(chunk->GetRange().GetFrom(),
                                   chunk->GetRange().GetTo() + 1,
                                   buff);
            } else {
                seq_vec.GetSeqData(seq_vec_size - chunk->GetRange().GetTo() - 1,
                                   seq_vec_size - chunk->GetRange().GetFrom(),
                                   buff);
            }
            if (GetWidth(row) == 3) {
                TranslateNAToAA(buff, buff, GetGenCode(row));
            }
           buffer += buff;
        } else {
            // add appropriate number of gap/end chars
            const int n = chunk->GetAlnRange().GetLength();
            char* ch_buff = new char[n+1];
            char fill_ch;
            if (chunk->GetType() & fNoSeqOnLeft  ||
                chunk->GetType() & fNoSeqOnRight) {
                fill_ch = GetEndChar();
            } else {
                fill_ch = GetGapChar(row);
            }
            memset(ch_buff, fill_ch, n);
            ch_buff[n] = 0;
            buffer += ch_buff;
            delete[] ch_buff;
        }
    }
    return buffer;
}
Esempio n. 21
0
bool CLocation_constraint :: Match(const CSeq_feat& feat, CConstRef <CSeq_feat> feat_to, CConstRef <CBioseq> feat_bioseq) const
{
  if (x_IsLocationConstraintEmpty()) {
     return true;
  }
 
  const CSeq_loc& feat_loc = feat.GetLocation();
  if (GetStrand() != eStrand_constraint_any) {
    if (feat_bioseq.Empty()) {
       return false;
    }
    else if (feat_bioseq->IsAa()) {
      if (feat_to.Empty()) {  // when feat is product, feat_to points to cds
         return false;
      }
      else if (!x_DoesStrandMatchConstraint (feat_to->GetLocation())) {
        return false;
      }
    }
    else if (!x_DoesStrandMatchConstraint (feat_loc)) {
        return false;
    }
  }

  if (!x_DoesBioseqMatchSequenceType(feat_bioseq, GetSeq_type())) {
     return false;
  }

  if (!x_DoesLocationMatchPartialnessConstraint (feat_loc)) {
     return false;
  }

  if (!x_DoesLocationMatchTypeConstraint (feat_loc)) {
     return false;
  }

  if (!x_DoesLocationMatchDistanceConstraint(feat_bioseq, feat_loc)) {
     return false;
  }

  return true;
};
Esempio n. 22
0
bool CLocation_constraint :: x_DoesLocationMatchDistanceConstraint(CConstRef <CBioseq> bioseq, const CSeq_loc& loc) const
{
  if (!CanGetEnd5() && !CanGetEnd3()) {
      return true;
  }

  unsigned pos = loc.GetStop(eExtreme_Positional);
  int pos2;
  if (bioseq.NotEmpty()) {
     pos2 = (bioseq->IsSetLength() ?  bioseq->GetLength() : 0) - pos - 1;
  }

  if (loc.GetStrand() == eNa_strand_minus) {
    if (CanGetEnd5()) {
      if (bioseq.Empty()) {
          return false;
      }
      else {
        if (!GetEnd5().Match(pos2)) {
           return false;
        }
      }
    }
    if (CanGetEnd3()) {
        return GetEnd3().Match(pos);
    }
  }
  else
  {
    if (CanGetEnd5() && !GetEnd5().Match(pos)) {
        return false;
    }
    if (CanGetEnd3()) {
      if (bioseq.Empty()) {
         return false;
      }
      return GetEnd3().Match(pos2);
    }
  }
  return true;
};
Esempio n. 23
0
//	----------------------------------------------------------------------------
string CFeatTableEdit::xNextProteinId(
    const CSeq_feat& cds)
//	----------------------------------------------------------------------------
{
    // format: mLocusTagPrefix|<locus tag of gene>[_numeric disambiguation]
    CConstRef<CSeq_feat> pGene = xGetGeneParent(cds);
    if (!pGene) {
        return "";
    }
    string locusTag = pGene->GetNamedQual("locus_tag");
    string disAmbig = "";
    map<string, int>::iterator it = mMapProtIdCounts.find(locusTag);
    if (it == mMapProtIdCounts.end()) {
        mMapProtIdCounts[locusTag] = 0;
    }
    else {
        ++mMapProtIdCounts[locusTag];
        disAmbig = string("_") + NStr::IntToString(mMapProtIdCounts[locusTag]);
    }
    return (mLocusTagPrefix + "|" + locusTag + disAmbig);
}
Esempio n. 24
0
void
CCmdLineBlastXML2ReportData::x_InitCommon(
	const CSearchResults & results,
    CConstRef<CBlastOptions> opts)
{
	if(opts.Empty()) {
		NCBI_THROW(CException, eUnknown, "blastxml2: Empty blast options");
	}

	if(m_Scope.Empty()) {
		NCBI_THROW(CException, eUnknown, "blastxml2: Empty scope");
	}

	x_FillScoreMatrix(m_Options->GetMatrixName());

	string resolved = SeqDB_ResolveDbPath("taxdb.bti");
	if(!resolved.empty()) {
		m_TaxDBFound = true;
	}

  	m_isIterative  = opts->IsIterativeSearch();
}
Esempio n. 25
0
bool CBlastBioseqMaker::IsProtein(CConstRef<CSeq_id> id)
{
    _ASSERT(m_scope.NotEmpty());

    CBioseq_Handle bh = m_scope->GetBioseqHandle(*id);
    if (!bh)
    {
        NCBI_THROW(CInputException, eSeqIdNotFound,
                    "Sequence ID not found: '" + 
                    id->AsFastaString() + "'");
    }
    return bh.IsProtein();
}
Esempio n. 26
0
CRef<CBlastQueryVector>
CBlastInput::GetNextSeqBatch(CScope& scope)
{
    CRef<CBlastQueryVector> retval(new CBlastQueryVector);
    TSeqPos size_read = 0;

    while (size_read < GetBatchSize()) {

        if (End())
            break;

        CRef<CBlastSearchQuery> q;
        try { q.Reset(m_Source->GetNextSequence(scope)); }
        catch (const CObjReaderParseException& e) {
            if (e.GetErrCode() == CObjReaderParseException::eEOF) {
                break;
            }
            throw;
        }
        CConstRef<CSeq_loc> loc = q->GetQuerySeqLoc();

        if (loc->IsInt()) {
            size_read += sequence::GetLength(loc->GetInt().GetId(),
                                             q->GetScope());
        } else if (loc->IsWhole()) {
            size_read += sequence::GetLength(loc->GetWhole(), q->GetScope());
        } else {
            // programmer error, CBlastInputSource should only return Seq-locs
            // of type interval or whole
            abort();
        }

        retval->AddQuery(q);
    }

    return retval;
}
pair<double, bool> CScoreSeqCoverage::MakeScore(CBioseq_Handle const& query_handle, vector<CSeq_align const*>::const_iterator begin, vector<CSeq_align const*>::const_iterator end) 
{
    CConstRef<CBioseq> bioseq = query_handle.GetCompleteBioseq();

    unsigned int qlen = 0;
    if ( !bioseq.Empty() && bioseq->IsSetLength()) {
        qlen = bioseq->GetLength();
    }

    if ( !qlen ) {
        return make_pair(0, false);
    }

    // Subject coverage score
    CRangeCollection<TSeqPos> range_coll;

    for ( ; begin != end; ++begin ) {
        CRange<TSeqPos> range = (*begin)->GetSeqRange(0);
        s_FixMinusStrandRange(range);
        range_coll += range;            
    } 
    double score = ( 100.0 * range_coll.GetCoveredLength() ) / qlen;
    return make_pair(score, true);
}
Esempio n. 28
0
static
CRef<CBioseq> MakeMaskingBioseq(const CSeq_id& new_id,
                                TSeqPos seq_length,
                                CConstRef<CSeq_id> original_id,
                                const CSeq_loc& masking_loc)
{
    vector<CRange<TSeqPos> > mask_ranges;
    for ( CSeq_loc_CI it(masking_loc); it; ++it ) {
        if ( !original_id ) {
            original_id = &it.GetSeq_id();
        }
        else if ( !original_id->Equals(it.GetSeq_id()) ) {
            continue;
        }
        mask_ranges.push_back(it.GetRange());
    }
    return MakeMaskingBioseq(new_id, seq_length, *original_id, mask_ranges);
}
Esempio n. 29
0
bool CBioseq_Handle::IsSynonym(const CSeq_id_Handle& idh) const
{
    CConstRef<CSynonymsSet> syns = GetSynonyms();
    return syns && syns->ContainsSynonym(idh);
}
Esempio n. 30
0
 void x_ValidatePssmVsGi40456275(CConstRef<CSeq_align> sa) {
     BOOST_REQUIRE_EQUAL(false, sa->IsSetSegs());
 }