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

Go to the SVN repository for this file.

1 /* $Id: xutils.cpp 99335 2023-03-13 13:48:10Z stakhovv $
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  * File Name: xutils.cpp
27  *
28  * Author: Alexey Dobronadezhdin
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 #include <objects/general/Date.hpp>
42 
43 #ifdef THIS_FILE
44 # undef THIS_FILE
45 #endif
46 #define THIS_FILE "xutils.cpp"
47 
48 #include "ftacpp.hpp"
49 #include "ftaerr.hpp"
50 #include "xgbparint.h"
51 #include "xutils.h"
52 
55 
56 /**********************************************************
57  *
58  * NLM_EXTERN bool LIBCALL ISAGappedSeqLoc(slp):
59  *
60  * Looks at a single SeqLoc item. If it has the SeqId
61  * of type GENERAL with Dbtag.db == $(seqlitdbtag) and
62  * Dbtag.tag.id == 0, then returns TRUE, otherwise
63  * returns FALSE.
64  *
65  **********************************************************/
66 static bool XISAGappedSeqLoc(const CSeq_loc& loc)
67 {
68  const CSeq_id* id = loc.GetId();
69  if (! id || ! id->IsGeneral() || ! id->GetGeneral().IsSetDb() || ! id->GetGeneral().IsSetTag())
70  return false;
71 
72 
73  if ((id->GetGeneral().GetDb() == seqlitdbtag || id->GetGeneral().GetDb() == unkseqlitdbtag) && id->GetGeneral().GetTag().GetId() == 0)
74  return true;
75 
76  return false;
77 }
78 
79 /**********************************************************
80  *
81  * NLM_EXTERN DeltaSeqPtr LIBCALL GappedSeqLocsToDeltaSeqs(slp):
82  *
83  * This functions is used only in the case, if ISAGappedSeqLoc()
84  * has returned TRUE.
85  * Converts SeqLoc set to the sequence of DeltaSeqs.
86  * Gbtag'ed SeqLocs it turns into SeqLits with the only "length"
87  * element. The regular SeqLocs saves as they are. Returns
88  * obtained DeltaSeq.
89  *
90  **********************************************************/
92 {
93  for (const auto& loc : locs) {
95  if (XISAGappedSeqLoc(*loc)) {
96  const CSeq_interval& interval = loc->GetInt();
97  delta->SetLiteral().SetLength(interval.GetTo() - interval.GetFrom() + 1);
98 
99  const CSeq_id* id = loc->GetId();
100  if (id) {
101  const CDbtag& tag = id->GetGeneral();
102  if (tag.GetDb() == unkseqlitdbtag)
103  delta->SetLiteral().SetFuzz().SetLim();
104  }
105  } else
106  delta->SetLoc().Assign(*loc);
107 
108  deltas.push_back(delta);
109  }
110 }
111 
112 /**********************************************************/
113 int XDateCheck(const CDate_std& date)
114 {
115  Int2 day, month, year, last;
116  static Uint1 days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
117 
118  if (! date.IsSetYear())
119  return 3;
120 
121  year = date.GetYear();
122 
123  if (! date.IsSetMonth())
124  return -2;
125 
126  month = date.GetMonth();
127  if (month > 12)
128  return 2;
129 
130  if (! date.IsSetDay())
131  return -1;
132 
133  day = date.GetDay();
134 
135  if (month > 12)
136  return false;
137  last = days[month - 1];
138 
139  if ((month == 2) && (year % 4 == 0) && (year != 2000)) {
140  last = 29;
141  }
142  if (day > last) {
143  return 1;
144  }
145 
146  return 0;
147 }
148 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
Definition: Dbtag.hpp:53
CDelta_seq –.
Definition: Delta_seq.hpp:66
CRef –.
Definition: ncbiobj.hpp:618
std::list< CRef< objects::CDelta_seq > > TDeltaList
Definition: ftablock.h:64
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsSetDb(void) const
name of database or system Check if a value has been assigned to Db data member.
Definition: Dbtag_.hpp:208
bool IsSetYear(void) const
full year (including 1900) Check if a value has been assigned to Year data member.
Definition: Date_std_.hpp:407
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:267
bool IsSetTag(void) const
appropriate tag Check if a value has been assigned to Tag data member.
Definition: Dbtag_.hpp:255
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
bool IsSetDay(void) const
day of month (1-31) Check if a value has been assigned to Day data member.
Definition: Date_std_.hpp:501
bool IsSetMonth(void) const
month (1-12) Check if a value has been assigned to Month data member.
Definition: Date_std_.hpp:454
TYear GetYear(void) const
Get the Year member data.
Definition: Date_std_.hpp:426
TMonth GetMonth(void) const
Get the Month member data.
Definition: Date_std_.hpp:473
TDay GetDay(void) const
Get the Day member data.
Definition: Date_std_.hpp:520
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
TFrom GetFrom(void) const
Get the From member data.
bool IsGeneral(void) const
Check if variant General is selected.
Definition: Seq_id_.hpp:877
const TGeneral & GetGeneral(void) const
Get the variant data.
Definition: Seq_id_.cpp:369
TTo GetTo(void) const
Get the To member data.
const char * tag
std::list< SeqLoc > TSeqLocList
Int4 delta(size_t dimension_, const Int4 *score_)
const char * seqlitdbtag
Definition: xgbparint.cpp:55
const char * unkseqlitdbtag
Definition: xgbparint.cpp:56
USING_SCOPE(objects)
void XGappedSeqLocsToDeltaSeqs(const TSeqLocList &locs, TDeltaList &deltas)
Definition: xutils.cpp:91
static bool XISAGappedSeqLoc(const CSeq_loc &loc)
Definition: xutils.cpp:66
int XDateCheck(const CDate_std &date)
Definition: xutils.cpp:113
Modified on Mon Apr 22 04:02:23 2024 by modify_doxy.py rev. 669887