source: tags/ms_r16q2/CONVERTALN/genbank.h

Last change on this file was 13018, checked in by westram, 10 years ago
File size: 2.8 KB
Line 
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
11struct GenbankRef {
12    char *ref;
13    char *author;
14    char *title;
15    char *journal;
16    char *standard;
17
18    GenbankRef()
19        : ref(no_content()),
20          author(no_content()),
21          title(no_content()),
22          journal(no_content()),
23          standard(no_content())
24    {}
25    GenbankRef(const GenbankRef& other)
26        : ref(strdup(other.ref)),
27          author(strdup(other.author)),
28          title(strdup(other.title)),
29          journal(strdup(other.journal)),
30          standard(strdup(other.standard))
31    {}
32    ~GenbankRef() {
33        free(standard);
34        free(journal);
35        free(title);
36        free(author);
37        free(ref);
38    }
39    DECLARE_ASSIGNMENT_OPERATOR(GenbankRef);
40};
41
42class GenBank : public InputFormat, public RefContainer<GenbankRef> { // derived from a Noncopyable
43    char *create_id() const OVERRIDE {
44        char buf[TOKENSIZE];
45        genbank_key_word(locus, 0, buf);
46        return strdup(buf);
47    }
48public:
49    char *locus;
50    char *definition;
51    char *accession;
52    char *keywords;
53    char *source;
54    char *organism;
55
56    RDP_comments comments;
57
58    GenBank() {
59        locus      = no_content();
60        definition = no_content();
61        accession  = no_content();
62        keywords   = no_content();
63        source     = no_content();
64        organism   = no_content();
65    }
66    virtual ~GenBank() OVERRIDE {
67        freenull(locus);
68        freenull(definition);
69        freenull(accession);
70        freenull(keywords);
71        freenull(source);
72        freenull(organism);
73    }
74
75    bool locus_contains_date() const { return str0len(locus) >= 60; }
76
77    char *get_date() const {
78        if (locus_contains_date()) return strndup(locus+50, 11);
79        return strdup(genbank_date(today_date()));
80    }
81
82    // InputFormat interface
83    void reinit() OVERRIDE { INPLACE_RECONSTRUCT(GenBank, this); }
84    Format format() const OVERRIDE { return GENBANK; }
85};
86
87class GenbankReader : public SimpleFormatReader {
88    GenBank data;
89public:
90    GenbankReader(const char *inf) : SimpleFormatReader(inf) {}
91
92    const char *get_key_word(int offset) {
93        char key[TOKENSIZE];
94        genbank_key_word(line() + offset, 0, key);
95        return shorttimecopy(key);
96    }
97    bool read_one_entry(Seq& seq) OVERRIDE __ATTR__USERESULT;
98    InputFormat& get_data() OVERRIDE { return data; }
99};
100
101// ----------------------
102//      GenbankParser
103
104class GenbankParser : public Parser {
105    GenBank& gbk;
106
107    void parse_keyed_section(const char *key);
108public:
109    GenbankParser(GenBank& gbk_, Seq& seq_, GenbankReader& reader_) : Parser(seq_, reader_), gbk(gbk_) {}
110    void parse_section() OVERRIDE;
111
112    const GenBank& get_data() const OVERRIDE { return gbk; }
113};
114
115#else
116#error genbank.h included twice
117#endif // GENBANK_H
Note: See TracBrowser for help on using the repository browser.