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

Go to the SVN repository for this file.

1 /* $Id: fasta_retrieve_job.cpp 39642 2017-10-23 16:51:10Z katargir $
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/bioseq_handle.hpp>
35 #include <objmgr/bioseq_ci.hpp>
36 #include <objmgr/util/sequence.hpp>
37 
41 
46 
48 
51 
53  const vector<pair<CBioseq_Handle, string> >& handles)
54  : CTextRetrieveJob(context), m_Handles(handles)
55 {
56 }
57 
59 {
60 }
61 
63 {
64  for (auto& h : m_Handles) {
66  if (h.first)
67  x_DumpBioseq(h.first);
68  else
69  x_AddItem(nullptr);
70  }
71 
73 
74  return eCompleted;
75 }
76 
78 {
79  CFastaTitleItem* titleItem = new CFastaTitleItem(h);
80  CCompositeTextItem* expanded = new CCompositeTextItem();
81  x_AddItem(new CExpandItem(titleItem, expanded, true));
82 
83  expanded->AddItem(new CFastaTitleItem(h), false);
84  TSeqPos seqLength = h.GetBioseqLength();
85  size_t blockSize = kFastaSeqLine*kFastaSeqBlockSize;
86  size_t blockCount = (seqLength + blockSize - 1) / blockSize;
87 
88  vector<ITextItem*> items(blockCount, 0);
89 
90  for (size_t i = 0; i < blockCount; ++i) {
92  size_t from = i*blockSize;
93  size_t count = (i + 1 == blockCount) ? seqLength - from : blockSize;
94  CFastaSeqHdrItem* seqCollapsed = new CFastaSeqHdrItem(from, count, *titleItem);
95  CFastaSeqBlockItem* seqExpanded = new CFastaSeqBlockItem(h, from, count);
96  expanded->AddItem(new CExpandItem(seqCollapsed, seqExpanded, (blockCount == 1)), false);
97  }
98 }
99 
101  : CTextRetrieveJob(context), m_Loc(&loc), m_Scope(&scope)
102 {
103 }
104 
106 {
107 }
108 
110 {
111  if (!m_Loc) return eCompleted;
112 
113  for( CSeq_loc_CI it(*m_Loc); it; ++it) {
115 
116  CBioseq_Handle handle = m_Scope->GetBioseqHandle(it.GetSeq_id());
117  if (!handle)
118  continue;
119 
120  CConstRef<CSeq_loc> loc = it.GetRangeAsSeq_loc();
121  CFastaTitleItem* titleItem = new CFastaTitleItem(handle, loc);
122  CCompositeTextItem* expanded = new CCompositeTextItem();
123  x_AddItem(new CExpandItem(titleItem, expanded));
124 
125  expanded->AddItem(new CFastaTitleItem(handle, loc), false);
126 
127  CSeq_loc_CI::TRange range = it.GetRange();
128  TSeqPos seqLength = range.GetLength();
129  size_t blockSize = kFastaSeqLine*kFastaSeqBlockSize;
130  size_t blockCount = (seqLength + blockSize - 1)/blockSize;
131 
132  for (size_t i = 0; i < blockCount; ++i) {
134 
135  size_t from = range.GetFrom() + i*blockSize;
136  size_t count = (i + 1 == blockCount) ? seqLength - i*blockSize : blockSize;
137  CFastaSeqHdrItem* seqCollapsed = new CFastaSeqHdrItem(from, count, *titleItem);
138  CFastaSeqBlockItem* seqExpanded = new CFastaSeqBlockItem(handle, from, count);
139  expanded->AddItem(new CExpandItem(seqCollapsed, seqExpanded, (blockCount == 1)), false);
140  }
141  }
142 
143  x_CreateResult();
144 
145  return eCompleted;
146 }
147 
static CRef< CScope > m_Scope
CBioseq_Handle –.
void AddItem(ITextItem *item, bool updatePositions=true)
virtual EJobState x_Run()
vector< pair< objects::CBioseq_Handle, string > > m_Handles
CFastaRetrieveJob(CTextPanelContext &context, const vector< pair< objects::CBioseq_Handle, string > > &handles)
void x_DumpBioseq(const objects::CBioseq_Handle &h)
virtual EJobState x_Run()
CConstRef< objects::CSeq_loc > m_Loc
CFastaRetrieveLocJob(CTextPanelContext &context, const objects::CSeq_loc &loc, objects::CScope &scope)
CRef< objects::CScope > m_Scope
CScope –.
Definition: scope.hpp:92
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:453
void x_CheckCancelled() const
void x_AddItem(ITextItem *item)
USING_SCOPE(objects)
const int kFastaSeqLine
const int kFastaSeqBlockSize
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
@ eCompleted
Definition: app_job.hpp:89
TSeqPos GetBioseqLength(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
int i
range(_Ty, _Ty) -> range< _Ty >
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Sat Jun 15 11:50:36 2024 by modify_doxy.py rev. 669887