| 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 | |
|---|
| 21 | GenbankRef() |
|---|
| 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 | {} |
|---|
| 35 | ~GenbankRef() { |
|---|
| 36 | free(standard); |
|---|
| 37 | free(journal); |
|---|
| 38 | free(title); |
|---|
| 39 | free(author); |
|---|
| 40 | free(ref); |
|---|
| 41 | } |
|---|
| 42 | DECLARE_ASSIGNMENT_OPERATOR(GenbankRef); |
|---|
| 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 | } |
|---|
| 69 | ~GenBank() OVERRIDE { |
|---|
| 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); |
|---|
| 82 | return ARB_strdup(genbank_date(today_date())); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | // InputFormat interface |
|---|
| 86 | void reinit() OVERRIDE { INPLACE_RECONSTRUCT(GenBank, this); } |
|---|
| 87 | Format format() const OVERRIDE { return GENBANK; } |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | class GenbankReader : public SimpleFormatReader { |
|---|
| 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 | } |
|---|
| 100 | bool read_one_entry(Seq& seq) OVERRIDE __ATTR__USERESULT; |
|---|
| 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 |
|---|