File: ProjectPairwise.cc

package info (click to toggle)
probcons 1.12-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 668 kB
  • sloc: cpp: 7,263; xml: 567; makefile: 114; sh: 21
file content (72 lines) | stat: -rw-r--r-- 1,718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/////////////////////////////////////////////////////////////////
// ProjectPairwise
//
// Program for projecting multiple alignments to all pairwise
// alignments.
/////////////////////////////////////////////////////////////////

#include "SafeVector.h"
#include "MultiSequence.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <set>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <iomanip>

bool compressGaps = true;

/////////////////////////////////////////////////////////////////
// main()
//
// Main program.
/////////////////////////////////////////////////////////////////

int main (int argc, char **argv){

  // check arguments
  if (argc < 2){
    cerr << "Usage: project ALIGNMENT [-nocompressgaps]" << endl;
    exit (1);
  }

  for (int i = 2; i < argc; i++){
    if (strcmp (argv[i], "-nocompressgaps") == 0)
      compressGaps = false;
    else {
      cerr << "Unrecognized option: " << argv[i] << endl;
      exit (1);
    }
  }

  MultiSequence *align = new MultiSequence (string (argv[1])); assert (align);

  int N = align->GetNumSequences();
  for (int i = 0; i < N; i++){
    for (int j = i+1; j < N; j++){
      string name = align->GetSequence(i)->GetHeader() + "-" + align->GetSequence(j)->GetHeader() + ".fasta";
      ofstream outfile (name.c_str());

      if (compressGaps){
	set<int> s;
	s.insert (i); s.insert (j);
	MultiSequence *proj = align->Project (s);
	proj->WriteMFA (outfile);
	delete proj;
      }
      else {
	align->GetSequence(i)->WriteMFA (outfile, 60);
	align->GetSequence(j)->WriteMFA (outfile, 60);
      }
      outfile.close();
    }
  }

  delete align;
}