seq_feat_handle.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: seq_feat_handle.cpp,v $
  4.  * PRODUCTION Revision 1000.0  2004/06/01 19:25:57  gouriano
  5.  * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: seq_feat_handle.cpp,v 1000.0 2004/06/01 19:25:57 gouriano Exp $
  10. * ===========================================================================
  11. *
  12. *                            PUBLIC DOMAIN NOTICE
  13. *               National Center for Biotechnology Information
  14. *
  15. *  This software/database is a "United States Government Work" under the
  16. *  terms of the United States Copyright Act.  It was written as part of
  17. *  the author's official duties as a United States Government employee and
  18. *  thus cannot be copyrighted.  This software/database is freely available
  19. *  to the public for use. The National Library of Medicine and the U.S.
  20. *  Government have not placed any restriction on its use or reproduction.
  21. *
  22. *  Although all reasonable efforts have been taken to ensure the accuracy
  23. *  and reliability of the software and data, the NLM and the U.S.
  24. *  Government do not and cannot warrant the performance or results that
  25. *  may be obtained by using this software or data. The NLM and the U.S.
  26. *  Government disclaim all warranties, express or implied, including
  27. *  warranties of performance, merchantability or fitness for any particular
  28. *  purpose.
  29. *
  30. *  Please cite the author in any work or product based on this material.
  31. *
  32. * ===========================================================================
  33. *
  34. * Author: Aleksey Grichenko, Eugene Vasilchenko
  35. *
  36. * File Description:
  37. *   Seq-feat handle
  38. *
  39. */
  40. #include <ncbi_pch.hpp>
  41. #include <objmgr/seq_feat_handle.hpp>
  42. #include <objmgr/scope.hpp>
  43. #include <objmgr/impl/seq_annot_info.hpp>
  44. BEGIN_NCBI_SCOPE
  45. BEGIN_SCOPE(objects)
  46. CSeq_feat_Handle::CSeq_feat_Handle(void)
  47.     : m_AnnotInfoType(eType_null)
  48. {
  49.     return;
  50. }
  51. CSeq_feat_Handle::CSeq_feat_Handle(CScope& scope,
  52.                                    const CSeq_annot_Info& annot_info,
  53.                                    size_t index)
  54.     : m_Scope(scope),
  55.       m_Annot(&annot_info),
  56.       m_AnnotInfoType(eType_Seq_annot_Info),
  57.       m_Index(index)
  58. {
  59.     return;
  60. }
  61. CSeq_feat_Handle::CSeq_feat_Handle(CScope& scope,
  62.                                    const CSeq_annot_SNP_Info& snp_info,
  63.                                    size_t index)
  64.     : m_Scope(scope),
  65.       m_Annot(&snp_info.GetParentSeq_annot_Info()),
  66.       m_AnnotInfoType(eType_Seq_annot_SNP_Info),
  67.       m_Index(index)
  68. {
  69.     return;
  70. }
  71. CSeq_feat_Handle::~CSeq_feat_Handle(void)
  72. {
  73.     return;
  74. }
  75. const SSNP_Info& CSeq_feat_Handle::x_GetSNP_Info(void) const
  76. {
  77.     _ASSERT(m_AnnotInfoType == eType_Seq_annot_SNP_Info);
  78.     return m_Annot->x_GetSNP_annot_Info().GetSNP_Info(m_Index);
  79. }
  80. const CSeq_feat& CSeq_feat_Handle::x_GetSeq_feat(void) const
  81. {
  82.     _ASSERT(m_AnnotInfoType == eType_Seq_annot_Info);
  83.     return m_Annot->GetAnnotObject_Info(m_Index).GetFeat();
  84. }
  85. CConstRef<CSeq_feat> CSeq_feat_Handle::GetSeq_feat(void) const
  86. {
  87.     switch (m_AnnotInfoType) {
  88.     case eType_Seq_annot_Info:
  89.         {
  90.             return ConstRef(&x_GetSeq_feat());
  91.         }
  92.     case eType_Seq_annot_SNP_Info:
  93.         {
  94.             return x_GetSNP_Info().
  95.                 CreateSeq_feat(m_Annot->x_GetSNP_annot_Info());
  96.         }
  97.     default:
  98.         {
  99.             return CConstRef<CSeq_feat>(0);
  100.         }
  101.     }
  102. }
  103. CSeq_annot_Handle CSeq_feat_Handle::GetAnnot(void) const
  104. {
  105.     if ( m_Annot ) {
  106.         return CSeq_annot_Handle(m_Scope.GetScope(), *m_Annot);
  107.     }
  108.     return CSeq_annot_Handle();
  109. }
  110. CSeq_feat_Handle::TRange CSeq_feat_Handle::GetRange(void) const
  111. {
  112.     switch (m_AnnotInfoType) {
  113.     case eType_Seq_annot_Info:
  114.         {
  115.             return x_GetSeq_feat().GetLocation().GetTotalRange();
  116.         }
  117.     case eType_Seq_annot_SNP_Info:
  118.         {
  119.             const SSNP_Info& snp_info = x_GetSNP_Info();
  120.             return TRange(snp_info.GetFrom(), snp_info.GetTo());
  121.         }
  122.     default:
  123.         {
  124.             return TRange::GetEmpty();
  125.         }
  126.     }
  127. }
  128. CSeq_id::TGi CSeq_feat_Handle::GetGi(void) const
  129. {
  130.     _ASSERT(m_AnnotInfoType == eType_Seq_annot_SNP_Info);
  131.     return m_Annot->x_GetSNP_annot_Info().GetGi();
  132. }
  133. size_t CSeq_feat_Handle::GetAllelesCount(void) const
  134. {
  135.     const SSNP_Info& snp = x_GetSNP_Info();
  136.     size_t count = 0;
  137.     for (; count < SSNP_Info::kMax_AllelesCount; ++count) {
  138.         if (snp.m_AllelesIndices[count] == SSNP_Info::kNo_AlleleIndex) {
  139.             break;
  140.         }
  141.     }
  142.     return count;
  143. }
  144. string CSeq_feat_Handle::GetAllele(size_t index) const
  145. {
  146.     _ASSERT(index < SSNP_Info::kMax_AllelesCount);
  147.     const SSNP_Info& snp = x_GetSNP_Info();
  148.     _ASSERT(snp.m_AllelesIndices[index] != SSNP_Info::kNo_AlleleIndex);
  149.     return m_Annot->x_GetSNP_annot_Info().
  150.         x_GetAllele(snp.m_AllelesIndices[index]);
  151. }
  152. END_SCOPE(objects)
  153. END_NCBI_SCOPE
  154. /*
  155.  * ===========================================================================
  156.  * $Log: seq_feat_handle.cpp,v $
  157.  * Revision 1000.0  2004/06/01 19:25:57  gouriano
  158.  * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
  159.  *
  160.  * Revision 1.2  2004/05/21 21:42:13  gorelenk
  161.  * Added PCH ncbi_pch.hpp
  162.  *
  163.  * Revision 1.1  2004/05/04 18:06:06  grichenk
  164.  * Initial revision
  165.  *
  166.  *
  167.  * ===========================================================================
  168.  */