File: isomorphic.cpp

package info (click to toggle)
iqtree 2.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 14,620 kB
  • sloc: cpp: 142,571; ansic: 57,789; sh: 275; python: 242; makefile: 95
file content (67 lines) | stat: -rw-r--r-- 1,541 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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <terraces/parser.hpp>
#include <terraces/rooting.hpp>
#include <terraces/trees.hpp>
#include <vector>

#include "../lib/validation.hpp"

using namespace terraces;

std::vector<tree> read_trees(std::string file) {
	std::vector<tree> trees;
	auto tree_file = std::ifstream{file};
	auto tree_string = std::string{};
	index_map indices;
	while (tree_string.empty()) {
		std::getline(tree_file, tree_string);
	}
	{
		auto fst_tree = parse_new_nwk(tree_string);
		indices = fst_tree.indices;
		trees.push_back(fst_tree.tree);
	}

	do {
		std::getline(tree_file, tree_string);
		if (tree_string.empty()) {
			continue;
		}
		trees.push_back(parse_nwk(tree_string, indices));
	} while (!tree_file.eof());

	return trees;
}

int main(int argc, char* argv[]) {
	if (argc != 3) {
		return 1;
	}
	auto fst = read_trees(argv[1]);
	auto snd = read_trees(argv[2]);
	std::cout << "pairwise comparison\n";
	std::cout << std::noboolalpha;
	for (auto& t_fst : fst) {
		for (auto& t_snd : snd) {
			std::cout << is_isomorphic_unrooted(t_fst, t_snd) << " ";
		}
		std::cout << "\n";
	}
	std::cout << "comparison inside first group\n";
	for (auto& t_fst : fst) {
		for (auto& t_snd : fst) {
			std::cout << is_isomorphic_unrooted(t_fst, t_snd) << " ";
		}
		std::cout << "\n";
	}
	std::cout << "comparison inside second group\n";
	for (auto& t_fst : snd) {
		for (auto& t_snd : snd) {
			std::cout << is_isomorphic_unrooted(t_fst, t_snd) << " ";
		}
		std::cout << "\n";
	}
}