1 /*  $Id: validerror_descr.cpp 632625 2021-06-03 17:38:33Z 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  * Author:  Jonathan Kans, Clifford Clausen, Aaron Ucko......
27  *
28  * File Description:
29  *   validation of seq_descr
30  *   .......
31  *
32  */
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <objtools/validator/validator.hpp>
36 #include <objtools/validator/validerror_desc.hpp>
37 #include <objtools/validator/validerror_descr.hpp>
38 
39 #include <serial/iterator.hpp>
40 
41 #include <objects/seq/Seqdesc.hpp>
42 #include <objects/seq/Seq_descr.hpp>
43 
44 
45 BEGIN_NCBI_SCOPE
BEGIN_SCOPE(objects)46 BEGIN_SCOPE(objects)
47 BEGIN_SCOPE(validator)
48 
49 
50 CValidError_descr::CValidError_descr(CValidError_imp& imp) :
51     CValidError_base(imp), m_DescValidator(imp)
52 {
53 }
54 
55 
~CValidError_descr(void)56 CValidError_descr::~CValidError_descr(void)
57 {
58 }
59 
60 
ValidateSeqDescr(const CSeq_descr & descr,const CSeq_entry & ctx)61 void CValidError_descr::ValidateSeqDescr(const CSeq_descr& descr, const CSeq_entry& ctx)
62 {
63     size_t  num_sources = 0,
64             num_titles = 0;
65     CConstRef<CSeqdesc> last_source;
66     const CSeqdesc* first_title = NULL;
67     const char* lastname = kEmptyCStr;
68     bool same_taxnames = false;
69 
70     FOR_EACH_DESCRIPTOR_ON_DESCR (dt, descr) {
71         const CSeqdesc& desc = **dt;
72 
73         m_DescValidator.ValidateSeqDesc (desc, ctx);
74 
75         switch ( desc.Which() ) {
76         case CSeqdesc::e_Mol_type:
77         case CSeqdesc::e_Modif:
78         case CSeqdesc::e_Method:
79             // obsolete
80             break;
81 
82         case CSeqdesc::e_Name:
83             break;
84         case CSeqdesc::e_Title:
85             num_titles++;
86             if (num_titles > 1) {
87                 PostErr(eDiag_Error, eErr_SEQ_DESCR_MultipleTitles,
88                     "Undesired multiple title descriptors", ctx, *first_title);
89             } else {
90                 first_title = *dt;
91             }
92             break;
93 
94         case CSeqdesc::e_Comment:
95             break;
96 
97         case CSeqdesc::e_Num:
98             break;
99         case CSeqdesc::e_Maploc:
100             break;
101 
102         case CSeqdesc::e_Pir:
103             break;
104 
105         case CSeqdesc::e_Genbank:
106             break;
107 
108         case CSeqdesc::e_Pub:
109             break;
110 
111         case CSeqdesc::e_Region:
112             break;
113         case CSeqdesc::e_User:
114             break;
115 
116         case CSeqdesc::e_Sp:
117             break;
118 
119         case CSeqdesc::e_Dbxref:
120             break;
121 
122         case CSeqdesc::e_Embl:
123             break;
124 
125         case CSeqdesc::e_Create_date:
126             break;
127         case CSeqdesc::e_Update_date:
128             break;
129 
130         case CSeqdesc::e_Prf:
131             break;
132 
133         case CSeqdesc::e_Pdb:
134             break;
135 
136         case CSeqdesc::e_Het:
137             break;
138         case CSeqdesc::e_Source:
139             {
140                 num_sources++;
141                 last_source = &desc;
142                 const CBioSource& src = desc.GetSource();
143                 if ( src.IsSetTaxname() ) {
144                     const string& currname = src.GetTaxname();
145                     if ( lastname != kEmptyCStr && NStr::EqualNocase (currname, lastname) ) {
146                         same_taxnames = true;
147                     }
148                     lastname = currname.c_str();
149                 }
150             }
151             break;
152         case CSeqdesc::e_Org:
153             break;
154         case CSeqdesc::e_Molinfo:
155             break;
156 
157         default:
158             break;
159         }
160     }
161 
162     if ( num_sources > 1 && same_taxnames ) {
163         PostErr(eDiag_Error, eErr_SEQ_DESCR_MultipleBioSources,
164             "Undesired multiple source descriptors", ctx, *last_source);
165     }
166 }
167 
168 
ValidateStructuredComment(const CUser_object & usr,const CSeqdesc & desc,bool report)169 bool CValidError_descr::ValidateStructuredComment (const CUser_object& usr, const CSeqdesc& desc, bool report)
170 {
171     return m_DescValidator.ValidateStructuredComment (usr, desc, report);
172 }
173 
174 
175 END_SCOPE(validator)
176 END_SCOPE(objects)
177 END_NCBI_SCOPE
178