Applied process

Amin Bazaz, Heraldo Borges, Eduardo Ogasawara

2018-08-23

This documentation is intended to present the outputs of a sample dataset.

#> foreach: simple, scalable parallel programming from Revolution Analytics
#> Use Revolution R for scalability, fault tolerance and more.
#> http://www.revolutionanalytics.com

Launch the workflow to find the motifs

The workflow consists of 3 steps described in the main package documentation. These 3 steps will be applied on our sample.

  1. The function STSIdentifyCandidateSTMotifs allows to generate the candidates:

# The process is launched on the provided example dataset
dim(STMotif::example_dataset)
#> [1] 100  50


# Generation of candidates
candidates <- STSIdentifyCandidateSTMotifs(data = STMotif::example_dataset, tslice = 25, sslice = 10, alpha = 7, window_size = 3)
#> 1/20 - 5%
#> 2/20 - 10%
#> 3/20 - 15%
#> 4/20 - 20%
#> 5/20 - 25%
#> 6/20 - 30%
#> 7/20 - 35%
#> 8/20 - 40%
#> 9/20 - 45%
#> 10/20 - 50%
#> 11/20 - 55%
#> 12/20 - 60%
#> 13/20 - 65%
#> 14/20 - 70%
#> 15/20 - 75%
#> 16/20 - 80%
#> 17/20 - 85%
#> 18/20 - 90%
#> 19/20 - 95%
#> 20/20 - 100%


# Information of the block 1
# The candidates built 
head(candidates$motifs[[1]]$Subs)[1:3,]
#>          [,1]       [,2]        [,3]       [,4]
#> result.1    1  0.4267144 -0.06625811 -0.5016810
#> result.2    4 -1.1292980 -0.64609802  0.3268169
#> result.3    7  0.2030308  0.35613463  0.8545364

# The candidates built with SAX
head(candidates$motifs[[1]]$Subs.SAX)[1:3,]
#>          StartPosition 1 2 3
#> result.1             1 e d d
#> result.2             4 c c e
#> result.3             7 e e f

# Grouping identical candidates 
head(candidates$motifs[[1]]$Motif.raw)[1:3]
#> [[1]]
#>           [,1]      [,2]      [,3]      [,4]
#> result.3     7 0.2030308 0.3561346 0.8545364
#> result.22   64 0.2714389 0.2475504 0.6927458
#> result.55  163 0.1813140 0.1020475 0.6710290
#> 
#> [[2]]
#>           [,1]      [,2]      [,3]         [,4]
#> result.9    25 1.1075377 1.0923359  0.239949483
#> result.45  133 0.8208752 0.6514838  0.179142301
#> result.46  136 0.9924384 1.5158145  0.432143611
#> result.71  211 1.5462181 1.0554172 -0.006536772
#> result.79  235 0.8165319 1.0467305  0.525526069
#> 
#> [[3]]
#>           [,1]      [,2]       [,3]      [,4]
#> result.11   31 -0.384410 0.09010321 0.7763557
#> result.62  184 -0.411556 0.38436654 1.5342738

# Grouping identical motifs with SAX
head(candidates$motifs[[1]]$Motif.SAX)[1:3]
#> [[1]]
#>           StartPosition 1 2 3
#> result.3              7 e e f
#> result.22            64 e e f
#> result.55           163 e e f
#> 
#> [[2]]
#>           StartPosition 1 2 3
#> result.9             25 f f e
#> result.45           133 f f e
#> result.46           136 f f e
#> result.71           211 f f e
#> result.79           235 f f e
#> 
#> [[3]]
#>           StartPosition 1 2 3
#> result.11            31 d e f
#> result.62           184 d e f

# Grouping the starting position of identical candidates in the combined series
head(candidates$motifs[[1]]$Indices)[1:3]
#> $eef
#> [1]   7  64 163
#> 
#> $ffe
#> [1]  25 133 136 211 235
#> 
#> $def
#> [1]  31 184


# Number of blocks in horizontal and vertical
c(candidates$nrows,candidates$ncols)
#> [1] 4 5


# Position of the block 1 into the original dataset
candidates$rectangles[[1]]
#> sS eS sT eT nr nc 
#>  1 10  1 25  1  1

# Values of block 1
head(candidates$blocks$datasets[[1]])[1:3,]
#>        1    2    3    4    5   6    7     8    9  10
#> 360  737 1350  869  750 1138 758 1006  1095   99 -83
#> 361  283  565  504  317 1849 944  -80  -895 -936 906
#> 362 -118 -375 -564 -803  870 472 -922 -1009 -698 741


# Encoded values of block 1
head(candidates$saxblocks$datasets[[1]])[1:3,]
#>   1 2 3 4 5 6 7 8 9 10
#> 1 e f e e f e f f d  d
#> 2 d e e d f f d b b  e
#> 3 d c c c e e b b c  e
  1. The functions STSIdentifySTMotifs and STSIdentifyTightSTMotifs allows to check and filter the candidates:
stmotifs <- STSIdentifySTMotifs(candidates = candidates, ka = 1, si = 1)

# Output of the first selected motif
stmotifs[[1]]
#> $saxcod
#>          1 2 3
#> result.3 e e f
#> 
#> $isaxcod
#> [1] "eef"
#> 
#> $recmatrix
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    0    0    2    0    0
#> [3,]    0    0    0    0    0
#> [4,]    0    0    0    0    0
#> 
#> $vecst
#>    s  t
#> 1  1  8
#> 2  3 15
#> 3  7 14
#> 4 26 37
#> 5 28 26
sttightmotifs <- STSIdentifyTightSTMotifs(stmotifs = stmotifs, rectangles = candidates$rectangles)

# Output of the first motif after removing the isolated
sttightmotifs[[1]]
#> $saxcod
#>          1 2 3
#> result.3 e e f
#> 
#> $isaxcod
#> [1] "eef"
#> 
#> $recmatrix
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    0    0    0    0    0
#> [3,]    0    0    0    0    0
#> [4,]    0    0    0    0    0
#> 
#> $vecst
#>   s  t
#> 1 1  8
#> 2 3 15
#> 3 7 14
#> 
#> $SOtight
#> [1] 3
#> 
#> $GOtight
#> [1] 3
#> 
#> $SO
#> [1] 5
#> 
#> $GO
#> [1] 5
  1. The function STSRankTightSTMotifs allows to rank the selected motifs by their quality:
ranksttightmotifs <- STSRankTightSTMotifs(sttightmotifs = sttightmotifs)

# Motif with the better quality
ranksttightmotifs[[1]]
#> $saxcod
#>           1 2 3
#> result.16 g g g
#> 
#> $isaxcod
#> [1] "ggg"
#> 
#> $recmatrix
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    0    0    0    0    0
#> [2,]    0    0    0    0    0
#> [3,]    1    1    0    0    0
#> [4,]    0    1    0    0    0
#> 
#> $vecst
#>     s  t
#> 1   2 72
#> 2   3 71
#> 3   5 72
#> 4   7 73
#> 5   9 74
#> 6  11 55
#> 7  17 61
#> 8  18 63
#> 9  12 76
#> 10 13 78
#> 11 13 96
#> 12 14 77
#> 13 15 79
#> 14 16 81
#> 15 17 80
#> 16 18 82
#> 17 19 81
#> 18 20 83
#> 
#> $SOtight
#> [1] 15
#> 
#> $GOtight
#> [1] 18
#> 
#> $SO
#> [1] 41
#> 
#> $GO
#> [1] 48
#> 
#> $objfunc
#> [1] 0.9375

Plot the result

The function runVisualization allows to launch the shiny application to see the result. There are two ways to visualize the result.

# Plot the intensity of the dataset and highlight one selected motif
intensityDataset(dataset = STMotif::example_dataset,rankList = ranksttightmotifs,position = 1,alpha = 7)

# Plot five specific spatial-series which some of them contain the best motif
displayPlotSeries(dataset = STMotif::example_dataset, rankList = ranksttightmotifs ,position = 1 ,space = c(1,2,5:7))