Skip to contents

Auxiliary function for getting the largest paths in a graphical solution.

Usage

get_trajectory_sizes_from_edge_sets(
  edge_sets = MotrpacRatTraining6moData::GRAPH_COMPONENTS$edge_sets,
  min_size = 10
)

Arguments

edge_sets

A named list of string vectors. The name of an edge is [node_id]---[node_id] edges with no analytes have a NULL set (a set of size zero, but are still represented), node ids are [timepoint]_F[x]_M[y] where x and y represent the up/down state in each sex. GRAPH_COMPONENTS$edge_sets by default.

min_size

An integer specifying the minimal path size to be considered.

Value

NULL if no paths of size of at least min_size were found, otherwise return a data frame that represents all paths of size min_size or greater, ranked from the largest path to the smallest one.

Details

This is implemented using a dynamic programming approach where we iteratively add the data of the next edge.

When analyzing an edge (x,y) with a set of analytes s, we extend all trajectories that end with x using the new edge, but also all the trajectories that start with y.

At the end, because we examine all edges and all extensions we are guaranteed to have covered all full paths.

The min_size parameter is important, since we are interested in paths and edges with at least this number of analytes, then we know that if a current trajectory does not have at least min_size analytes, then since the set of any extension can only be the same or smaller then we can ignore such paths moving forward.

However, this parameter has to be considered with care, as specifying a number that is too high will result in no paths in the output.

See bayesian_graphical_clustering for more details about the graphical analysis.

Examples

if (FALSE) { # \dontrun{
### Example 1: Simulate data with a single cluster
zcolnames = c(
  paste("female",c("1w","2w","4w","8w"),sep="_"),
  paste("male",c("1w","2w","4w","8w"),sep="_")
)
zscores = matrix(rnorm(80000),ncol=8,dimnames = list(1:10000,zcolnames))
# now add a cluster with a strong signal and rerun
zscores[1:500,1:4] = zscores[1:500,1:4] + 5

# run the clustering solution wrapper
clustering_sol = bayesian_graphical_clustering(zscores)

# extract the top full trajectories in the data
# these should be the clusters with at least 10 features
min_cluster_size=10
get_trajectory_sizes_from_edge_sets(clustering_sol$edge_sets, 
                                    min_size = min_cluster_size)

# extract the edges of the top two full trajectories
# this step "cleans" the edge sets by removing edges of trajectories with very few features
top2traj_edge_sets = filter_edge_sets_by_trajectories(
  clustering_sol$edge_sets, 
  topk = 2, 
  min_path_size = 10
)
# examine the new edge set sizes, excluded edges should have zero size
sapply(top2traj_edge_sets,length)
} # }

### Example 2: Use published data 
get_trajectory_sizes_from_edge_sets()
#>     X1         X2         X3         X4         X5   X6
#> 18  0w  1w_F-1_M1  2w_F-1_M0  4w_F-1_M0  8w_F-1_M0 1459
#> 146 0w   1w_F0_M1   2w_F0_M1   4w_F0_M1   8w_F1_M1 1112
#> 190 0w   1w_F1_M1   2w_F1_M1   4w_F1_M1   8w_F1_M1 1078
#> 122 0w   1w_F0_M0   2w_F0_M0   4w_F0_M0   8w_F1_M1  987
#> 66  0w   1w_F0_M0   2w_F0_M0   4w_F0_M0 8w_F-1_M-1  946
#> 139 0w   1w_F0_M1   2w_F0_M1   4w_F0_M1   8w_F0_M1  824
#> 1   0w 1w_F-1_M-1 2w_F-1_M-1 4w_F-1_M-1 8w_F-1_M-1  718
#> 36  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M0   8w_F0_M1  698
#> 106 0w   1w_F0_M0   2w_F0_M0   4w_F0_M0   8w_F0_M1  594
#> 82  0w   1w_F0_M0   2w_F0_M0   4w_F0_M0  8w_F0_M-1  578
#> 52  0w  1w_F0_M-1  2w_F0_M-1  4w_F0_M-1  8w_F0_M-1  478
#> 74  0w   1w_F0_M1   2w_F0_M1   4w_F0_M0  8w_F-1_M0  476
#> 14  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M0 8w_F-1_M-1  460
#> 184 0w   1w_F0_M1   2w_F0_M1   4w_F1_M1   8w_F1_M1  423
#> 173 0w   1w_F1_M0   2w_F1_M0   4w_F1_M0   8w_F1_M1  403
#> 112 0w  1w_F0_M-1  2w_F0_M-1   4w_F0_M0   8w_F1_M0  396
#> 158 0w   1w_F1_M0   2w_F1_M0   4w_F1_M0   8w_F0_M0  396
#> 159 0w   1w_F1_M0   2w_F1_M1   4w_F1_M0   8w_F0_M0  384
#> 167 0w  1w_F1_M-1   2w_F1_M0   4w_F1_M0   8w_F1_M0  340
#> 144 0w   1w_F0_M0   2w_F0_M0   4w_F0_M1   8w_F1_M1  330
#> 99  0w   1w_F1_M0   2w_F1_M0   4w_F0_M0   8w_F0_M0  327
#> 34  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M0   8w_F0_M0  322
#> 136 0w   1w_F0_M0   2w_F0_M0   4w_F0_M1   8w_F0_M1  303
#> 90  0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0   8w_F0_M0  282
#> 5   0w  1w_F0_M-1  2w_F0_M-1 4w_F-1_M-1 8w_F-1_M-1  278
#> 110 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0   8w_F1_M0  266
#> 57  0w  1w_F0_M-1  2w_F0_M-1  4w_F0_M-1   8w_F0_M0  264
#> 168 0w   1w_F1_M0   2w_F1_M0   4w_F1_M0   8w_F1_M0  251
#> 31  0w 1w_F-1_M-1 2w_F-1_M-1  4w_F-1_M0   8w_F0_M0  250
#> 189 0w   1w_F1_M0   2w_F1_M1   4w_F1_M1   8w_F1_M1  230
#> 76  0w   1w_F1_M0   2w_F1_M0   4w_F0_M0  8w_F-1_M0  223
#> 49  0w   1w_F0_M0   2w_F0_M0  4w_F0_M-1 8w_F-1_M-1  209
#> 6   0w   1w_F0_M0   2w_F0_M0 4w_F-1_M-1 8w_F-1_M-1  208
#> 97  0w   1w_F0_M1   2w_F0_M1   4w_F0_M0   8w_F0_M0  197
#> 43  0w  1w_F-1_M1  2w_F-1_M1  4w_F-1_M1  8w_F-1_M1  196
#> 182 0w   1w_F0_M0   2w_F0_M0   4w_F1_M1   8w_F1_M1  191
#> 187 0w   1w_F1_M0   2w_F1_M0   4w_F1_M1   8w_F1_M1  190
#> 131 0w   1w_F1_M1   2w_F0_M1   4w_F0_M1   8w_F0_M0  185
#> 140 0w   1w_F1_M1   2w_F0_M1   4w_F0_M1   8w_F0_M1  185
#> 130 0w   1w_F0_M1   2w_F0_M1   4w_F0_M1   8w_F0_M0  177
#> 155 0w   1w_F1_M0   2w_F1_M0   4w_F1_M0  8w_F0_M-1  176
#> 177 0w   1w_F1_M1   2w_F1_M1   4w_F1_M1   8w_F0_M0  176
#> 32  0w  1w_F-1_M0 2w_F-1_M-1  4w_F-1_M0   8w_F0_M0  173
#> 16  0w   1w_F0_M0   2w_F0_M0  4w_F-1_M0 8w_F-1_M-1  171
#> 126 0w   1w_F0_M1   2w_F0_M1   4w_F0_M1  8w_F-1_M0  159
#> 166 0w  1w_F0_M-1   2w_F1_M0   4w_F1_M0   8w_F1_M0  159
#> 170 0w   1w_F0_M0   2w_F0_M0   4w_F1_M0   8w_F1_M1  157
#> 4   0w  1w_F-1_M0  2w_F-1_M0 4w_F-1_M-1 8w_F-1_M-1  152
#> 87  0w 1w_F-1_M-1 2w_F-1_M-1   4w_F0_M0   8w_F0_M0  152
#> 101 0w   1w_F1_M1   2w_F1_M1   4w_F0_M0   8w_F0_M0  151
#> 154 0w  1w_F1_M-1  2w_F1_M-1   4w_F1_M0  8w_F0_M-1  151
#> 25  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M0  8w_F-1_M1  149
#> 88  0w  1w_F-1_M0 2w_F-1_M-1   4w_F0_M0   8w_F0_M0  148
#> 64  0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0 8w_F-1_M-1  146
#> 72  0w   1w_F1_M0   2w_F0_M0   4w_F0_M0  8w_F-1_M0  143
#> 100 0w   1w_F1_M0   2w_F1_M1   4w_F0_M0   8w_F0_M0  143
#> 17  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M0  8w_F-1_M0  141
#> 44  0w  1w_F-1_M0  2w_F-1_M0  4w_F-1_M1   8w_F0_M1  138
#> 12  0w 1w_F-1_M-1 2w_F-1_M-1 4w_F-1_M-1   8w_F0_M0  136
#> 165 0w  1w_F1_M-1  2w_F1_M-1   4w_F1_M0   8w_F1_M0  132
#> 21  0w  1w_F-1_M1  2w_F-1_M1  4w_F-1_M0  8w_F-1_M0  128
#> 85  0w   1w_F0_M1   2w_F0_M1   4w_F0_M0  8w_F0_M-1  122
#> 188 0w   1w_F0_M1   2w_F1_M1   4w_F1_M1   8w_F1_M1  120
#> 53  0w   1w_F0_M0   2w_F0_M0  4w_F0_M-1  8w_F0_M-1  116
#> 7   0w 1w_F-1_M-1 2w_F-1_M-1 4w_F-1_M-1  8w_F-1_M0  113
#> 86  0w   1w_F1_M0   2w_F1_M0   4w_F0_M0  8w_F0_M-1  113
#> 83  0w   1w_F1_M0   2w_F0_M0   4w_F0_M0  8w_F0_M-1  112
#> 38  0w   1w_F0_M0   2w_F0_M0  4w_F-1_M0   8w_F0_M1  110
#> 102 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0   8w_F0_M1  109
#> 103 0w  1w_F0_M-1  2w_F0_M-1   4w_F0_M0   8w_F0_M1  108
#> 54  0w  1w_F1_M-1  2w_F1_M-1  4w_F0_M-1  8w_F0_M-1  106
#> 2   0w  1w_F-1_M0 2w_F-1_M-1 4w_F-1_M-1 8w_F-1_M-1  105
#> 124 0w   1w_F1_M0   2w_F1_M0   4w_F0_M0   8w_F1_M1  104
#> 9   0w  1w_F0_M-1  2w_F0_M-1 4w_F-1_M-1  8w_F-1_M0  100
#> 24  0w   1w_F0_M1   2w_F0_M1  4w_F-1_M0  8w_F-1_M0   97
#> 51  0w 1w_F-1_M-1 2w_F-1_M-1  4w_F0_M-1  8w_F0_M-1   96
#> 142 0w   1w_F1_M1   2w_F1_M1   4w_F0_M1   8w_F0_M1   92
#> 11  0w 1w_F-1_M-1 2w_F-1_M-1 4w_F-1_M-1  8w_F0_M-1   88
#> 109 0w  1w_F-1_M0 2w_F-1_M-1   4w_F0_M0   8w_F1_M0   86
#> 125 0w  1w_F-1_M0  2w_F-1_M1   4w_F0_M1  8w_F-1_M0   86
#> 48  0w  1w_F0_M-1  2w_F0_M-1  4w_F0_M-1 8w_F-1_M-1   85
#> 134 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M1   8w_F0_M1   84
#> 186 0w   1w_F1_M1   2w_F0_M1   4w_F1_M1   8w_F1_M1   84
#> 28  0w  1w_F-1_M1  2w_F-1_M1  4w_F-1_M0  8w_F-1_M1   83
#> 133 0w   1w_F1_M1   2w_F1_M1   4w_F0_M1   8w_F0_M0   83
#> 20  0w   1w_F0_M1  2w_F-1_M0  4w_F-1_M0  8w_F-1_M0   82
#> 50  0w  1w_F1_M-1  2w_F1_M-1  4w_F0_M-1 8w_F-1_M-1   81
#> 92  0w  1w_F0_M-1  2w_F0_M-1   4w_F0_M0   8w_F0_M0   81
#> 40  0w  1w_F-1_M1  2w_F-1_M1  4w_F-1_M1  8w_F-1_M0   80
#> 56  0w 1w_F-1_M-1 2w_F-1_M-1  4w_F0_M-1   8w_F0_M0   79
#> 150 0w  1w_F1_M-1  2w_F1_M-1  4w_F1_M-1   8w_F1_M0   76
#> 181 0w   1w_F1_M1   2w_F1_M1   4w_F1_M1   8w_F1_M0   75
#> 143 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M1   8w_F1_M1   74
#> 69  0w   1w_F0_M1  2w_F-1_M0   4w_F0_M0  8w_F-1_M0   72
#> 157 0w  1w_F1_M-1   2w_F1_M0   4w_F1_M0   8w_F0_M0   71
#> 81  0w  1w_F0_M-1  2w_F0_M-1   4w_F0_M0  8w_F0_M-1   70
#> 22  0w   1w_F0_M0   2w_F0_M0  4w_F-1_M0  8w_F-1_M0   68
#> 10  0w   1w_F0_M0   2w_F0_M0 4w_F-1_M-1  8w_F-1_M0   66
#> 29  0w 1w_F-1_M-1 2w_F-1_M-1  4w_F-1_M0  8w_F0_M-1   66
#> 116 0w   1w_F0_M0   2w_F0_M0   4w_F0_M0   8w_F1_M0   65
#> 164 0w   1w_F1_M0   2w_F0_M0   4w_F1_M0   8w_F1_M0   64
#> 148 0w  1w_F1_M-1  2w_F1_M-1  4w_F1_M-1  8w_F1_M-1   63
#> 163 0w   1w_F0_M0   2w_F0_M0   4w_F1_M0   8w_F1_M0   63
#> 62  0w  1w_F0_M-1  2w_F0_M-1  4w_F0_M-1   8w_F1_M0   61
#> 95  0w   1w_F1_M0   2w_F0_M0   4w_F0_M0   8w_F0_M0   57
#> 160 0w   1w_F1_M1   2w_F1_M1   4w_F1_M0   8w_F0_M0   57
#> 117 0w  1w_F0_M-1   2w_F1_M0   4w_F0_M0   8w_F1_M0   56
#> 55  0w   1w_F1_M0   2w_F1_M0  4w_F0_M-1  8w_F0_M-1   55
#> 59  0w  1w_F1_M-1  2w_F1_M-1  4w_F0_M-1   8w_F0_M0   54
#> 60  0w   1w_F1_M0   2w_F1_M0  4w_F0_M-1   8w_F0_M0   54
#> 178 0w   1w_F0_M1   2w_F0_M1   4w_F1_M1   8w_F0_M1   54
#> 15  0w   1w_F0_M0  2w_F-1_M0  4w_F-1_M0 8w_F-1_M-1   53
#> 93  0w 1w_F-1_M-1   2w_F0_M0   4w_F0_M0   8w_F0_M0   51
#> 104 0w  1w_F-1_M0   2w_F0_M0   4w_F0_M0   8w_F0_M1   51
#> 179 0w   1w_F1_M1   2w_F1_M1   4w_F1_M1   8w_F0_M1   51
#> 3   0w  1w_F0_M-1 2w_F-1_M-1 4w_F-1_M-1 8w_F-1_M-1   50
#> 65  0w   1w_F0_M0  2w_F-1_M0   4w_F0_M0 8w_F-1_M-1   50
#> 94  0w  1w_F-1_M0   2w_F0_M0   4w_F0_M0   8w_F0_M0   49
#> 8   0w  1w_F-1_M0  2w_F-1_M0 4w_F-1_M-1  8w_F-1_M0   48
#> 107 0w   1w_F0_M1   2w_F0_M1   4w_F0_M0   8w_F0_M1   48
#> 105 0w  1w_F0_M-1   2w_F0_M0   4w_F0_M0   8w_F0_M1   47
#> 132 0w   1w_F0_M1   2w_F1_M1   4w_F0_M1   8w_F0_M0   47
#> 39  0w   1w_F0_M1   2w_F0_M1  4w_F-1_M0   8w_F0_M1   46
#> 120 0w   1w_F1_M1   2w_F1_M1   4w_F0_M0   8w_F1_M0   46
#> 135 0w  1w_F-1_M1  2w_F-1_M1   4w_F0_M1   8w_F0_M1   46
#> 169 0w   1w_F1_M1   2w_F1_M1   4w_F1_M0   8w_F1_M0   46
#> 171 0w   1w_F1_M0   2w_F0_M0   4w_F1_M0   8w_F1_M1   46
#> 156 0w  1w_F1_M-1  2w_F1_M-1   4w_F1_M0   8w_F0_M0   45
#> 26  0w  1w_F-1_M1  2w_F-1_M0  4w_F-1_M0  8w_F-1_M1   44
#> 61  0w  1w_F0_M-1  2w_F0_M-1  4w_F0_M-1   8w_F0_M1   43
#> 58  0w   1w_F1_M0   2w_F0_M0  4w_F0_M-1   8w_F0_M0   42
#> 121 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0   8w_F1_M1   42
#> 137 0w   1w_F1_M0   2w_F0_M0   4w_F0_M1   8w_F0_M1   42
#> 70  0w   1w_F0_M0   2w_F0_M0   4w_F0_M0  8w_F-1_M0   41
#> 162 0w  1w_F0_M-1  2w_F0_M-1   4w_F1_M0   8w_F1_M0   41
#> 30  0w 1w_F-1_M-1  2w_F-1_M0  4w_F-1_M0  8w_F0_M-1   40
#> 27  0w   1w_F0_M0  2w_F-1_M0  4w_F-1_M0  8w_F-1_M1   39
#> 13  0w  1w_F0_M-1  2w_F0_M-1 4w_F-1_M-1   8w_F0_M0   38
#> 78  0w   1w_F0_M0  2w_F-1_M0   4w_F0_M0  8w_F-1_M1   38
#> 84  0w   1w_F0_M0   2w_F0_M1   4w_F0_M0  8w_F0_M-1   38
#> 175 0w   1w_F0_M1   2w_F0_M1   4w_F1_M1   8w_F0_M0   38
#> 123 0w   1w_F0_M1   2w_F0_M1   4w_F0_M0   8w_F1_M1   37
#> 180 0w   1w_F1_M0   2w_F0_M0   4w_F1_M1   8w_F1_M0   37
#> 79  0w   1w_F0_M1  2w_F-1_M1   4w_F0_M0  8w_F-1_M1   35
#> 152 0w   1w_F0_M0   2w_F0_M0   4w_F1_M0  8w_F0_M-1   35
#> 141 0w   1w_F1_M0   2w_F1_M0   4w_F0_M1   8w_F0_M1   34
#> 176 0w   1w_F1_M1   2w_F0_M1   4w_F1_M1   8w_F0_M0   34
#> 183 0w   1w_F0_M0   2w_F0_M1   4w_F1_M1   8w_F1_M1   34
#> 19  0w   1w_F0_M0  2w_F-1_M0  4w_F-1_M0  8w_F-1_M0   33
#> 111 0w   1w_F0_M0  2w_F-1_M0   4w_F0_M0   8w_F1_M0   33
#> 68  0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0  8w_F-1_M0   31
#> 80  0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M0  8w_F0_M-1   31
#> 47  0w  1w_F0_M-1 2w_F-1_M-1  4w_F0_M-1 8w_F-1_M-1   29
#> 63  0w  1w_F0_M-1  2w_F1_M-1  4w_F0_M-1   8w_F1_M0   29
#> 75  0w   1w_F0_M0   2w_F1_M0   4w_F0_M0  8w_F-1_M0   29
#> 153 0w   1w_F1_M0   2w_F0_M0   4w_F1_M0  8w_F0_M-1   29
#> 33  0w 1w_F-1_M-1  2w_F-1_M0  4w_F-1_M0   8w_F0_M0   28
#> 98  0w  1w_F0_M-1   2w_F1_M0   4w_F0_M0   8w_F0_M0   28
#> 119 0w   1w_F1_M0   2w_F1_M1   4w_F0_M0   8w_F1_M0   28
#> 128 0w  1w_F-1_M0  2w_F-1_M0   4w_F0_M1   8w_F0_M0   28
#> 138 0w   1w_F0_M0   2w_F0_M1   4w_F0_M1   8w_F0_M1   28
#> 37  0w   1w_F0_M0  2w_F-1_M0  4w_F-1_M0   8w_F0_M1   27
#> 114 0w  1w_F-1_M0   2w_F0_M0   4w_F0_M0   8w_F1_M0   27
#> 149 0w  1w_F0_M-1  2w_F0_M-1  4w_F1_M-1   8w_F1_M0   27
#> 185 0w   1w_F1_M0   2w_F0_M1   4w_F1_M1   8w_F1_M1   27
#> 41  0w   1w_F0_M1  2w_F-1_M1  4w_F-1_M1  8w_F-1_M0   26
#> 45  0w   1w_F0_M1  2w_F-1_M1  4w_F-1_M1   8w_F0_M1   26
#> 129 0w  1w_F-1_M0   2w_F0_M1   4w_F0_M1   8w_F0_M0   26
#> 161 0w   1w_F1_M0   2w_F1_M0   4w_F1_M0  8w_F1_M-1   26
#> 71  0w   1w_F0_M1   2w_F0_M0   4w_F0_M0  8w_F-1_M0   25
#> 115 0w  1w_F0_M-1   2w_F0_M0   4w_F0_M0   8w_F1_M0   25
#> 147 0w  1w_F1_M-1  2w_F1_M-1  4w_F1_M-1  8w_F0_M-1   25
#> 23  0w  1w_F-1_M1   2w_F0_M1  4w_F-1_M0  8w_F-1_M0   24
#> 127 0w  1w_F-1_M1  2w_F-1_M1   4w_F0_M1  8w_F-1_M1   24
#> 145 0w   1w_F0_M0   2w_F0_M1   4w_F0_M1   8w_F1_M1   24
#> 174 0w   1w_F1_M0   2w_F1_M1   4w_F1_M0   8w_F1_M1   24
#> 113 0w   1w_F0_M0  2w_F0_M-1   4w_F0_M0   8w_F1_M0   23
#> 151 0w   1w_F1_M0   2w_F1_M0  4w_F1_M-1   8w_F1_M0   23
#> 46  0w   1w_F0_M1   2w_F0_M1  4w_F-1_M1   8w_F0_M1   22
#> 35  0w 1w_F-1_M-1  2w_F-1_M0  4w_F-1_M0   8w_F0_M1   21
#> 96  0w   1w_F1_M1   2w_F0_M0   4w_F0_M0   8w_F0_M0   21
#> 172 0w   1w_F0_M0   2w_F1_M0   4w_F1_M0   8w_F1_M1   21
#> 108 0w   1w_F1_M0   2w_F1_M0   4w_F0_M0   8w_F0_M1   20
#> 118 0w   1w_F1_M0   2w_F1_M0   4w_F0_M0   8w_F1_M0   18
#> 42  0w   1w_F0_M1   2w_F0_M1  4w_F-1_M1  8w_F-1_M0   17
#> 73  0w   1w_F0_M0   2w_F0_M1   4w_F0_M0  8w_F-1_M0   17
#> 91  0w  1w_F-1_M0  2w_F0_M-1   4w_F0_M0   8w_F0_M0   17
#> 67  0w   1w_F0_M1   2w_F0_M1   4w_F0_M0 8w_F-1_M-1   14
#> 89  0w  1w_F0_M-1 2w_F-1_M-1   4w_F0_M0   8w_F0_M0   13
#> 77  0w   1w_F1_M0   2w_F1_M1   4w_F0_M0  8w_F-1_M0   11