NCBI C++ ToolKit
sorted_proteins.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sorted_proteins.cpp 36969 2016-11-18 19:13:24Z asztalos $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 #include <objmgr/bioseq_handle.hpp>
33 #include <objmgr/util/sequence.hpp>
34 
38 
41 
43  : m_Seh(seh)
44 {
45 }
46 
47 
49 {
52 
53  string report;
54  auto iter = m_Proteins.begin();
55  auto prev = iter;
56  for (; iter != m_Proteins.end(); ++iter) {
57  if (prev != iter && !NStr::EqualCase(iter->second, prev->second)) {
58  report += "\n";
59  }
60 
61  CNcbiOstrstream oss;
62  CFastaOstream fasta_ostr(oss);
63  fasta_ostr.Write(iter->first);
64  report += CNcbiOstrstreamToString(oss);
65  prev = iter;
66  }
67 
68  CGenericReportDlg* reportdlg = new CGenericReportDlg(NULL);
69  reportdlg->SetTitle("Sorted Proteins");
70  reportdlg->SetText(ToWxString(report));
71  reportdlg->Show(true);
72 }
73 
75 {
76  m_Proteins.clear();
77 
78  for (CBioseq_CI b_iter(m_Seh, CSeq_inst::eMol_aa); b_iter; ++b_iter) {
80  if (feat_it) {
81  const CProt_ref& prot = feat_it->GetData().GetProt();
82  if (prot.IsSetName() && !prot.GetName().empty()) {
83  m_Proteins.emplace_back(*b_iter, prot.GetName().front());
84  }
85  else {
86  string feat_label;
87  feature::GetLabel(*feat_it->GetOriginalSeq_feat(), &feat_label, feature::eBoth);
88  m_Proteins.push_back(make_pair(*b_iter, feat_label));
89  }
90  }
91  else {
92  m_Proteins.push_back(make_pair(*b_iter, kEmptyStr));
93  }
94  }
95 }
96 
98 {
99  _ASSERT(!m_Proteins.empty());
100  m_Proteins.sort([](const pair<CBioseq_Handle, string>& prot1, const pair<CBioseq_Handle, string>& prot2) { return NStr::CompareCase(prot1.second, prot2.second) < 0; });
101 }
102 
@ eBoth
Both preliminary and traceback stages.
Definition: blast_def.h:332
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
FASTA-format output; see also ReadFasta in <objtools/readers/fasta.hpp>
Definition: sequence.hpp:770
CFeat_CI –.
Definition: feat_ci.hpp:64
void SetText(const wxString &text)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CSeq_entry_Handle –.
list< pair< objects::CBioseq_Handle, string > > m_Proteins
CSortedProteins(const objects::CSeq_entry_Handle &seh)
objects::CSeq_entry_Handle m_Seh
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
#define NULL
Definition: ncbistd.hpp:225
string GetLabel(const CSeq_id &id)
virtual void Write(const CSeq_entry_Handle &handle, const CSeq_loc *location=0)
Unspecified locations designate complete sequences; non-empty custom titles override the usual title ...
Definition: sequence.cpp:2727
const CSeqFeatData & GetData(void) const
CConstRef< CSeq_feat > GetOriginalSeq_feat(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
Definition: ncbistr.hpp:5325
static int CompareCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive compare of a substring with another string.
Definition: ncbistr.cpp:135
const TProt & GetProt(void) const
Get the variant data.
USING_SCOPE(objects)
SAnnotSelector –.
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Thu May 02 14:27:05 2024 by modify_doxy.py rev. 669887