debug.cc 2.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
// *******************************************************************
//   (C) Copyright 2014 Leiden Institute of Advanced Computer Science
//   Universiteit Leiden
//   All Rights Reserved
// *******************************************************************
// Extractor (library)
// *******************************************************************
// FILE INFORMATION:
//   File:     debug.cc
//   Author:   Jonathan K. Vis
J.K. Vis's avatar
J.K. Vis committed
11
12
//   Revision: 2.1.1
//   Date:     2014/08/21
13
14
15
16
17
18
19
20
// *******************************************************************
// 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
21
22
23
#include "extractor.h"
using namespace mutalyzer;

jkvis's avatar
jkvis committed
24
25
#include <cstdio>

26
// Entry point.
jkvis's avatar
jkvis committed
27
int main(int argc, char* argv[])
jkvis's avatar
jkvis committed
28
{
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);
jkvis's avatar
jkvis committed
67

jkvis's avatar
jkvis committed
68

69
  // The actual extraction.
J.K. Vis's avatar
J.K. Vis committed
70
71
  std::vector<Variant> variant;
  size_t const weight = extract(variant, reference, reference_length, sample, sample_length);
jkvis's avatar
jkvis committed
72

jkvis's avatar
jkvis committed
73

74
75
  // Printing the variants.
  fprintf(stdout, "\nVariants (%ld / %ld):\n", variant.size(), weight);
J.K. Vis's avatar
J.K. Vis committed
76
  for (std::vector<Variant>::iterator it = variant.begin() ; it != variant.end(); ++it)
jkvis's avatar
jkvis committed
77
  {
J.K. Vis's avatar
J.K. Vis committed
78
79
    //if (it->type != IDENTITY)
    {
80
      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);
J.K. Vis's avatar
J.K. Vis committed
81
    } // if
jkvis's avatar
jkvis committed
82
83
  } // for

84
85

  // Cleaning up.
jkvis's avatar
jkvis committed
86
87
88
  delete[] reference;
  delete[] sample;

jkvis's avatar
jkvis committed
89
90
91
  return 0;
} // main