Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
tools_treecluster.py

Using the matrix_science::ms_treecluster class.

1#!/usr/bin/python
2
16
17import msparser
18
19rows = 11
20cols = 5
21tc = msparser.ms_treecluster(rows, cols)
22
23data = msparser.vectord()
24mask = msparser.vectori()
25
26data.append(1.623866862); data.append(-0.052894948); data.append(1.182692298); data.append(2.298658316); data.append(1.13422094)
27mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
28tc.setRow(0 , data, mask); data.clear(); mask.clear()
29
30data.append(1.156396617); data.append(0.0000000000); data.append(0.521050737); data.append(1.544979883); data.append(0.65718266)
31mask.append(1); mask.append(0); mask.append(1); mask.append(1); mask.append(1)
32tc.setRow(1 , data, mask); data.clear(); mask.clear()
33
34data.append(1.523561956); data.append(-0.017417053); data.append(1.168000125); data.append(2.459693903); data.append(1.308011315)
35mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
36tc.setRow(2 , data, mask); data.clear(); mask.clear()
37
38data.append(1.55875743); data.append(-0.241270432); data.append(0.440420721); data.append(2.427337989); data.append(1.043344505)
39mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
40tc.setRow(3 , data, mask); data.clear(); mask.clear()
41
42data.append(1.449957484); data.append(-0.169744676); data.append(0.867896464); data.append(2.418999465); data.append(1.171206827)
43mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
44tc.setRow(4 , data, mask); data.clear(); mask.clear()
45
46data.append(1.171206827); data.append(0.0000000000); data.append(0.854394678); data.append(2.075532631); data.append(0.950095094)
47mask.append(1); mask.append(0); mask.append(1); mask.append(1); mask.append(1)
48tc.setRow(5 , data, mask); data.clear(); mask.clear()
49
50data.append(1.361768359); data.append(-0.120294234); data.append(0.992043276); data.append(2.238786860); data.append(1.090175950)
51mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
52tc.setRow(6 , data, mask); data.clear(); mask.clear()
53
54data.append(1.781149852); data.append(0.0028825090); data.append(1.079975377); data.append(2.464929601); data.append(1.301002256)
55mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
56tc.setRow(7 , data, mask); data.clear(); mask.clear()
57
58data.append(-1.227692025); data.append(-3.522840789);data.append(-2.434402824);data.append(-0.873027144);data.append(-1.977099598)
59mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
60tc.setRow(8 , data, mask); data.clear(); mask.clear()
61
62data.append(1.272023189); data.append(-0.535331733); data.append(0.608809243); data.append(2.004681156); data.append(0.826192536)
63mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
64tc.setRow(9 , data, mask); data.clear(); mask.clear()
65
66data.append(1.069014678); data.append(-0.623709617); data.append(0.412510571); data.append(1.82822536); data.append(0.650764559)
67mask.append(1); mask.append(1); mask.append(1); mask.append(1); mask.append(1)
68tc.setRow(10 , data, mask); data.clear(); mask.clear()
69
70weights = msparser.vectord()
71left = msparser.vectori()
72right = msparser.vectori()
73distance = msparser.vectord()
74
75if not tc.cluster(msparser.ms_treecluster.TCD_EUCLIDEAN, msparser.ms_mascotresults.TCM_PAIRWISE_AVERAGE, weights, left, right, distance):
76 print("Failed")
77else:
78 print("Node\tleft\tright\tdistance\n")
79 for i in range(0, len(left)):
80 node = -1 - i
81 print("%d \t %d \t %d \t %.16f " % (node, left[i], right[i], distance[i]))
82
83"""
84tools_treecluster.py
85Will give the following output:
86
87Node left right distance
88
89-1 6 4 0.0129355369880599
90-2 2 0 0.0135342339743674
91-3 7 -2 0.0168450469179865
92-4 5 9 0.0227119800299183
93-5 10 1 0.0249214407900277
94-6 -1 -3 0.0358259860933716
95-7 -4 -5 0.0759763042954681
96-8 3 -6 0.0985921612204670
97-9 -7 -8 0.2259074963919064
98-10 8 -9 9.2461259564223610
99"""
100