コード例 #1
0
bool CBasicFastaWrapper::ReadAsSeqEntry(CNcbiIstream& iStream, CRef< CSeq_entry >& seqEntry) 
{
    bool result = ReadFile(iStream);
    if (result) {
        seqEntry->Assign(*m_seqEntry);
    }
    return result;

}
コード例 #2
0
ファイル: cuCD.cpp プロジェクト: DmitrySigaev/ncbi
CRef< COrg_ref > GetCommonTax(CCdCore* cd, bool useRootWhenNoTaxInfo)
{
	int comTax = 0;
	CRef< COrg_ref > orgRef;
	CTaxon1 taxServer;
	if (!taxServer.Init())
		return orgRef;

	bool is_species;
	bool is_uncultured;
	string blast_name;
	int num = cd->GetNumRows();

	for (int i = 0; i < num; i++)
	{
		TGi gi = INVALID_GI;
		cd->GetGI(i,gi,false);
		int taxid = 0;
		if (gi > ZERO_GI)
			taxServer.GetTaxId4GI(gi, taxid);
		if (taxid == 0)
		{
			CRef< CBioseq > bioseq;
			if (cd->GetBioseqForRow(i, bioseq))
			{
				taxid = GetTaxIdInBioseq(*bioseq);
			}
		}

		if (taxid > 0)
		{
			if (comTax == 0)
				comTax = taxid;
			else
			{
				int joined = taxServer.Join(comTax, taxid);
				if (joined == 0)
				{
					LOG_POST("Failed to join two taxids:"<<comTax<<" and "<<taxid<<". The latter one is ignored.");
				}
				else
					comTax = joined;
			}
		}
		if (comTax == 1) //reach root
			break;
	}

    //  The condition 'comTax == 0' is true only if no row satisfied (taxid > 0) above.
    //  Use root tax node as common tax node unless told not to.
	if (comTax == 0 && useRootWhenNoTaxInfo)
		comTax = 1;

	orgRef = new COrg_ref;
    if (comTax > 0) {
        orgRef->Assign(*taxServer.GetOrgRef(comTax, is_species, is_uncultured, blast_name));
    } else {
        orgRef.Reset();
    }
	return orgRef;
}
コード例 #3
0
ファイル: feature_edit.cpp プロジェクト: svn2github/ncbi_tk
CRef<CSeq_feat> CFeatTrim::Apply(const CSeq_feat& feat,
    const CRange<TSeqPos>& range)
{
    CRef<CSeq_loc> loc = Ref(new CSeq_loc());
    loc->Assign(feat.GetLocation());

    const TSeqPos from = range.GetFrom();
    const TSeqPos to = range.GetTo();

    const bool set_partial = true;

    x_TrimLocation(from, to, set_partial, loc);
    if (loc->IsNull()) {
        return Ref(new CSeq_feat());
    }

    // Create a new seq-feat with the trimmed location
    CRef<CSeq_feat> new_sf(new CSeq_feat());
    new_sf->Assign(feat);
    new_sf->SetLocation(*loc);
    if (!loc->IsNull() &&
        (loc->IsPartialStart(eExtreme_Biological) || 
        loc->IsPartialStop(eExtreme_Biological))) {
        new_sf->SetPartial(true);
    }


    // If Cdregion need to consider changes in frameshift
    if (new_sf->GetData().IsCdregion()) {
        const TSeqPos offset = x_GetStartOffset(feat, from, to);
        x_UpdateFrame(offset, new_sf->SetData().SetCdregion());

        if (new_sf->SetData().SetCdregion().IsSetCode_break()) {
            // iterate over code breaks and remove if they fall outside the range
            list<CRef<CCode_break>>& code_breaks = new_sf->SetData().SetCdregion().SetCode_break();
            code_breaks.remove_if(SOutsideRange(from,to));
            if (code_breaks.empty()) {
                new_sf->SetData().SetCdregion().ResetCode_break();
            }
            else {
                const auto strand = loc->GetStrand();
                // Trim the 3' end
                if (strand != eNa_strand_minus) {
                    for (auto code_break : code_breaks) {
                        const TSeqPos cb_to = code_break->GetLoc().GetTotalRange().GetTo();
                        if (cb_to > to) {
                            x_TrimCodeBreak(from, to, *code_break);
                        }
                    }
                }
                else { // strand == eNa_strand_minus
                    for (auto code_break : code_breaks) {
                        const TSeqPos cb_from = code_break->GetLoc().GetTotalRange().GetFrom();
                        if (cb_from < from) {
                            x_TrimCodeBreak(from, to, *code_break);
                        }
                    }
                } 
            }
        }
    }
    else 
    if (new_sf->GetData().GetSubtype() == CSeqFeatData::eSubtype_tRNA) {
        auto& rna = new_sf->SetData().SetRna();
        if (rna.IsSetExt() && rna.GetExt().IsTRNA()) {
            x_TrimTrnaExt(from, to, rna.SetExt().SetTRNA());
        }
    }
    return new_sf;
}