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

Go to the SVN repository for this file.

1 /* $Id: fasta_seqblock_item.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <objmgr/seq_vector.hpp>
35 #include <objmgr/util/sequence.hpp>
36 
39 
42 
43 #include <wx/dcclient.h>
44 #include <wx/txtstrm.h>
45 
48 
49 CFastaSeqBlockItem::CFastaSeqBlockItem(const objects::CBioseq_Handle& h, size_t from, size_t length)
50  : m_Bioseq(h), m_From(from), m_Length(length)
51 {
52  CRef<CSeq_loc> loc(new CSeq_loc());
53  loc->SetInt().SetFrom(static_cast<CSeq_interval::TFrom>(m_From));
54  loc->SetInt().SetTo(static_cast<CSeq_interval::TTo>(m_From + m_Length - 1));
55 
56  try {
57  loc->SetId(*m_Bioseq.GetSeqId());
58  m_Loc = loc;
59  }
60  catch (const CObjMgrException&) {
61  }
62 }
63 
65 {
66  return (m_Length + kFastaSeqLine - 1)/kFastaSeqLine;
67 }
68 
69 void CFastaSeqBlockItem::CalcSize(wxDC& /*dc*/, CTextPanelContext* context)
70 {
71  size_t lineCount = (m_Length + kFastaSeqLine - 1)/kFastaSeqLine;
72  wxSize size = context->GetWSize();
73  m_Size.Set(context->GetLeftMargin() + size.x*kFastaSeqLine, static_cast<int>(size.y*lineCount));
74 }
75 
77 {
78  static CTextStyle errStyle(255,0,0,255,255,255,wxTRANSPARENT,false,false);
79  static string err_msg_saved;
80  string seq, err_msg;
81 
82  try {
83  CSeqVector v_seq = m_Bioseq.GetSeqVector();
84  v_seq.SetIupacCoding();
85  v_seq.GetSeqData(static_cast<TSeqPos>(m_From), static_cast<TSeqPos>(m_From + m_Length), seq);
86 
87  if (seq.length() < m_Length)
88  seq.append(string(m_Length - seq.length(), '-'));
89 
90  }
91  catch (const CException& e) {
92  err_msg = e.GetMsg();
93  }
94 
95 
96  size_t i, from, length,
97  lineCount = (m_Length + kFastaSeqLine - 1)/kFastaSeqLine;
98 
99  if (err_msg.empty()) {
100  ostream << DefaultStyle();
101 
102  for (i = 0, from = 0; i < lineCount; ++i, from += kFastaSeqLine) {
103  length = (i + 1 == lineCount) ? m_Length - from : kFastaSeqLine;
104  ostream << seq.substr(from, length) << NewLine();
105  }
106  }
107  else {
108  ostream << errStyle;
109 
110  for (i = 0, from = 0; i < lineCount; ++i, from += kFastaSeqLine) {
111  length = (i + 1 == lineCount) ? m_Length - from : kFastaSeqLine;
112  if (i == 0)
113  ostream << err_msg << NewLine();
114  else
115  ostream << string(length, '-') << NewLine();
116  }
117 
118  if (err_msg_saved != err_msg) {
119  err_msg_saved = err_msg;
120  LOG_POST(Error << "CException in CFastaSeqBlockItem::x_RenderText: " << err_msg);
121  }
122 
123  ostream << DefaultStyle();
124  }
125 }
126 
128 {
130 }
131 
133 
134 
virtual const CConstRef< CObject > GetAssosiatedObject() const
CRef< objects::CSeq_loc > m_Loc
virtual size_t GetLineCount() const
virtual void x_RenderText(CStyledTextOStream &ostream, CTextPanelContext *context) const
const objects::CBioseq_Handle m_Bioseq
virtual void CalcSize(wxDC &dc, CTextPanelContext *context)
CFastaSeqBlockItem(const objects::CBioseq_Handle &h, size_t from, size_t length)
Base class for all object manager exceptions.
CSeqVector –.
Definition: seq_vector.hpp:65
wxSize m_Size
Definition: text_item.hpp:172
wxSize GetWSize() const
virtual int GetLeftMargin() const
USING_SCOPE(objects)
const int kFastaSeqLine
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
string
Definition: cgiapp.hpp:687
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
void SetId(CSeq_id &id)
set the 'id' field in all parts of this location
Definition: Seq_loc.cpp:3474
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
void GetSeqData(TSeqPos start, TSeqPos stop, string &buffer) const
Fill the buffer string with the sequence data for the interval [start, stop).
Definition: seq_vector.cpp:304
void SetIupacCoding(void)
Set coding to either Iupacaa or Iupacna depending on molecule type.
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
Modified on Sat Dec 02 09:23:35 2023 by modify_doxy.py rev. 669887