| 1 | // ----------------------------------------------------------------------------- |
|---|
| 2 | // Include-Dateien |
|---|
| 3 | // ----------------------------------------------------------------------------- |
|---|
| 4 | |
|---|
| 5 | #include <iostream> |
|---|
| 6 | #include <fstream> |
|---|
| 7 | #include <cstdio> |
|---|
| 8 | #include <cstdlib> |
|---|
| 9 | |
|---|
| 10 | #include "a3_arbdb.hxx" |
|---|
| 11 | #include <BI_helix.hxx> |
|---|
| 12 | // #include "a3_bihelix.hxx" |
|---|
| 13 | #include "a3_ali.hxx" |
|---|
| 14 | |
|---|
| 15 | using std::cout; |
|---|
| 16 | using std::ifstream; |
|---|
| 17 | using std::flush; |
|---|
| 18 | |
|---|
| 19 | // ----------------------------------------------------------------------------- |
|---|
| 20 | static void Usage ( void ) |
|---|
| 21 | // ----------------------------------------------------------------------------- |
|---|
| 22 | { |
|---|
| 23 | cout << "\nAUFRUF: aliv3 <Datenbank> <Sequenz>\n"; |
|---|
| 24 | cout << "\n <Datenbank> ::= Eine ARB-Datenbank (z.B.: 23sx.arb)."; |
|---|
| 25 | cout << "\n <Sequenz> ::= Name einer RNS-Sequenz (z.B.: ECOLI).\n"; |
|---|
| 26 | cout << "\nDarueberhinaus muss noch eine Datei matches.txt existieren, in der die Teilloesungen"; |
|---|
| 27 | cout << "\ndes Prealigners zeilenweise abgelegt sind. Innerhalb einer Zeile muessen die Positions-"; |
|---|
| 28 | cout << "\npaare der Loesung durch Kommata getrennt sein (z.B.: 5 10, 20 30, ...).\n\n"; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | // ----------------------------------------------------------------------------- |
|---|
| 32 | static DArray *ReadMatches ( str file ) |
|---|
| 33 | // ----------------------------------------------------------------------------- |
|---|
| 34 | { |
|---|
| 35 | short error = 0; |
|---|
| 36 | DArray *pre = new DArray; |
|---|
| 37 | ifstream input(file); |
|---|
| 38 | |
|---|
| 39 | if (!pre || !input) error = 1; |
|---|
| 40 | else |
|---|
| 41 | { |
|---|
| 42 | str line = NULL; |
|---|
| 43 | |
|---|
| 44 | pre->Free(DARRAY_NOFREE); |
|---|
| 45 | pre->Null(DARRAY_NONULL); |
|---|
| 46 | |
|---|
| 47 | while (!error) |
|---|
| 48 | { |
|---|
| 49 | // if (!input.gets(&line) && !input.eof()) error = 2; |
|---|
| 50 | // else if (strlen(line)) |
|---|
| 51 | { |
|---|
| 52 | PSolution *psol = new PSolution; |
|---|
| 53 | |
|---|
| 54 | if (!psol) error = 3; |
|---|
| 55 | else |
|---|
| 56 | { |
|---|
| 57 | str tmp = strtok(line,","); |
|---|
| 58 | |
|---|
| 59 | while (!error && tmp) |
|---|
| 60 | { |
|---|
| 61 | HMatch *m = new HMatch; |
|---|
| 62 | |
|---|
| 63 | if (!m) error = 4; |
|---|
| 64 | else |
|---|
| 65 | { |
|---|
| 66 | sscanf(tmp,"%d%d",&m->first,&m->last); |
|---|
| 67 | |
|---|
| 68 | psol->match.Add(m); |
|---|
| 69 | psol->score += (m->last - m->first + 1); |
|---|
| 70 | |
|---|
| 71 | tmp = strtok(NULL,","); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | if (!error) |
|---|
| 76 | { |
|---|
| 77 | psol->match.Sort(hmatchcmp); |
|---|
| 78 | pre->Add(psol); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | delete line; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | if (input.eof()) break; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (!error) pre->Sort(psolcmp); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if (error) delete pre, pre = NULL; |
|---|
| 92 | |
|---|
| 93 | return pre; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | // ----------------------------------------------------------------------------- |
|---|
| 97 | int main ( int argc, |
|---|
| 98 | char *argv[] ) |
|---|
| 99 | // ----------------------------------------------------------------------------- |
|---|
| 100 | { |
|---|
| 101 | int error = 0; |
|---|
| 102 | |
|---|
| 103 | if (argc != 3) Usage(); |
|---|
| 104 | else |
|---|
| 105 | { |
|---|
| 106 | A3Arbdb db; |
|---|
| 107 | |
|---|
| 108 | if (db.open(argv[1])) error = 1; |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | db.begin_transaction(); |
|---|
| 112 | |
|---|
| 113 | str seq = db.get_sequence_string(argv[2]), |
|---|
| 114 | fam = db.get_sequence_string("EscCol19"); |
|---|
| 115 | |
|---|
| 116 | db.commit_transaction(); |
|---|
| 117 | |
|---|
| 118 | if (!(seq && fam)) error = 2; |
|---|
| 119 | else |
|---|
| 120 | { |
|---|
| 121 | // DArray *pre = ReadMatches("matches.txt"); |
|---|
| 122 | |
|---|
| 123 | cout << "\n" << seq; |
|---|
| 124 | // cout << "\n" << fam << "\n"; |
|---|
| 125 | |
|---|
| 126 | // if (!pre) error = 3; |
|---|
| 127 | // else |
|---|
| 128 | { |
|---|
| 129 | BI_helix helix; |
|---|
| 130 | const char *err = helix.init(db.gb_main); |
|---|
| 131 | size_t pos = 0; |
|---|
| 132 | |
|---|
| 133 | if (err) cout << err << ", " << helix.size(); |
|---|
| 134 | |
|---|
| 135 | while (pos < helix.size()) |
|---|
| 136 | { |
|---|
| 137 | if (helix.pairtype(pos) != HELIX_PAIR) cout << "."; |
|---|
| 138 | else |
|---|
| 139 | { |
|---|
| 140 | if (helix.opposite_position(pos) < pos) cout << "]"; |
|---|
| 141 | else cout << "["; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | pos++; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | cout << flush; |
|---|
| 148 | |
|---|
| 149 | // Aligner ali(seq[2],seq[0],seq[1],*pre); |
|---|
| 150 | // DArray &tmp = ali.Align(); |
|---|
| 151 | |
|---|
| 152 | // delete &tmp; |
|---|
| 153 | // delete pre; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | if (seq) delete seq; |
|---|
| 158 | if (fam) delete fam; |
|---|
| 159 | |
|---|
| 160 | db.close(); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | if (error) cout << "\nALIV3: Fehler Nummer " << error << " ist aufgetreten!\n\n"; |
|---|
| 165 | |
|---|
| 166 | return error; |
|---|
| 167 | } |
|---|