@@ -315,6 +315,7 @@ as.logical.Splits <- function(x, tipLabels = attr(x, "tip.label"), ...) {
315315print.Splits <- function (x , details = FALSE , ... ) {
316316 nTip <- attr(x , " nTip" )
317317 tipLabels <- attr(x , " tip.label" )
318+ count <- attr(x , " count" )
318319 trivial <- TrivialSplits(x )
319320 cat(dim(x )[1 ], " bipartition" , ifelse(dim(x )[1 ] == 1 , " split" , " splits" ),
320321 if (any(trivial )) paste0(" (" , sum(trivial ), " trivial)" ),
@@ -324,9 +325,9 @@ print.Splits <- function(x, details = FALSE, ...) {
324325 } else {
325326 if (nTip ) {
326327 if (nTip == 1 ) {
327- paste(" tip," , tipLabels [1 ])
328+ paste(" tip," , tipLabels [[ 1 ] ])
328329 } else {
329- paste(" tips," , tipLabels [1 ] , " .." , tipLabels [nTip ])
330+ paste(" tips," , tipLabels [[ 1 ]] , " .." , tipLabels [[ nTip ] ])
330331 }
331332 } else {
332333 " tips"
@@ -345,18 +346,57 @@ print.Splits <- function(x, details = FALSE, ...) {
345346 splitNames <- character (length(x ))
346347 nameLengths = 0L
347348 }
348- cat(" \n " , paste0(rep.int(" " , max(nameLengths )), collapse = " " ),
349+ if (length(splitNames ) > 0 ) {
350+ cat(" \n " , paste0(rep.int(" " , max(nameLengths )), collapse = " " ),
349351 paste0(rep_len(c(1 : 9 , " " ), nTip ), collapse = " " ))
350-
351- for (i in seq_len(dim(x )[1 ])) {
352- split <- x [i , , drop = FALSE ]
353- cat(" \n " , splitNames [i ], " " ,
354- paste(ifelse(as.logical(rawToBits(split )[seq_len(nTip )]), " *" , " ." ),
355- collapse = " " ))
352+
353+
354+ nSplits <- dim(x )[[1 ]]
355+ splitCounts <- if (! is.null(count )) {
356+ if (length(count ) != nSplits ) {
357+ warning(" \" count\" attribute does not match number of splits" )
358+ }
359+ paste0(" \U D7 " , count )
360+ } else {
361+ rep(" " , nSplits )
362+ }
363+
364+ for (i in seq_len(nSplits )) {
365+ split <- x [i , , drop = FALSE ]
366+ cat(" \n " , splitNames [i ], " " ,
367+ paste(ifelse(as.logical(rawToBits(split )[seq_len(nTip )]), " *" , " ." ),
368+ collapse = " " ),
369+ splitCounts [i ])
370+ }
356371 }
357372 }
358373}
359374
375+ # ' @family Splits operations
376+ # ' @export
377+ sort.Splits <- function (x , decreasing = TRUE , ... ) {
378+ newOrder <- order(x , decreasing = decreasing , ... )
379+ count <- attr(x , " count" )
380+ if (is.null(count )) {
381+ x [[newOrder ]]
382+ } else {
383+ structure(x [[newOrder ]], count = count [newOrder ])
384+ }
385+ }
386+
387+ # Underpins `order`
388+ # ' @family Splits operations
389+ # ' @export
390+ xtfrm.Splits <- function (x ) {
391+ count <- attr(x , " count" )
392+ splitRanking <- as.integer(x )
393+ if (is.null(count )) {
394+ splitRanking
395+ } else {
396+ count + (splitRanking / max(splitRanking ))
397+ }
398+ }
399+
360400# ' @family Splits operations
361401# ' @importFrom utils head
362402# ' @export
@@ -390,11 +430,14 @@ tail.Splits <- function(x, n = 6L, ...) {
390430summary.Splits <- function (object , ... ) {
391431 print(object , details = TRUE , ... )
392432 nTip <- attr(object , " nTip" )
393- if (is.null(attr(object , " tip.label" ))) {
433+ tipLabels <- attr(object , " tip.label" )
434+ if (is.null(tipLabels )) {
394435 cat(" \n\n Tips not labelled." )
395436 } else {
396- cat(" \n\n " , paste0(" Tip " , seq_len(nTip ), " : " , attr(object , " tip.label" ),
397- " \t " , c(character (4L ), " \n " )[seq_len(min(nTip , 5L ))]))
437+ if (length(tipLabels ) > 0 ) {
438+ cat(" \n\n " , paste0(" Tip " , seq_len(nTip ), " : " , tipLabels ,
439+ " \t " , c(character (4L ), " \n " )[seq_len(min(nTip , 5L ))]))
440+ }
398441 }
399442}
400443
@@ -584,7 +627,7 @@ rev.Splits <- function(x) {
584627
585628# ' Polarize splits on a single taxon
586629# '
587- # ' @param x Object of class [`Splits`].
630+ # ' @param x Object that can be coerced into class [`Splits`].
588631# ' @param pole Numeric, character or logical vector identifying tip that will
589632# ' polarize each split.
590633# '
@@ -593,6 +636,7 @@ rev.Splits <- function(x) {
593636# ' @family Splits operations
594637# ' @export
595638PolarizeSplits <- function (x , pole = 1L ) {
639+ x <- as.Splits(x )
596640 nTip <- attr(x , " nTip" )
597641 if (is.logical(pole )) {
598642 pole <- which(pole )[[1 ]]
0 commit comments