1 #ifndef OBJMGR_UTIL___AUTODEF__HPP
2 #define OBJMGR_UTIL___AUTODEF__HPP
3 
4 /*  $Id: autodef.hpp 578777 2019-01-25 13:17:09Z bollin $
5 * ===========================================================================
6 *
7 *                            PUBLIC DOMAIN NOTICE
8 *               National Center for Biotechnology Information
9 *
10 *  This software/database is a "United States Government Work" under the
11 *  terms of the United States Copyright Act.  It was written as part of
12 *  the author's official duties as a United States Government employee and
13 *  thus cannot be copyrighted.  This software/database is freely available
14 *  to the public for use. The National Library of Medicine and the U.S.
15 *  Government have not placed any restriction on its use or reproduction.
16 *
17 *  Although all reasonable efforts have been taken to ensure the accuracy
18 *  and reliability of the software and data, the NLM and the U.S.
19 *  Government do not and cannot warrant the performance or results that
20 *  may be obtained by using this software or data. The NLM and the U.S.
21 *  Government disclaim all warranties, express or implied, including
22 *  warranties of performance, merchantability or fitness for any particular
23 *  purpose.
24 *
25 *  Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author:  Colleen Bollin
30 *
31 * File Description:
32 *   Creates unique definition lines for sequences in a set using organism
33 *   descriptions and feature clauses.
34 */
35 
36 #include <corelib/ncbistd.hpp>
37 #include <objects/seqfeat/BioSource.hpp>
38 #include <objects/seqfeat/Org_ref.hpp>
39 #include <objects/seqfeat/OrgMod.hpp>
40 #include <objects/seqfeat/SubSource.hpp>
41 #include <objects/seqfeat/OrgName.hpp>
42 #include <objects/seqfeat/Seq_feat.hpp>
43 #include <objects/seq/MolInfo.hpp>
44 
45 #include <objmgr/bioseq_handle.hpp>
46 #include <objmgr/seq_entry_handle.hpp>
47 #include <objmgr/feat_ci.hpp>
48 
49 #include <objmgr/util/autodef_available_modifier.hpp>
50 #include <objmgr/util/autodef_source_desc.hpp>
51 #include <objmgr/util/autodef_source_group.hpp>
52 #include <objmgr/util/autodef_mod_combo.hpp>
53 #include <objmgr/util/autodef_feature_clause.hpp>
54 #include <objmgr/util/autodef_options.hpp>
55 
56 BEGIN_NCBI_SCOPE
57 BEGIN_SCOPE(objects)
58 
59 class NCBI_XOBJEDIT_EXPORT CAutoDef
60 {
61 public:
62 
63     typedef set<CAutoDefAvailableModifier> TAvailableModifierSet;
64 
65     CAutoDef();
66     ~CAutoDef();
67 
68     void AddSources(CSeq_entry_Handle se);
69     void AddSources(CBioseq_Handle bh);
70     CRef<CAutoDefModifierCombo> FindBestModifierCombo();
71     CAutoDefModifierCombo* GetAllModifierCombo();
72     CAutoDefModifierCombo* GetEmptyCombo();
73     unsigned int GetNumAvailableModifiers();
74     string GetOneSourceDescription(const CBioseq_Handle& bh);
75     string GetOneFeatureClauseList(CBioseq_Handle bh, unsigned int genome_val);
76     string GetOneDefLine(CAutoDefModifierCombo* mod_combo, const CBioseq_Handle& bh);
77     string GetOneDefLine(const CBioseq_Handle& bh);
78 
79     void SetOptionsObject(const CUser_object& user);
GetOptionsObject() const80     CRef<CUser_object> GetOptionsObject() const { return m_Options.MakeUserObject(); }
81 
82     void SetFeatureListType(CAutoDefOptions::EFeatureListType feature_list_type);
83     void SetMiscFeatRule(CAutoDefOptions::EMiscFeatRule misc_feat_rule);
84     void SetProductFlag(CBioSource::EGenome product_flag);
85     void SetNuclearCopyFlag(CBioSource::EGenome product_flag);
86 	void SetSpecifyNuclearProduct (bool specify_nuclear_product);
87     void SetAltSpliceFlag (bool alt_splice_flag);
88     void SetSuppressLocusTags(bool suppress_locus_tags);
89     void SetSuppressAllele(bool suppress_allele);
90     void SetGeneClusterOppStrand(bool gene_opp_strand);
91     void SetSuppressFeatureAltSplice (bool suppress_alt_splice);
92     void SuppressMobileElementAndInsertionSequenceSubfeatures(bool suppress);
93     void SuppressMiscFeatSubfeatures(bool suppress);
94     void SetKeepExons(bool keep);
95     void SetKeepIntrons(bool keep);
96     void SetKeepRegulatoryFeatures(bool keep);
97     void SetKeepLTRs(bool keep);
98     void SetKeep3UTRs(bool keep);
99     void SetKeep5UTRs(bool keep);
100     void SetKeepuORFs(bool keep);
101     void SetKeepOptionalMobileElements(bool keep);
102     void SetKeepPrecursorRNA(bool keep);
103     void SetKeepRepeatRegion(bool keep);
104     void SetKeepMiscRecomb(bool keep);
105 	void SetUseNcRNAComment (bool use_comment);
106     void SetUseFakePromoters (bool use_fake);
107     void SetCustomFeatureClause(const string& custom_feature_clause);
108 
109     void SuppressFeature(const objects::CFeatListItem& feat);
110     void SuppressFeature(objects::CSeqFeatData::ESubtype subtype);
111 
112     typedef vector<CRef<CAutoDefModifierCombo>> TModifierComboVector;
113 
114     void GetAvailableModifiers(TAvailableModifierSet &mod_set);
115 
Cancel()116     void Cancel() { m_Cancelled = true; }
Cancelled()117     bool Cancelled() { return m_Cancelled; }
118 
119     static string GetKeywordPrefix(CBioseq_Handle bh);
120 
121     static bool RegenerateSequenceDefLines(CSeq_entry_Handle se);
122     static string RegenerateDefLine(CBioseq_Handle bh);
123 
124     static CRef<CUser_object> CreateIDOptions(CSeq_entry_Handle seh);
125 
126 private:
127     typedef vector<unsigned int> TModifierIndexVector;
128     typedef vector<CSeq_entry_Handle> TSeqEntryHandleVector;
129 
130     CAutoDefModifierCombo m_OrigModCombo;
131 
132     CAutoDefOptions m_Options;
133 
134     // feature clause specifications
135     bool         m_Cancelled;
136 
137     void x_SortModifierListByRank
138         (TModifierIndexVector& index_list,
139          CAutoDefSourceDescription::TAvailableModifierVector& modifier_list);
140     void x_GetModifierIndexList
141         (TModifierIndexVector& index_list,
142          CAutoDefSourceDescription::TAvailableModifierVector& modifier_list);
143 
144     string x_GetNonFeatureListEnding();
145 
146     string x_GetFeatureClauses(const CBioseq_Handle& bh);
147     string x_GetFeatureClauseProductEnding(const string& feature_clauses,
148                                            CBioseq_Handle bh);
149 
150     void x_RemoveOptionalFeatures(CAutoDefFeatureClause_Base *main_clause, const CBioseq_Handle& bh);
151 
152 
153     bool x_IsOrgModRequired(unsigned int mod_type);
154     bool x_IsSubSrcRequired(unsigned int mod_type);
155 
156     bool x_IsFeatureSuppressed(CSeqFeatData::ESubtype subtype);
157 
158     void GetMasterLocation(CBioseq_Handle &bh, CRange<TSeqPos>& range);
159     bool IsSegment(const CBioseq_Handle& bh);
160     bool x_Is5SList(CFeat_CI feat_ci);
161     bool x_IsSingleMiscFeat(CFeat_CI feat_ci);
162     string x_GetHumanSTRFeatureClauses(CBioseq_Handle bh, const CUser_object& comment);
163     bool x_IsHumanSTR(const CUser_object& obj);
164 
165     string x_GetOneNonFeatureClause(CBioseq_Handle bh, unsigned int genome_val);
166 
167 };  //  end of CAutoDef
168 
169 
170 inline
SetFeatureListType(CAutoDefOptions::EFeatureListType feature_list_type)171 void CAutoDef::SetFeatureListType(CAutoDefOptions::EFeatureListType feature_list_type)
172 {
173     m_Options.SetFeatureListType(feature_list_type);
174 }
175 
176 
177 inline
SetMiscFeatRule(CAutoDefOptions::EMiscFeatRule misc_feat_rule)178 void CAutoDef::SetMiscFeatRule(CAutoDefOptions::EMiscFeatRule misc_feat_rule)
179 {
180     m_Options.SetMiscFeatRule(misc_feat_rule);
181 }
182 
183 
184 inline
SetProductFlag(CBioSource::EGenome product_flag)185 void CAutoDef::SetProductFlag(CBioSource::EGenome product_flag)
186 {
187     m_Options.SetProductFlag(product_flag);
188 }
189 
190 
191 inline
SetNuclearCopyFlag(CBioSource::EGenome product_flag)192 void CAutoDef::SetNuclearCopyFlag(CBioSource::EGenome product_flag)
193 {
194     m_Options.SetNuclearCopyFlag(product_flag);
195 }
196 
197 
198 inline
SetSpecifyNuclearProduct(bool specify_nuclear_product)199 void CAutoDef::SetSpecifyNuclearProduct (bool specify_nuclear_product)
200 {
201     m_Options.SetSpecifyNuclearProduct(specify_nuclear_product);
202 }
203 
204 
205 inline
SetAltSpliceFlag(bool alt_splice_flag)206 void CAutoDef::SetAltSpliceFlag (bool alt_splice_flag)
207 {
208     m_Options.SetAltSpliceFlag(alt_splice_flag);
209 }
210 
211 
212 inline
SetSuppressLocusTags(bool suppress_locus_tags)213 void CAutoDef::SetSuppressLocusTags (bool suppress_locus_tags)
214 {
215     m_Options.SetSuppressLocusTags(suppress_locus_tags);
216 }
217 
218 
219 inline
SetGeneClusterOppStrand(bool gene_opp_strand)220 void CAutoDef::SetGeneClusterOppStrand (bool gene_opp_strand)
221 {
222     m_Options.SetGeneClusterOppStrand(gene_opp_strand);
223 }
224 
225 
226 inline
SetSuppressFeatureAltSplice(bool suppress_alt_splice)227 void CAutoDef::SetSuppressFeatureAltSplice (bool suppress_alt_splice)
228 {
229     m_Options.SetSuppressFeatureAltSplice(suppress_alt_splice);
230 }
231 
232 
233 inline
SuppressMobileElementAndInsertionSequenceSubfeatures(bool suppress)234 void CAutoDef::SuppressMobileElementAndInsertionSequenceSubfeatures(bool suppress)
235 {
236     m_Options.SetSuppressMobileElementSubfeatures(suppress);
237 }
238 
239 
240 inline
SuppressMiscFeatSubfeatures(bool suppress)241 void CAutoDef::SuppressMiscFeatSubfeatures(bool suppress)
242 {
243     m_Options.SetSuppressMiscFeatureSubfeatures(suppress);
244 }
245 
246 
247 inline
SetKeepExons(bool keep)248 void CAutoDef::SetKeepExons(bool keep)
249 {
250     m_Options.SetKeepExons(keep);
251 }
252 
253 
254 inline
SetKeepIntrons(bool keep)255 void CAutoDef::SetKeepIntrons(bool keep)
256 {
257     m_Options.SetKeepIntrons(keep);
258 }
259 
260 
261 inline
SetKeepRegulatoryFeatures(bool keep)262 void CAutoDef::SetKeepRegulatoryFeatures(bool keep)
263 {
264     m_Options.SetKeepRegulatoryFeatures(keep);
265 }
266 
267 inline
SetKeepLTRs(bool keep)268 void CAutoDef::SetKeepLTRs(bool keep)
269 {
270     m_Options.SetKeepLTRs(keep);
271 }
272 
273 
274 inline
SetKeep3UTRs(bool keep)275 void CAutoDef::SetKeep3UTRs(bool keep)
276 {
277     m_Options.SetKeep3UTRs(keep);
278 }
279 
280 
281 inline
SetKeep5UTRs(bool keep)282 void CAutoDef::SetKeep5UTRs(bool keep)
283 {
284     m_Options.SetKeep5UTRs(keep);
285 }
286 
287 
288 inline
SetKeepuORFs(bool keep)289 void CAutoDef::SetKeepuORFs(bool keep)
290 {
291     m_Options.SetKeepuORFs(keep);
292 }
293 
294 
295 inline
SetKeepOptionalMobileElements(bool keep)296 void CAutoDef::SetKeepOptionalMobileElements(bool keep)
297 {
298     m_Options.SetKeepMobileElements(keep);
299 }
300 
301 inline
SetKeepPrecursorRNA(bool keep)302 void CAutoDef::SetKeepPrecursorRNA(bool keep)
303 {
304     m_Options.SetKeepPrecursorRNA(keep);
305 }
306 
307 inline
SetKeepRepeatRegion(bool keep)308 void CAutoDef::SetKeepRepeatRegion(bool keep)
309 {
310     m_Options.SetKeepRepeatRegion(keep);
311 }
312 
313 inline
SetKeepMiscRecomb(bool keep)314 void CAutoDef::SetKeepMiscRecomb(bool keep)
315 {
316     m_Options.SetKeepMiscRecomb(keep);
317 }
318 
319 inline
SetUseNcRNAComment(bool use_comment)320 void CAutoDef::SetUseNcRNAComment(bool use_comment)
321 {
322     m_Options.SetUseNcRNAComment(use_comment);
323 }
324 
325 
326 inline
SetUseFakePromoters(bool use_fake)327 void CAutoDef::SetUseFakePromoters(bool use_fake)
328 {
329     m_Options.SetUseFakePromoters(use_fake);
330 }
331 
332 
333 inline
SetCustomFeatureClause(const string & custom_feature_clause)334 void CAutoDef::SetCustomFeatureClause(const string& custom_feature_clause)
335 {
336     m_Options.SetCustomFeatureClause(custom_feature_clause);
337 }
338 
339 END_SCOPE(objects)
340 END_NCBI_SCOPE
341 
342 #endif //OBJMGR_UTIL___AUTODEF__HPP
343