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

Go to the SVN repository for this file.

1 /* $Id: bed_annot_assembler.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: Iterate through file names matching a given glob pattern
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbifile.hpp>
35 
38 
45 
47 #include "featid_generator.hpp"
48 #include "bed_annot_assembler.hpp"
49 #include "bed_import_data.hpp"
50 
51 #include <assert.h>
52 
55 
56 // ============================================================================
58  CImportMessageHandler& errorReporter):
59 // ============================================================================
60  CFeatAnnotAssembler(errorReporter)
61 {
63 }
64 
65 // ============================================================================
67 // ============================================================================
68 {
69 }
70 
71 // ============================================================================
72 void
74  const CFeatImportData& record_,
75  CSeq_annot& annot)
76 // ============================================================================
77 {
78  assert(dynamic_cast<const CBedImportData*>(&record_));
79  const CBedImportData& record = static_cast<const CBedImportData&>(record_);
80 
81  CRef<CSeq_feat> pGene(0), pMrna(0), pCds(0);
82 
83  const auto& geneLocation = record.ChromLocation();
84  if (!geneLocation.IsNull()) {
85  pGene.Reset(new CSeq_feat);
86  //pGene->SetData().SetGene();
87  pGene->SetData().SetRegion(record.Name());
88  pGene->SetLocation().Assign(geneLocation);
89 
90  const auto& displayData = record.DisplayData();
91  if (displayData.IsSetData()) {
92  CRef<CUser_object> pDisplayData(new CUser_object);
93  pDisplayData->Assign(displayData);
94  pGene->SetExts().push_back(pDisplayData);
95  }
96 
97  pGene->SetId(*mpIdGenerator->GetIdFor("gene"));
98  annot.SetData().SetFtable().push_back(pGene);
99  }
100 
101  const auto mRnaLocation =
102  record.BlocksLocation().Merge(CSeq_loc::fMerge_All, nullptr);
103  if (!mRnaLocation->IsNull()) {
104  pMrna.Reset(new CSeq_feat);
105  //pMrna->SetData().SetRna().SetType(CRNA_ref::eType_mRNA);
106  pMrna->SetData().SetRegion(record.Name());
107  pMrna->SetLocation(). Assign(*mRnaLocation);
108  pMrna->SetId(*mpIdGenerator->GetIdFor("mrna"));
109  annot.SetData().SetFtable().push_back(pMrna);
110  }
111 
112  CRef<CSeq_loc> pCdsLocation(new CSeq_loc);
113  pCdsLocation->Assign(record.ThickLocation());
114  if (!mRnaLocation->IsNull()) {
115  CRef<CSeq_loc> pIntersection = pCdsLocation->Intersect(
116  *mRnaLocation, 0, nullptr);
117  pCdsLocation->Assign(*pIntersection);
118  }
119  if (!pCdsLocation->IsNull()) {
120  pCds.Reset(new CSeq_feat);
121  //pCds->SetData().SetCdregion();
122  pCds->SetData().SetRegion(record.Name());
123  pCds->SetLocation().Assign(*pCdsLocation);
124  pCds->SetId(*mpIdGenerator->GetIdFor("cds"));
125  annot.SetData().SetFtable().push_back(pCds);
126  }
127 
128  if (pGene && pMrna) {
129  pGene->AddSeqFeatXref(pMrna->GetId());
130  pMrna->AddSeqFeatXref(pGene->GetId());
131  }
132  if (pGene && pCds) {
133  pGene->AddSeqFeatXref(pCds->GetId());
134  pCds->AddSeqFeatXref(pGene->GetId());
135  }
136  if (pMrna && pCds) {
137  pMrna->AddSeqFeatXref(pCds->GetId());
138  pCds->AddSeqFeatXref(pMrna->GetId());
139  }
140 }
141 
142 
143 // ============================================================================
144 void
146  const CAnnotImportData& annotInfo,
147  CSeq_annot& annot)
148  // ============================================================================
149 {
150  auto description = annotInfo.ValueOf("description");
151  if (!description.empty()) {
152  annot.SetTitleDesc(description);
153  }
154  auto name = annotInfo.ValueOf("name");
155  if (!name.empty()) {
156  annot.SetNameDesc(name);
157  }
158 
159  CRef<CUser_object> pTrackData(new CUser_object());
160  pTrackData->SetType().SetStr("Track Data");
161  pTrackData->SetData();
162  for (auto info: annotInfo) {
163  pTrackData->AddField(info.first, info.second);
164  }
165  CRef<CAnnotdesc> user(new CAnnotdesc());
166  user->SetUser(*pTrackData);
167  annot.SetDesc().Set().push_back(user);
168 }
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
USING_NCBI_SCOPE
std::string ValueOf(const std::string &) const
CAnnotdesc –.
Definition: Annotdesc.hpp:66
unique_ptr< CFeatureIdGenerator > mpIdGenerator
virtual void FinalizeAnnot(const CAnnotImportData &, CSeq_annot &) override
void ProcessRecord(const CFeatImportData &, CSeq_annot &) override
CBedAnnotAssembler(CImportMessageHandler &)
const CSeq_loc & ChromLocation() const
const CSeq_loc & BlocksLocation() const
const std::string & Name() const
const CSeq_loc & ThickLocation() const
const CUser_object & DisplayData() const
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
bool AddSeqFeatXref(const CSeqFeatXref::TId &id)
Definition: Seq_feat.cpp:279
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Override Assign() to incorporate cache invalidation.
Definition: Seq_loc.cpp:337
CRef< CSeq_loc > Merge(TOpFlags flags, ISynonymMapper *syn_mapper) const
All functions create and return a new seq-loc object.
Definition: Seq_loc.cpp:5037
CRef< CSeq_loc > Intersect(const CSeq_loc &other, TOpFlags flags, ISynonymMapper *syn_mapper) const
Find the intersection with the seq-loc, merge/sort resulting ranges depending on flags.
Definition: Seq_loc.cpp:5183
@ fMerge_All
Definition: Seq_loc.hpp:331
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TData & SetData(void)
Assign a value to Data data member.
void SetType(TType &value)
Assign a value to Type data member.
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
const TId & GetId(void) const
Get the Id member data.
Definition: Seq_feat_.hpp:904
void SetId(TId &value)
Assign a value to Id data member.
Definition: Seq_feat_.cpp:73
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
virtual void Reset(void)
Reset the whole object.
Definition: Seq_loc_.cpp:59
bool IsNull(void) const
Check if variant Null is selected.
Definition: Seq_loc_.hpp:504
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_annot_.cpp:244
void SetDesc(TDesc &value)
Assign a value to Desc data member.
Definition: Seq_annot_.cpp:223
TUser & SetUser(void)
Select the variant.
Definition: Annotdesc_.cpp:190
static MDB_envinfo info
Definition: mdb_load.c:37
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
#define assert(x)
Definition: srv_diag.hpp:58
Modified on Wed Apr 17 13:09:51 2024 by modify_doxy.py rev. 669887