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

Go to the SVN repository for this file.

1 /* $Id: make_cdr_prods.cpp 52206 2011-12-07 16:59:24Z ivanov $
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: Josh Cherry
27  *
28  * File Description: Make protein products of coding region features
29  *
30  */
31 
32 
33 #include <ncbi_pch.hpp>
35 
36 #include <objects/seq/Bioseq.hpp>
37 #include <objects/seq/Seq_data.hpp>
39 #include <objects/seq/Seq_inst.hpp>
40 #include <objects/seq/Seqdesc.hpp>
47 
48 #include <objmgr/scope.hpp>
49 #include <objmgr/util/feature.hpp>
50 #include <objmgr/util/sequence.hpp>
51 
52 
55 
57 
59  CBioseq_Handle handle)
60 {
61  CRef<CBioseq_set> bioseq_set(new CBioseq_set);
62  if (!annot->GetData().IsFtable()) {
63  // Is this the right thing to do?
64  // Could throw, or could return null CRef instead.
65  return bioseq_set;
66  }
67 
68  list<CRef<CSeq_feat> >& ftable = annot->SetData().SetFtable();
69 
70  NON_CONST_ITERATE (list<CRef<CSeq_feat> >, feat, ftable) {
71  if (!(*feat)->GetData().IsCdregion()) {
72  // not interested if not a Cdregion
73  continue;
74  }
75  if ((*feat)->IsSetProduct()) {
76  // already has a product; don't make new one
77  continue;
78  }
79 
80  string prot;
81  CSeqTranslator::Translate(**feat, handle.GetScope(), prot);
82  CRef<CSeq_data> seq_data(new CSeq_data(prot,
84  CRef<CSeq_inst> seq_inst(new CSeq_inst);
85  seq_inst->SetSeq_data(*seq_data);
88  seq_inst->SetLength(prot.size());
89 
90  CRef<CBioseq> bio_seq(new CBioseq);
91  string num = NStr::NumericToString(sm_Counter.Add(1));
92  // pad to five digits
93  if (num.size() < 5) {
94  num.insert(SIZE_TYPE(0), 5 - num.size(), '0');
95  }
96  string acc = "tp" + num;
97  string full_acc = "lcl|" + acc;
98  CRef<CSeq_id> id(new CSeq_id(full_acc));
99  bio_seq->SetId().push_back(id);
100  // a title
101  CRef<CSeqdesc> title(new CSeqdesc);
102  title->SetTitle(string("Translation product ") + acc);
103  bio_seq->SetDescr().Set().push_back(title);
104  // Mol_type
105  CRef<CSeqdesc> mol_type(new CSeqdesc);
106  mol_type->SetMol_type( eGIBB_mol_peptide);
107  bio_seq->SetDescr().Set().push_back(mol_type);
108 
109  // set the instance
110  bio_seq->SetInst(*seq_inst);
111 
112  // wrap this Bio_seq in an entry
113  CRef<CSeq_entry> seq_entry(new CSeq_entry);
114  seq_entry->SetSeq(*bio_seq);
115 
116  // add this entry to our Bioseq_set
117  bioseq_set->SetSeq_set().push_back(seq_entry);
118 
119  // record it as product in the annot we're handed
120  CRef<CSeq_loc> prod_loc(new CSeq_loc);
121  prod_loc->SetWhole(*id);
122  (*feat)->SetProduct(*prod_loc);
123  }
124 
125  return bioseq_set;
126 }
127 
128 
User-defined methods of the data storage class.
CAtomicCounter –.
Definition: ncbicntr.hpp:71
CBioseq_Handle –.
static CAtomicCounter sm_Counter
static CRef< objects::CBioseq_set > MakeCdrProds(CRef< objects::CSeq_annot > annot, objects::CBioseq_Handle handle)
Given an annot containing a feature table with Cdregions, translate those without products.
Definition: Seq_entry.hpp:56
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
Definition: ncbicntr.hpp:278
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
static void Translate(const string &seq, string &prot, const CGenetic_code *code, bool include_stop=true, bool remove_trailing_X=false, bool *alt_start=NULL, bool is_5prime_complete=true, bool is_3prime_complete=true)
Translate a string using a specified genetic code.
Definition: sequence.cpp:4095
CScope & GetScope(void) const
Get scope this handle belongs to.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_annot_.cpp:244
TId & SetId(void)
Assign a value to Id data member.
Definition: Bioseq_.hpp:296
TTitle & SetTitle(void)
Select the variant.
Definition: Seqdesc_.hpp:1039
TMol_type & SetMol_type(void)
Select the variant.
Definition: Seqdesc_.hpp:945
void SetInst(TInst &value)
Assign a value to Inst data member.
Definition: Bioseq_.cpp:86
void SetDescr(TDescr &value)
Assign a value to Descr data member.
Definition: Bioseq_.cpp:65
void SetRepr(TRepr value)
Assign a value to Repr data member.
Definition: Seq_inst_.hpp:574
bool IsFtable(void) const
Check if variant Ftable is selected.
Definition: Seq_annot_.hpp:615
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
void SetLength(TLength value)
Assign a value to Length data member.
Definition: Seq_inst_.hpp:668
void SetSeq_data(TSeq_data &value)
Assign a value to Seq_data data member.
Definition: Seq_inst_.cpp:130
void SetMol(TMol value)
Assign a value to Mol data member.
Definition: Seq_inst_.hpp:621
@ eRepr_raw
continuous sequence
Definition: Seq_inst_.hpp:94
@ e_Iupacaa
IUPAC 1 letter amino acid code.
Definition: Seq_data_.hpp:105
@ eGIBB_mol_peptide
Definition: GIBB_mol_.hpp:73
USING_SCOPE(objects)
#define ftable
Definition: utilfeat.h:37
Modified on Fri Sep 20 14:58:11 2024 by modify_doxy.py rev. 669887