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

Go to the SVN repository for this file.

1 /* $Id: feat_util.cpp 86362 2019-05-02 15:04:11Z ludwigf $
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  * Author: Frank Ludwig
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbifile.hpp>
36 #include "feat_util.hpp"
37 
40 
41 // ============================================================================
42 bool
44  const CSeq_annot& annot)
45 // ============================================================================
46 {
47  return (annot.IsFtable() && !annot.GetData().GetFtable().empty());
48 }
49 
50 
51 // ============================================================================
54  const CSeq_loc& lhs,
55  const CSeq_loc& rhs)
56 // ============================================================================
57 {
58  CRef<CSeq_loc> pMerged(new CSeq_loc);
59  pMerged->Assign(lhs);
60  if (pMerged->IsNull()) {
61  if (!rhs.IsNull()) {
62  pMerged->Assign(rhs);
63  }
64  }
65  else {
66  if (!rhs.IsNull()) {
67  pMerged = lhs.Add(rhs, CSeq_loc::fSortAndMerge_All, nullptr);
68  }
69  }
70  return pMerged;
71 }
72 
73 // ============================================================================
76  const CSeq_id& id,
77  const string& codeBreakStr)
78 // ============================================================================
79 {
80  CRef<CCode_break> pCodeBreak;
81 
82  const string cdstr_start = "(pos:";
83  const string cdstr_div = ",aa:";
84  const string cdstr_end = ")";
85 
86  if (!NStr::StartsWith(codeBreakStr, cdstr_start)
87  || !NStr::EndsWith(codeBreakStr, cdstr_end)) {
88  return pCodeBreak;
89  }
90  size_t pos_start = cdstr_start.length();
91  size_t pos_stop = codeBreakStr.find(cdstr_div);
92  string posstr = codeBreakStr.substr(pos_start, pos_stop-pos_start);
93  string aaa = codeBreakStr.substr(pos_stop+cdstr_div.length());
94  aaa = aaa.substr(0, aaa.length()-cdstr_end.length());
95 
96  const string posstr_compl = "complement(";
97  ENa_strand strand = eNa_strand_plus;
98  if (NStr::StartsWith(posstr, posstr_compl)) {
99  posstr = posstr.substr(posstr_compl.length());
100  posstr = posstr.substr(0, posstr.length()-1);
101  strand = eNa_strand_minus;
102  }
103  const string posstr_div = "..";
104  size_t pos_div = posstr.find(posstr_div);
105  if (pos_div == string::npos) {
106  return pCodeBreak;
107  }
108 
109  int from, to;
110  try {
111  from = NStr::StringToInt(posstr.substr(0, pos_div))-1;
112  to = NStr::StringToInt(posstr.substr(pos_div + posstr_div.length()))-1;
113  }
114  catch(...) {
115  return pCodeBreak;
116  }
117  int aaCode = 'U'; // for now
118 
119  pCodeBreak.Reset(new CCode_break);
120  pCodeBreak->SetAa().SetNcbieaa(aaCode);
121  auto& cbLoc = pCodeBreak->SetLoc().SetInt();
122  cbLoc.SetId().Assign(id);
123  cbLoc.SetFrom(from);
124  cbLoc.SetTo(to);
125  cbLoc.SetStrand(strand);
126 
127  return pCodeBreak;
128 }
129 
CCode_break –.
Definition: Code_break.hpp:66
bool IsFtable(void) const
Definition: Seq_annot.cpp:177
static CRef< CCode_break > MakeCodeBreak(const CSeq_id &, const std::string &)
Definition: feat_util.cpp:75
static bool ContainsData(const CSeq_annot &annot)
Definition: feat_util.cpp:43
static CRef< CSeq_loc > AddLocations(const CSeq_loc &, const CSeq_loc &)
Definition: feat_util.cpp:53
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Override Assign() to incorporate cache invalidation.
Definition: Seq_loc.cpp:337
void Add(const CSeq_loc &other)
Simple adding of seq-locs.
Definition: Seq_loc.cpp:3875
@ fSortAndMerge_All
Definition: Seq_loc.hpp:334
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
void SetAa(TAa &value)
Assign a value to Aa data member.
void SetLoc(TLoc &value)
Assign a value to Loc data member.
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
bool IsNull(void) const
Check if variant Null is selected.
Definition: Seq_loc_.hpp:504
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:621
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Modified on Wed Mar 27 11:20:23 2024 by modify_doxy.py rev. 669887