Bioseq_set.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: Bioseq_set.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 19:34:50 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: Bioseq_set.cpp,v 1000.1 2004/06/01 19:34:50 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: .......
- *
- * File Description:
- * .......
- *
- * Remark:
- * This code was originally generated by application DATATOOL
- * using specifications from the ASN data definition file
- * 'seqset.asn'.
- *
- */
- // standard includes
- #include <ncbi_pch.hpp>
- #include <serial/serial.hpp>
- #include <serial/iterator.hpp>
- #include <serial/enumvalues.hpp>
- // generated includes
- #include <objects/seqset/Bioseq_set.hpp>
- #include <objects/seq/Bioseq.hpp>
- #include <objects/seq/Seq_annot.hpp> // to make KCC happy
- #include <objects/seq/Seq_inst.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objects/seqloc/Textseq_id.hpp>
- // generated classes
- BEGIN_NCBI_SCOPE
- BEGIN_objects_SCOPE // namespace ncbi::objects::
- // destructor
- CBioseq_set::~CBioseq_set(void)
- {
- }
- static bool s_is_na(const CBioseq& seq)
- {
- switch (seq.GetInst().GetMol()) {
- case CSeq_inst::eMol_dna:
- case CSeq_inst::eMol_rna:
- case CSeq_inst::eMol_na:
- return true;
- default:
- return false;
- }
- }
- static bool s_has_gb(const CSeq_id& id)
- {
- switch (id.Which()) {
- case CSeq_id::e_Genbank:
- case CSeq_id::e_Embl:
- case CSeq_id::e_Ddbj:
- case CSeq_id::e_Other:
- case CSeq_id::e_Tpg:
- case CSeq_id::e_Tpe:
- case CSeq_id::e_Tpd:
- return true;
- default:
- return false;
- }
- }
- static bool s_has_accession(const CSeq_id& id)
- {
- if (!id.GetTextseq_Id()) {
- return false;
- } else if (id.GetTextseq_Id()->IsSetAccession()) {
- return true;
- } else {
- return false;
- }
- }
- void CBioseq_set::GetLabel(string* label, ELabelType type) const
- {
- // If no label, just return
- if (!label) {
- return;
- }
- // Get type label
- if (IsSetClass() && type != eContent) {
- const CEnumeratedTypeValues* tv =
- CBioseq_set::GetTypeInfo_enum_EClass();
- const string& cn = tv->FindName(GetClass(), true);
- *label += cn;
- if (type != eType) {
- *label += ": ";
- }
- }
- if (type == eType) {
- return;
- }
- // Loop through CBioseqs looking for the best one to use for a label
- bool best_is_na = false, best_has_gb = false, best_has_accession = false;
- const CBioseq* best = 0;
- for (CTypeConstIterator<CBioseq> si(ConstBegin(*this)); si; ++si) {
- bool takeit = false, is_na, has_gb = false, has_accession = false;
- is_na = s_is_na(*si);
- for (CTypeConstIterator<CSeq_id> ii(ConstBegin(*si)); ii; ++ii) {
- has_gb = has_gb ? true : s_has_gb(*ii);
- has_accession = has_accession ? true : s_has_accession(*ii);
- }
- if (!best) {
- takeit = true;
- } else {
- bool longer = false;
- if (si->GetInst().GetLength() > best->GetInst().GetLength()) {
- longer = true;
- }
- if(best_has_accession) {
- if (has_accession) {
- if(longer) {
- takeit = true;
- }
- }
- } else if (has_accession) {
- takeit = true;
- } else if (best_has_gb) {
- if (has_gb) {
- if (longer) {
- takeit = true;
- }
- }
- } else if (has_gb) {
- takeit = true;
- } else if (best_is_na) {
- if (is_na) {
- if (longer) {
- takeit = true;
- }
- }
- } else if (is_na) {
- takeit = true;
- } else if (longer) {
- takeit = true;
- }
- }
- if (takeit) {
- best = &(*si);
- best_has_accession = has_accession;
- best_has_gb = has_gb;
- best_is_na = is_na;
- }
- }
- // Add content to label.
- if (!best) {
- *label += "(No Bioseqs)";
- } else {
- CNcbiOstrstream os;
- if (best->GetFirstId()) {
- os << best->GetFirstId()->DumpAsFasta();
- *label += CNcbiOstrstreamToString(os);
- }
- }
- }
- END_objects_SCOPE // namespace ncbi::objects::
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: Bioseq_set.cpp,v $
- * Revision 1000.1 2004/06/01 19:34:50 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- *
- * Revision 1.9 2004/05/19 17:26:48 gorelenk
- * Added include of PCH - ncbi_pch.hpp
- *
- * Revision 1.8 2002/12/30 13:21:24 clausen
- * Replaced os.str() with CNcbiOstrstreamToString(os)
- *
- * Revision 1.7 2002/10/07 17:10:54 ucko
- * Include Seq-annot.hpp to make KCC happy.
- *
- * Revision 1.6 2002/10/03 18:57:12 clausen
- * Removed extra whitespace
- *
- * Revision 1.5 2002/10/03 17:18:19 clausen
- * Added GetLabel()
- *
- * Revision 1.4 2000/11/01 20:38:33 vasilche
- * Removed ECanDelete enum and related constructors.
- *
- *
- * ===========================================================================
- */