debug.cc 3.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// *******************************************************************
// Extractor (library)
// *******************************************************************
// FILE INFORMATION:
//   File:     debug.cc
//   Author:   Jonathan K. Vis
// *******************************************************************
// DESCRIPTION:
//   This source can be used to debug the Extractor library within
//   C/C++. It opens two files given as arguments and perform the
//   description extraction. Supply the -D__debug__ flag in the
//   Makefile for tracing.
// *******************************************************************

jkvis's avatar
jkvis committed
15
16
17
#include "extractor.h"
using namespace mutalyzer;

jkvis's avatar
jkvis committed
18
19
#include <cstdio>

J.K. Vis's avatar
J.K. Vis committed
20

21
22
23
#include <iostream>
#include <string>
using namespace std;
J.K. Vis's avatar
J.K. Vis committed
24

25

26
// Entry point.
jkvis's avatar
jkvis committed
27
int main(int argc, char* argv[])
jkvis's avatar
jkvis committed
28
{
J.K. Vis's avatar
J.K. Vis committed
29
/*
J.K. Vis's avatar
J.K. Vis committed
30
31
32
33
34
35
  if (argc < 3)
  {
    fprintf(stderr, "usage: %s reference sample\n", argv[0]);
    return 1;
  } // if
  fprintf(stderr, "HGVS description extractor\n");
36
37
38


  // Opening files.
J.K. Vis's avatar
J.K. Vis committed
39
40
41
42
43
44
45
  FILE* file = fopen(argv[1], "r");
  if (file == 0)
  {
    fprintf(stderr, "ERROR: could not open file `%s'\n", argv[1]);
    return 1;
  } // if
  fseek(file, 0, SEEK_END);
jkvis's avatar
jkvis committed
46
  size_t const reference_length = ftell(file);
J.K. Vis's avatar
J.K. Vis committed
47
48
  rewind(file);
  char_t* reference = new char_t[reference_length];
J.K. Vis's avatar
J.K. Vis committed
49
50
  size_t const ref_length = fread(reference, sizeof(char_t), reference_length, file);
  static_cast<void>(ref_length);
J.K. Vis's avatar
J.K. Vis committed
51
52
53
54
55
56
57
58
59
60
  fclose(file);

  file = fopen(argv[2], "r");
  if (file == 0)
  {
    fprintf(stderr, "ERROR: could not open file `%s'\n", argv[2]);
    delete[] reference;
    return 1;
  } // if
  fseek(file, 0, SEEK_END);
jkvis's avatar
jkvis committed
61
  size_t const sample_length = ftell(file);
J.K. Vis's avatar
J.K. Vis committed
62
63
  rewind(file);
  char_t* sample = new char_t[sample_length];
J.K. Vis's avatar
J.K. Vis committed
64
65
  size_t const alt_length = fread(sample, sizeof(char_t), sample_length, file);
  static_cast<void>(alt_length);
J.K. Vis's avatar
J.K. Vis committed
66
  fclose(file);
J.K. Vis's avatar
J.K. Vis committed
67
*/
jkvis's avatar
jkvis committed
68

69
70
71
72
73
74
75
76
77
  string header[4305];
  string protein[4305];

  for (int i = 0; i < 4305; ++i)
  {
    getline(cin, header[i]);
    getline(cin, protein[i]);
  } // for

J.K. Vis's avatar
J.K. Vis committed
78
  for (int i = 0; i < 4305; ++i)
79
80
  {
    cerr << i << endl;
J.K. Vis's avatar
J.K. Vis committed
81
82
    double best = 1.f;
    for (int j = i + 1; j < 4305; ++j)
83
84
85
86
87
88
    {
      vector<Variant> variant;
      extract(variant, protein[i].c_str(), protein[i].length(), protein[j].c_str(), protein[j].length(), TYPE_PROTEIN, "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF");

      for (std::vector<Variant>::iterator it = variant.begin(); it != variant.end(); ++it)
      {
J.K. Vis's avatar
J.K. Vis committed
89
        if (it->type >= FRAME_SHIFT && best > it->probability)
90
        {
J.K. Vis's avatar
J.K. Vis committed
91
92
          best = it->probability;
          fprintf(stdout, "%.9s %.9s %ld--%ld, %ld--%ld, %d, %.10e\n", header[i].c_str(), header[j].c_str(), it->reference_start, it->reference_end, it->sample_start, it->sample_end, it->type, 1.f - it->probability);
93
94
95
        } // if
      } // for
    } // for
J.K. Vis's avatar
J.K. Vis committed
96
    fprintf(stdout, "\n");
97
98
  } // for

J.K. Vis's avatar
J.K. Vis committed
99
/*
100
  // The actual extraction.
J.K. Vis's avatar
J.K. Vis committed
101
  std::vector<Variant> variant;
102
  size_t const weight = extract(variant, reference, reference_length - 1, sample, sample_length - 1, TYPE_PROTEIN, "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF");
jkvis's avatar
jkvis committed
103

jkvis's avatar
jkvis committed
104

105
  // Printing the variants.
106
  fprintf(stdout, "Variants (%ld / %ld):\n", variant.size(), weight);
J.K. Vis's avatar
J.K. Vis committed
107
  for (std::vector<Variant>::iterator it = variant.begin(); it != variant.end(); ++it)
jkvis's avatar
jkvis committed
108
  {
J.K. Vis's avatar
J.K. Vis committed
109
    if (it->type >= FRAME_SHIFT)
J.K. Vis's avatar
J.K. Vis committed
110
    {
J.K. Vis's avatar
J.K. Vis committed
111
      fprintf(stdout, "%ld--%ld, %ld--%ld, %d, %lf, %ld--%ld\n", it->reference_start, it->reference_end, it->sample_start, it->sample_end, it->type, 1.f - it->probability, it->transposition_start, it->transposition_end);
J.K. Vis's avatar
J.K. Vis committed
112
    } // if
J.K. Vis's avatar
J.K. Vis committed
113
114
115
116
    else
    {
      fprintf(stdout, "%ld--%ld, %ld--%ld, %d, %ld, %ld--%ld\n", it->reference_start, it->reference_end, it->sample_start, it->sample_end, it->type, it->weight, it->transposition_start, it->transposition_end);
    } // else
jkvis's avatar
jkvis committed
117
118
  } // for

119
120

  // Cleaning up.
jkvis's avatar
jkvis committed
121
122
  delete[] reference;
  delete[] sample;
J.K. Vis's avatar
J.K. Vis committed
123
*/
jkvis's avatar
jkvis committed
124
125
126
  return 0;
} // main