feature.cpp
来自「ncbi源码」· C++ 代码 · 共 710 行 · 第 1/2 页
CPP
710 行
/* * =========================================================================== * PRODUCTION $Log: feature.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 19:25:23 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: feature.cpp,v 1000.1 2004/06/01 19:25:23 gouriano Exp $* ===========================================================================** PUBLIC DOMAIN NOTICE* National Center for Biotechnology Information** This software/database is a "United States Government Work" under the* terms of the United States Copyright Act. It was written as part of* the author's official duties as a United States Government employee and* thus cannot be copyrighted. This software/database is freely available* to the public for use. The National Library of Medicine and the U.S.* Government have not placed any restriction on its use or reproduction.** Although all reasonable efforts have been taken to ensure the accuracy* and reliability of the software and data, the NLM and the U.S.* Government do not and cannot warrant the performance or results that* may be obtained by using this software or data. The NLM and the U.S.* Government disclaim all warranties, express or implied, including* warranties of performance, merchantability or fitness for any particular* purpose.** Please cite the author in any work or product based on this material.** ===========================================================================** Author: Clifford Clausen** File Description:* Sequence utilities*/#include <ncbi_pch.hpp>#include <serial/object.hpp>#include <serial/objistr.hpp>#include <serial/serial.hpp>#include <serial/iterator.hpp>#include <serial/enumvalues.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objmgr/seq_vector.hpp>#include <objects/seqfeat/Seq_feat.hpp>#include <objects/seqfeat/SeqFeatXref.hpp>#include <objects/seqfeat/Imp_feat.hpp>#include <objects/seqfeat/Prot_ref.hpp>#include <objects/seqfeat/Gene_ref.hpp>#include <objects/seqfeat/RNA_ref.hpp>#include <objects/seqfeat/Org_ref.hpp>#include <objects/seqfeat/Rsite_ref.hpp>#include <objects/seqfeat/Trna_ext.hpp>#include <objects/seqfeat/Cdregion.hpp>#include <objects/seqfeat/Gb_qual.hpp>#include <objects/seqfeat/BioSource.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/seqport_util.hpp>#include <objects/seq/IUPACaa.hpp>#include <objects/seq/NCBIstdaa.hpp>#include <objects/seq/NCBIeaa.hpp>#include <objects/seq/NCBI8aa.hpp>#include <objects/seq/Pubdesc.hpp>#include <objects/seq/Heterogen.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_loc_mix.hpp>#include <objects/seqfeat/SeqFeatData.hpp>#include <objects/general/Dbtag.hpp>#include <objects/general/Object_id.hpp>#include <objects/general/User_object.hpp>#include <objects/pub/Pub_equiv.hpp>#include <objects/pub/Pub.hpp>#include <objects/pub/Pub_set.hpp>#include <objmgr/util/feature.hpp>#include <objmgr/util/sequence.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)BEGIN_SCOPE(feature)USING_SCOPE(sequence);// Appends a label onto "label" based on the type of feature void s_GetTypeLabel(const CSeq_feat& feat, string* label){ string tlabel; // Determine typelabel CSeqFeatData::ESubtype idx = feat.GetData().GetSubtype(); if ( idx != CSeqFeatData::eSubtype_bad ) { tlabel = feat.GetData().GetKey(); if (feat.GetData().Which() == CSeqFeatData::e_Imp && tlabel != "CDS") { tlabel = "[" + tlabel + "]"; } else if (feat.GetData().Which() == CSeqFeatData::e_Region && feat.GetData().GetRegion() == "Domain" && feat.IsSetComment() ) { tlabel = "Domain"; } } else if (feat.GetData().Which() == CSeqFeatData::e_Imp) { tlabel = "[" + feat.GetData().GetImp().GetKey() + "]"; } else { tlabel = "Unknown=0"; } *label += tlabel; }// Appends a label onto tlabel for a CSeqFeatData::e_Cdregioninlinestatic void s_GetCdregionLabel(const CSeq_feat& feat, string* tlabel, CScope* scope){ // Check that tlabel exists and that the feature data is Cdregion if (!tlabel || !feat.GetData().IsCdregion()) { return; } const CGene_ref* gref = 0; const CProt_ref* pref = 0; // Look for CProt_ref object to create a label from if (feat.IsSetXref()) { ITERATE ( CSeq_feat::TXref, it, feat.GetXref()) { switch ((**it).GetData().Which()) { case CSeqFeatData::e_Prot: pref = &(**it).GetData().GetProt(); break; case CSeqFeatData::e_Gene: gref = &(**it).GetData().GetGene(); break; default: break; } } } // Try and create a label from a CProt_ref in CSeqFeatXref in feature if (pref) { pref->GetLabel(tlabel); return; } // Try and create a label from a CProt_ref in the feat product and // return if found if (feat.IsSetProduct() && scope) { try { const CSeq_id& id = GetId(feat.GetProduct(), scope); CBioseq_Handle hnd = scope->GetBioseqHandle(id); if (hnd) { const CBioseq& seq = hnd.GetBioseq(); // Now look for a CProt_ref feature in seq and // if found call GetLabel() on the CProt_ref CTypeConstIterator<CSeqFeatData> it = ConstBegin(seq); for (;it; ++it) { if (it->Which() == CSeqFeatData::e_Prot) { it->GetProt().GetLabel(tlabel); return; } } } } catch (CNotUnique&) {} } // Try and create a label from a CGene_ref in CSeqFeatXref in feature if (gref) { gref->GetLabel(tlabel); } // check to see if the CDregion is just an open reading frame if (feat.GetData().GetCdregion().IsSetOrf() && feat.GetData().GetCdregion().GetOrf()) { string str("open reading frame: "); switch (feat.GetData().GetCdregion().GetFrame()) { case CCdregion::eFrame_not_set: str += "frame not set; "; break; case CCdregion::eFrame_one: str += "frame 1; "; break; case CCdregion::eFrame_two: str += "frame 2; "; break; case CCdregion::eFrame_three: str += "frame 3; "; break; } switch (sequence::GetStrand(feat.GetLocation())) { case eNa_strand_plus: str += "positive strand"; break; case eNa_strand_minus: str += "negative strand"; break; case eNa_strand_both: str += "both strands"; break; case eNa_strand_both_rev: str += "both strands (reverse)"; break; default: str += "strand unknown"; break; } *tlabel += str; }}inlinestatic void s_GetRnaRefLabelFromComment(const CSeq_feat& feat, string* label, ELabelType label_type, const string* type_label){ if (feat.IsSetComment() && !feat.GetComment().empty()) { if (label_type == eContent && type_label != 0 && feat.GetComment().find(*type_label) == string::npos) { *label += *type_label + "-" + feat.GetComment(); } else { *label += feat.GetComment(); } } else if (type_label) { *label += *type_label; }}// Appends a label onto "label" for a CRNA_refinlinestatic void s_GetRnaRefLabel(const CSeq_feat& feat, string* label, ELabelType label_type, const string* type_label){ // Check that label exists and that feature data is type RNA-ref if (!label || !feat.GetData().IsRna()) { return; } const CRNA_ref& rna = feat.GetData().GetRna(); // Append the feature comment, the type label, or both and return // if Ext is not set if (!rna.IsSetExt()) { s_GetRnaRefLabelFromComment(feat, label, label_type, type_label); return; } // Append a label based on the type of the type of the ext of the // CRna_ref string tmp_label; switch (rna.GetExt().Which()) { case CRNA_ref::C_Ext::e_not_set: s_GetRnaRefLabelFromComment(feat, label, label_type, type_label); break; case CRNA_ref::C_Ext::e_Name: tmp_label = rna.GetExt().GetName(); if (label_type == eContent && type_label != 0 && tmp_label.find(*type_label) == string::npos) { *label += *type_label + "-" + tmp_label; } else if (!tmp_label.empty()) { *label += tmp_label; } else if (type_label) { *label += *type_label; } break; case CRNA_ref::C_Ext::e_TRNA: { if ( !rna.GetExt().GetTRNA().IsSetAa() ) { s_GetRnaRefLabelFromComment(feat, label, label_type, type_label); break; } try { CTrna_ext::C_Aa::E_Choice aa_code_type = rna.GetExt().GetTRNA().GetAa().Which(); int aa_code; CSeq_data in_seq, out_seq; string str_aa_code; switch (aa_code_type) { case CTrna_ext::C_Aa::e_Iupacaa: // Convert an e_Iupacaa code to an Iupacaa3 code for the label aa_code = rna.GetExt().GetTRNA().GetAa().GetIupacaa(); str_aa_code = CSeqportUtil::GetCode(CSeq_data::e_Iupacaa, aa_code); in_seq.SetIupacaa().Set() = str_aa_code; CSeqportUtil::Convert(in_seq, &out_seq, CSeq_data::e_Ncbistdaa); if (out_seq.GetNcbistdaa().Get().size()) { aa_code = out_seq.GetNcbistdaa().Get()[0]; tmp_label = CSeqportUtil::GetIupacaa3(aa_code); } else { s_GetRnaRefLabelFromComment(feat, label, label_type, type_label); } break; case CTrna_ext::C_Aa::e_Ncbieaa: // Convert an e_Ncbieaa code to an Iupacaa3 code for the label aa_code = rna.GetExt().GetTRNA().GetAa().GetNcbieaa(); str_aa_code = CSeqportUtil::GetCode(CSeq_data::e_Ncbieaa, aa_code); in_seq.SetNcbieaa().Set() = str_aa_code; CSeqportUtil::Convert(in_seq, &out_seq, CSeq_data::e_Ncbistdaa); if (out_seq.GetNcbistdaa().Get().size()) { aa_code = out_seq.GetNcbistdaa().Get()[0]; tmp_label = CSeqportUtil::GetIupacaa3(aa_code); } else { s_GetRnaRefLabelFromComment(feat, label, label_type, type_label); } break; case CTrna_ext::C_Aa::e_Ncbi8aa: // Convert an e_Ncbi8aa code to an Iupacaa3 code for the label aa_code = rna.GetExt().GetTRNA().GetAa().GetNcbi8aa(); tmp_label = CSeqportUtil::GetIupacaa3(aa_code); break; case CTrna_ext::C_Aa::e_Ncbistdaa: // Convert an e_Ncbistdaa code to an Iupacaa3 code for the label aa_code = rna.GetExt().GetTRNA().GetAa().GetNcbistdaa(); tmp_label = CSeqportUtil::GetIupacaa3(aa_code); break; default: break; } // Append to label, depending on ELabelType if (label_type == eContent && type_label != 0) { *label += *type_label + "-" + tmp_label; } else if (!tmp_label.empty()) { *label += tmp_label; } else if (type_label) { *label += *type_label; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?