@@ -22,6 +22,10 @@ def clade_nodes
22
22
end
23
23
return clades
24
24
end
25
+
26
+ def unquoted_taxa
27
+ self . taxa . map { |str | str . tr %q{"'} , "" }
28
+ end
25
29
end
26
30
27
31
# Top level namespace of the Gem.
@@ -82,8 +86,10 @@ def low_ent_cols leaves, leaf2attrs, entropy_cutoff
82
86
Set . new low_ent_cols
83
87
end
84
88
89
+ # @note If there are quoted names in the tree file, they are
90
+ # unquoted first.
85
91
def check_ids tree , mapping , aln
86
- tree_ids = Set . new ( NewickTree . fromFile ( tree ) . taxa )
92
+ tree_ids = Set . new ( NewickTree . fromFile ( tree ) . unquoted_taxa )
87
93
88
94
mapping_ids = Set . new
89
95
File . open ( mapping , "rt" ) . each_line . with_index do |line , idx |
@@ -143,8 +149,11 @@ def snazzy_clades tree, metadata
143
149
metadata . each do |md_cat , leaf2mdtag |
144
150
already_checked = Set . new
145
151
single_tag_clades = { }
152
+ p [ md_cat , leaf2mdtag ]
146
153
147
154
clades . each do |clade |
155
+ p [ clade . name , clade . all_leaves ]
156
+
148
157
assert clade . all_leaves . count > 1 ,
149
158
"A clade cannot also be a leaf"
150
159
@@ -173,7 +182,7 @@ def snazzy_clades tree, metadata
173
182
end
174
183
175
184
single_tag_clades . each do |clade , md_tag |
176
- non_clade_leaves = tree . taxa - clade . all_leaves
185
+ non_clade_leaves = tree . unquoted_taxa - clade . all_leaves
177
186
178
187
non_clade_leaves_with_this_md_tag = non_clade_leaves . map do |leaf |
179
188
[ leaf , leaf2mdtag [ leaf ] ]
@@ -288,10 +297,15 @@ class Clade
288
297
:single_tag_info ,
289
298
:all_tags
290
299
300
+ # @note If a node name is quoted, then those quotes are removed
301
+ # first.
302
+ #
291
303
# @param node [NewickNode] a NewickNode from a NewickTree
292
304
# @param tree [NewickTree] a NewickTree
293
305
def initialize node , tree , metadata = nil
294
- @name = node . name
306
+ tree_taxa = tree . unquoted_taxa
307
+
308
+ @name = unquote node . name
295
309
@all_leaves = descendant_leaves node
296
310
297
311
if ( children = node . children ) . count == 2
@@ -317,10 +331,10 @@ def initialize node, tree, metadata=nil
317
331
@parent_leaves = descendant_leaves parent
318
332
319
333
@other_leaves =
320
- Object ::Set . new ( tree . taxa ) - Object ::Set . new ( all_leaves )
334
+ Object ::Set . new ( tree_taxa ) - Object ::Set . new ( all_leaves )
321
335
322
336
@non_parent_leaves =
323
- Object ::Set . new ( tree . taxa ) - Object ::Set . new ( parent_leaves )
337
+ Object ::Set . new ( tree_taxa ) - Object ::Set . new ( parent_leaves )
324
338
325
339
if metadata
326
340
@metadata = metadata
@@ -345,7 +359,8 @@ def == clade
345
359
self . each_sibling_leaf_set == clade . each_sibling_leaf_set &&
346
360
self . parent_leaves == clade . parent_leaves &&
347
361
self . other_leaves == clade . other_leaves &&
348
- self . single_tag_info == clade . single_tag_info
362
+ self . single_tag_info == clade . single_tag_info &&
363
+ self . all_tags == clade . all_tags
349
364
)
350
365
end
351
366
@@ -379,14 +394,19 @@ def get_all_tags
379
394
380
395
def descendant_leaves node
381
396
if node . leaf?
382
- [ node . name ]
397
+ [ unquote ( node . name ) ]
383
398
else
384
399
node .
385
400
descendants .
386
401
flatten .
387
402
uniq .
388
- select { |node | node . leaf? } . map ( &:name )
403
+ select { |node | node . leaf? } .
404
+ map { |node | unquote ( node . name ) }
389
405
end
390
406
end
407
+
408
+ def unquote str
409
+ str . tr %q{"'} , ""
410
+ end
391
411
end
392
412
end
0 commit comments