1 /* $Id: source_mod_parser_wrapper.cpp 632526 2021-06-02 17:25:01Z 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: Michael Kornbluh
27 *
28 * File Description:
29 * Wraps CSourceModParser calls for CBioseq_Handles and such.
30 *
31 * ===========================================================================
32 */
33
34 #include <ncbi_pch.hpp>
35 #include <objtools/readers/source_mod_parser_wrapper.hpp>
36 #include <objtools/readers/source_mod_parser.hpp>
37
38 #include <objmgr/bioseq_handle.hpp>
39 #include <objmgr/seq_annot_ci.hpp>
40 #include <objmgr/seqdesc_ci.hpp>
41 #include <objects/misc/sequence_macros.hpp>
42
43 BEGIN_NCBI_SCOPE
BEGIN_SCOPE(objects)44 BEGIN_SCOPE(objects)
45
46 // static
47 void CSourceModParserWrapper::ExtractTitleAndApplyAllMods(CBioseq_Handle& bsh, CTempString organism)
48 {
49 // add subtypes and many other things based on the title
50 CSeqdesc_CI title_desc(bsh, CSeqdesc::e_Title);
51 if( title_desc ) {
52 CSourceModParser smp;
53 string& title(const_cast<string&>(title_desc->GetTitle()));
54 title = smp.ParseTitle(title, bsh.GetInitialSeqIdOrNull() );
55 x_ApplyAllMods(smp, bsh, organism);
56 smp.GetLabel(&title, CSourceModParser::fUnusedMods);
57 }
58
59 // need to create update date (or create date if there's no create date )
60 {
61 CRef<CSeqdesc> new_seqdesc( new CSeqdesc );
62 CRef<CDate> todays_date( new CDate(CTime(CTime::eCurrent), CDate::ePrecision_day) );
63
64 CSeqdesc_CI create_date_desc(bsh, CSeqdesc::e_Create_date);
65 if( create_date_desc ) {
66 // add update date
67 new_seqdesc->SetUpdate_date( *todays_date );
68 } else {
69 // add create date
70 new_seqdesc->SetCreate_date( *todays_date );
71 }
72
73 CBioseq_EditHandle(bsh).AddSeqdesc( *new_seqdesc );
74 }
75 }
76
77 // static
x_ApplyAllMods(CSourceModParser & smp,CBioseq_Handle & bsh,CTempString organism)78 void CSourceModParserWrapper::x_ApplyAllMods(
79 CSourceModParser &smp, CBioseq_Handle& bsh, CTempString organism)
80 {
81 // pull Bioseq out of the object manager so we can edit it
82 CSeq_entry_EditHandle seeh = CSeq_entry_EditHandle(bsh.GetParentEntry()); // TODO: what if there's no parent?
83 CRef<CBioseq> bioseq(const_cast<CBioseq*>(&*bsh.GetCompleteBioseq()));
84 seeh.SelectNone(); // the bioseq is removed from OM
85
86 // call underlying function
87 smp.ApplyAllMods( *bioseq, organism );
88
89 // put Bioseq back into the object manager
90 bsh = seeh.SelectSeq(*bioseq);
91 }
92
93 END_SCOPE(objects)
94 END_NCBI_SCOPE
95