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

Go to the SVN repository for this file.

1 /* $Id:
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: Liangshou Wu
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
32 #include <gui/utils/track_info.hpp>
33 
36 #include <objmgr/mapped_feat.hpp>
37 #include <util/static_map.hpp>
38 
40 
41 /// sort group index to group name
43 static const TGroupNameStr s_GroupNameStrs[] = {
44  { CCloneConcordancySorter::eConcordant, "Concordant" },
45  { CCloneConcordancySorter::eDiscordant, "Discordant" },
46  { CCloneConcordancySorter::eNotSet, "Concordancy not set" },
47  { CCloneConcordancySorter::eOther, "Others" },
48 };
49 
50 
53 
54 static const string& s_GroupIdxToName(int idx)
55 {
57  sm_GroupNameStrs.find((CCloneConcordancySorter::EGroup)idx);
58  if (iter != sm_GroupNameStrs.end()) {
59  return iter->second;
60  }
61  return kEmptyStr;
62 }
63 
64 
66 {
67  vector<string> tokens;
68  CTrackUtils::TokenizeWithEscape(sort_str, "|", tokens, true);
69  size_t num_tokens = tokens.size();
70 
71  // sort clones belonging to an explicit list of groups
72  for (size_t i = 0; i < num_tokens; ++i) {
73  if (NStr::EqualNocase(NStr::TruncateSpaces(tokens[i]), "concordant")) {
75  } else if (NStr::EqualNocase(NStr::TruncateSpaces(tokens[i]), "discordant")) {
77  } else if (NStr::EqualNocase(NStr::TruncateSpaces(tokens[i]), "notset")) {
79  } else if (NStr::EqualNocase(NStr::TruncateSpaces(tokens[i]), "other")) {
81  }
82  }
83 
84  if (m_SortGroups.empty()) {
85  // sort all clones
89  }
90 }
91 
92 
94 {
95  return s_GroupIdxToName(idx);
96 }
97 
98 
99 int CCloneConcordancySorter::GetGroupIdx(const objects::CMappedFeat& feat) const
100 {
101  EGroup idx = eInvalid;
102  const objects::CSeq_feat::TData& data = feat.GetOriginalFeature().GetData();
103  if (data.IsClone()) {
104  if (data.GetClone().IsSetConcordant()) {
105  if (data.GetClone().GetConcordant()) {
106  idx = eConcordant;
107  } else {
108  idx = eDiscordant;
109  }
110  } else {
111  idx = eNotSet;
112  }
113  if (m_SortGroups.count(idx) == 0) {
114  if (m_SortGroups.count(eOther) == 0) {
115  idx = eInvalid;
116  } else {
117  idx = eOther;
118  }
119  }
120  }
121 
122  return (int)idx;
123 }
124 
125 
128 {
129  return GetSorterDescr();
130 }
131 
132 
134 {
135  static const string kSorterName = "concordancy";
136  return kSorterName;
137 }
138 
141 {
142  return SSorterDescriptor(GetID(), "Clone Concordancy",
143  "Sort clones by concordancy");
144 }
145 
146 
147 
149 
User-defined methods of the data storage class.
CCloneConcordancySorter(const string &sort_str)
static const string & GetID()
virtual SSorterDescriptor GetThisDescr() const
Return a name for the sorter.
set< EGroup > m_SortGroups
Curently intended sorting groups.
virtual int GetGroupIdx(const objects::CMappedFeat &feat) const
Get the sorted group index for a given feature.
static SSorterDescriptor GetSorterDescr()
@ eInvalid
maybe it is valid, but not considered
virtual string GroupIdxToName(int idx) const
Convert group index into group name.
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
Definition: static_map.hpp:175
TBase::const_iterator const_iterator
Definition: static_map.hpp:179
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
bool empty() const
Definition: set.hpp:133
static const TGroupNameStr s_GroupNameStrs[]
SStaticPair< CCloneConcordancySorter::EGroup, const char * > TGroupNameStr
sort group index to group name
static const string & s_GroupIdxToName(int idx)
CStaticArrayMap< CCloneConcordancySorter::EGroup, string > TGroupNameMap
DEFINE_STATIC_ARRAY_MAP(TGroupNameMap, sm_GroupNameStrs, s_GroupNameStrs)
char data[12]
Definition: iconv.c:80
static void TokenizeWithEscape(const string &str, const string &delim, vector< string > &tokens, bool remove_escape=false)
Tokenize a string using the delim.
Definition: track_info.cpp:352
#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 EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5355
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string.
Definition: ncbistr.cpp:3177
int i
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Modified on Sun Jul 21 04:22:01 2024 by modify_doxy.py rev. 669887