ARB
genbank.h
Go to the documentation of this file.
1 #ifndef GENBANK_H
2 #define GENBANK_H
3 
4 #ifndef REFS_H
5 #include "refs.h"
6 #endif
7 #ifndef PARSER_H
8 #include "parser.h"
9 #endif
10 #ifndef ARB_STRING_H
11 #include <arb_string.h>
12 #endif
13 
14 struct GenbankRef {
15  char *ref;
16  char *author;
17  char *title;
18  char *journal;
19  char *standard;
20 
22  : ref(no_content()),
23  author(no_content()),
24  title(no_content()),
25  journal(no_content()),
26  standard(no_content())
27  {}
28  GenbankRef(const GenbankRef& other)
29  : ref(ARB_strdup(other.ref)),
30  author(ARB_strdup(other.author)),
31  title(ARB_strdup(other.title)),
32  journal(ARB_strdup(other.journal)),
33  standard(ARB_strdup(other.standard))
34  {}
36  free(standard);
37  free(journal);
38  free(title);
39  free(author);
40  free(ref);
41  }
43 };
44 
45 class GenBank FINAL_TYPE : public InputFormat, public RefContainer<GenbankRef> { // derived from a Noncopyable
46  char *create_id() const OVERRIDE {
47  char buf[TOKENSIZE];
48  genbank_key_word(locus, 0, buf);
49  return ARB_strdup(buf);
50  }
51 public:
52  char *locus;
53  char *definition;
54  char *accession;
55  char *keywords;
56  char *source;
57  char *organism;
58 
59  RDP_comments comments;
60 
61  GenBank() {
62  locus = no_content();
63  definition = no_content();
64  accession = no_content();
65  keywords = no_content();
66  source = no_content();
67  organism = no_content();
68  }
70  freenull(locus);
71  freenull(definition);
72  freenull(accession);
73  freenull(keywords);
74  freenull(source);
75  freenull(organism);
76  }
77 
78  bool locus_contains_date() const { return str0len(locus) >= 60; }
79 
80  char *get_date() const {
81  if (locus_contains_date()) return strndup(locus+50, 11);
83  }
84 
85  // InputFormat interface
86  void reinit() OVERRIDE { INPLACE_RECONSTRUCT(GenBank, this); }
87  Format format() const OVERRIDE { return GENBANK; }
88 };
89 
91  GenBank data;
92 public:
93  GenbankReader(const char *inf) : SimpleFormatReader(inf) {}
94 
95  const char *get_key_word(int offset) {
96  char key[TOKENSIZE];
97  genbank_key_word(line() + offset, 0, key);
98  return shorttimecopy(key);
99  }
101  InputFormat& get_data() OVERRIDE { return data; }
102 };
103 
104 // ----------------------
105 // GenbankParser
106 
107 class GenbankParser : public Parser {
108  GenBank& gbk;
109 
110  void parse_keyed_section(const char *key);
111 public:
112  GenbankParser(GenBank& gbk_, Seq& seq_, GenbankReader& reader_) : Parser(seq_, reader_), gbk(gbk_) {}
113  void parse_section() OVERRIDE;
114 
115  const GenBank& get_data() const OVERRIDE { return gbk; }
116 };
117 
118 #else
119 #error genbank.h included twice
120 #endif // GENBANK_H
CONSTEXPR_INLINE int str0len(const char *str)
Definition: global.h:98
Format
Definition: fun.h:10
const GenBank & get_data() const OVERRIDE
Definition: genbank.h:115
char * title
Definition: genbank.h:17
~GenBank() OVERRIDE
Definition: genbank.h:69
char * get_date() const
Definition: genbank.h:80
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
char * ref
Definition: genbank.h:15
Format format() const OVERRIDE
Definition: genbank.h:87
DECLARE_ASSIGNMENT_OPERATOR(GenbankRef)
#define INPLACE_RECONSTRUCT(type, this)
Definition: arbtools.h:49
char * organism
Definition: genbank.h:57
const char * genbank_date(const char *other_date)
Definition: date.cxx:164
FILE * seq
Definition: rns.c:46
void reinit() OVERRIDE
Definition: genbank.h:86
InputFormat & get_data() OVERRIDE
Definition: genbank.h:101
GenbankRef()
Definition: genbank.h:21
char * journal
Definition: genbank.h:18
const char * get_key_word(int offset)
Definition: genbank.h:95
~GenbankRef()
Definition: genbank.h:35
GenbankReader(const char *inf)
Definition: genbank.h:93
Definition: seq.h:43
char * locus
Definition: genbank.h:52
GenbankRef(const GenbankRef &other)
Definition: genbank.h:28
char * source
Definition: genbank.h:56
GenBank()
Definition: genbank.h:61
Definition: fun.h:13
void genbank_key_word(const char *line, int index, char *key)
Definition: genbank.cxx:9
char * standard
Definition: genbank.h:19
xml element
const char * today_date()
Definition: date.cxx:214
bool read_one_entry(Seq &seq) OVERRIDE __ATTR__USERESULT
Definition: genbank.cxx:459
#define OVERRIDE
Definition: cxxforward.h:93
#define __ATTR__USERESULT
Definition: attributes.h:58
char * definition
Definition: genbank.h:53
const char * shorttimecopy(const char *nocopy)
Definition: reader.h:67
#define TOKENSIZE
Definition: defs.h:18
char * author
Definition: genbank.h:16
const char * line() const
Definition: reader.h:43
GenbankParser(GenBank &gbk_, Seq &seq_, GenbankReader &reader_)
Definition: genbank.h:112
void parse_section() OVERRIDE
Definition: genbank.cxx:238
char * no_content()
Definition: global.h:129
#define offset(field)
Definition: GLwDrawA.c:73
bool locus_contains_date() const
Definition: genbank.h:78
char * strndup(const char *str, int len)
Definition: global.h:102