-
Notifications
You must be signed in to change notification settings - Fork 20
/
test_gGnome_ops.R
1700 lines (1297 loc) · 62.3 KB
/
test_gGnome_ops.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
library(testthat)
library(gUtils)
library(gTrack)
setDTthreads(1)
svaba = system.file('extdata', "HCC1143.svaba.somatic.sv.vcf", package = "gGnome")
delly = system.file('extdata', "delly.final.vcf.gz", package = "gGnome")
novobreak = system.file('extdata', "novoBreak.pass.flt.vcf", package = "gGnome")
HGSL = c("1"=249250621, "2"=243199373, "3"=198022430, "4"=191154276, "5"=180915260, "6"=171115067, "7"=159138663, "X"=155270560, "8"=146364022, "9"=141213431, "10"=135534747, "11"=135006516, "12"=133851895, "13"=115169878, "14"=107349540, "15"=102531392, "16"=90354753, "17"=81195210, "18"=78077248, "20"=63025520, "Y"=59373566, "19"=59128983, "22"=51304566, "21"=48129895, "M"=16571)
context('testing gGnome')
setDTthreads(1)
message("Toy segments: ", system.file('extdata', 'testing.segs.rds', package="gGnome"))
test_segs = readRDS(system.file('extdata', 'testing.segs.rds', package="gGnome"))
message("Toy edges: ", system.file('extdata', 'testing.es.rds', package="gGnome"))
test_es = readRDS(system.file('extdata', 'testing.es.rds', package="gGnome"))
jab = system.file('extdata', 'jabba.simple.rds', package="gGnome")
message("JaBbA result: ", jab)
jab.gw.grl = system.file('extdata', 'gw.grl.rds', package = "gGnome")
message("Example JaBbA genome walks: ", jab.gw.grl)
prego = system.file('extdata', 'intervalFile.results', package='gGnome')
message("PREGO results: ", prego)
weaver = system.file('extdata', 'weaver', package='gGnome')
message("Weaver results: ", weaver)
remixt = system.file('extdata', 'remixt', package='gGnome')
message("remixt results: ", remixt)
genome = seqinfo(test_segs)
test_that('json, swap, connect, print', {
})
test_that('fitcn, simple/TRA', { # we include the test for TRA here since h526 has TRA
setDTthreads(1)
# picking h526 since it has a small cluster that we can use as a light weight test case
ccle = dir(system.file("extdata", package = "gGnome"), ".+jabba.simple.rds", full = TRUE)
names(ccle) = gsub(".*gGnome/.*extdata/(.*)\\.jabba\\.simple\\.rds$", "\\1", ccle)
h526 = gG(jabba = ccle["NCI_H526"])
# cluster 8 has just 5 nodes so we use this one
h526$clusters(mode = "weak")
sg = h526$copy$nodes[cluster == 8]$subgraph
wks = sg$walks()
wks2 = wks$copy # take a separate object to test the R6 method
res = gGnome::fitcn(wks, verbose = TRUE)
notrim = gGnome::fitcn(wks, trim = FALSE)
edgeonly = gGnome::fitcn(wks, edgeonly = TRUE)
# TODO: not testing evolve since it errors
# evolve = gGnome::fitcn(wks, evolve = TRUE)
min.alt = gGnome::fitcn(wks, min.alt = FALSE)
weighted = gGnome::fitcn(wks, weight = seq_along(wks))
wks$set(weight = seq_along(wks))
weighted_by_field = gGnome::fitcn(wks)
expect_error(gGnome::fitcn(wks, cn.field = 'not.a.field'))
sol = gGnome::fitcn(wks, return.gw = FALSE)
# TODO: not adding a test for obs.mat for now since it is failing.
obs.mat = matrix(1, nrow = length(wks), ncol = length(wks))
res = gGnome::fitcn(wks, obs.mat = obs.mat, verbose = TRUE)
foo = refresh(wks2)$fitcn(verbose = TRUE)
foo = refresh(wks2)$fitcn(verbose = TRUE, edgeonly = TRUE)
foo = refresh(wks2)$fitcn(verbose = TRUE, trim = FALSE)
foo = refresh(wks2)$fitcn(verbose = TRUE, min.alt = FALSE)
foo = refresh(wks2)$fitcn(verbose = TRUE, weight = seq_along(wks))
wks2$set(weight = seq_along(wks))
foo = refresh(wks2)$fitcn(verbose = TRUE)
expect_error(gW()$fitcn())
# test simple/TRA
h526_simple = simple(h526)
expect_true('tra' %in% h526_simple$meta$simple$type)
})
test_that('eclusters', {
setDTthreads(1)
gg.jabba = gG(jabba = system.file('extdata/hcc1954', 'jabba.rds', package="gGnome"))
# make this go faster by subsetting to a region with one reciprocal hit
gr = parse.gr('1:100e6-120e6;6:61e6-63e6;11:70e6-72e6', seqlengths = seqlengths(gg.jabba))
gg.reduced = gg.jabba %&% gr
gg.reduced$eclusters(verbose = TRUE)
expect_equal(gg.reduced$edges[type == 'ALT'][1]$dt$ecluster, 1)
# test eclusters2
gg.reduced = gg.jabba %&% gr
# TODO: eclusters2 is failing (see error at the bottom of this page: https://app.travis-ci.com/github/mskilab/gGnome/builds/238302593)
#gg.reduced$eclusters2(verbose = TRUE)
#xpect_equal(gg.reduced$edges[type == 'ALT'][1]$dt$ecluster, 1)
expect_null(gG()$eclusters(verbose = TRUE))
# TODO: eclusters2 is failing (see error at the bottom of this page: https://app.travis-ci.com/github/mskilab/gGnome/builds/238302593)
#expect_null(gG()$eclusters2(verbose = TRUE))
gg.reduced = gg.jabba %&% gr
bla = gg.reduced$copy$eclusters(weak = FALSE, paths = TRUE, verbose = TRUE)
#expect_equal(gg.reduced$edges[type == 'ALT'][1]$dt$epath, 'p1')
gg.reduced = gg.jabba %&% gr
# TODO: eclusters2 is failing (see error at the bottom of this page: https://app.travis-ci.com/github/mskilab/gGnome/builds/238302593)
#bla = gg.reduced$copy$eclusters2(weak = FALSE, paths = TRUE, verbose = TRUE)
#expect_equal(gg.reduced$edges[type == 'ALT'][1]$dt$epath, 'p1')
})
test_that('maxflow', {
setDTthreads(1)
gg.jabba = gG(jabba = system.file('extdata/hcc1954', 'jabba.rds', package="gGnome"))
# make this go faster by subsetting to a region with one reciprocal hit
gr = parse.gr('1:89833582-121484093', seqlengths = seqlengths(gg.jabba))
gg.reduced = gg.jabba$copy %&% gr
expect_equal(max(gg.reduced$maxflow('cn', verbose = TRUE)), 4)
expect_equal(max(gg.reduced$maxflow('cn', multi = TRUE, verbose = TRUE)), 4)
expect_equal(max(gg.reduced$maxflow('cn', max = FALSE, verbose = TRUE)), 3)
})
test_that('proximity tutorial, transplant, printing', {
setDTthreads(1)
gg.jabba = gG(jabba = system.file('extdata/hcc1954', 'jabba.rds', package="gGnome"))
# test bcheck
bc = bcheck(gg.jabba)
# expect the majority of nodes to be balanced
expect_true(0.5 < (sum(bc$balanced == TRUE, na.rm = TRUE) / bc[,.N]))
gg.jabba$nodes$print()
gg.jabba$edges$print()
gg.jabba$print()
gg.jabba$json('test.json')
expect_warning(gg.jabba$json('test.json', annotation = 'no.such.annotations'))
expect_error(gg.jabba$json('test.json', cid.field = 'no.such.field'))
# test with proper cid.field (but one that has NAs for REF edges
gg.jabba$edges[type == 'ALT']$mark(jid = seq_along(gg.jabba$edges[type == 'ALT']))
gg.jabba$json('test.json', cid.field = 'jid')
gff = readRDS(gzcon(url('https://mskilab.com/gGnome/hg19/gencode.v19.annotation.gtf.gr.rds')))
## load Hnisz et al 2013 superenhancers mapped to hg19
se = readRDS(gzcon(url('https://mskilab.com/gGnome/hg19/Hnisz2013.se.rds')))
## many of these are redundant / overlapping so we will reduce them with some padding
## to reduce computation
ser = reduce(se)[c(4243, 4260, 5454, 4252, 4241, 4249)]
genes = gff %Q% (type == 'gene' & gene_name %in% c('TERT', 'BRD9'))
## useful (optional) params to tune for performance include "chunksize" and "mc.cores"
## which will chunk up and parallelize the path search, in this case 1000
## intervals at a time across 5 cores, can also monitor progress with verbose = TRUE
px = proximity(gg.jabba, ser, genes[, 'gene_name'])
px2 = proximity(gg.jabba, ser, genes[, 'gene_name'], chunksize = 2)
px3 = proximity(gg.jabba, ser, genes[, 'gene_name'], chunksize = 3)
expect_equal(width(px), width(px2))
expect_equal(width(px), width(px3))
expect_equal(px$dt$altdist, px2$dt$altdist)
expect_equal(px2$dt$altdist, px3$dt$altdist)
expect_equal(width(px), width(px2))
expect_equal(width(px), width(px3))
## peek at the first proximity, we can see the reldist, altdist, refdist
## and additional metadata features inherited from the genes object
expect_equal(px[1]$dt$altdist, 30218)
expect_equal(px[1]$dt$refdist, Inf)
## plot the first super-enhancer connecting to BRD9
px[1]$mark(col = 'purple')
## ## use $eval to count ALT junctions for each walk
## px$set(numalt = px$eval(sum(type == 'ALT')))
## ## let's look for a superenhancer connecting to TERT
## this.px = px[numalt>2 & refdist == Inf & gene_name == 'TERT']
## expect_equal(this.px[1]$dt$altdist, 52928)
## expect_equal(this.px[1]$dt$reldist, 0)
## expect_equal(length(this.px), 6)
## mark it up
## this.px[1]$mark(col = 'purple')
gg2 = gg.jabba$copy
old.gr = gg2$nodes[10]$gr
gg2$swap(10, px[1]$nodes$gr[1])
expect_identical(gr.string(gg2$nodes[parent.node.id == 10]$gr), '8:119213090-119213807+')
gg3 = gg.jabba$copy
gg3$swap(10, px[1]$grl)
expect_equal(length(gg3$nodes[parent.node.id == 10]), length(px[1]$grl[[1]]))
expect_equal(gr.string(sort(gr.stripstrand(gg3$nodes[parent.node.id == 10]$gr[, c()]))), gr.string(sort(gr.stripstrand(px[-1]$grl[[1]])[, c()])))
gg3$connect(10, 20, meta = data.table(type = 'ALT'))
expect_equal(20 %in% gg.jabba$nodes[10]$right$dt$node.id, FALSE)
expect_equal(20 %in% gg3$nodes[10]$right$dt$node.id, TRUE)
gg.jabba$toposort()
expect_identical(sort(gg.jabba$dt$topo.order[1:5]), gg.jabba$dt$topo.order[1:5])
trans = transplant(gg.jabba, donor = gg.jabba$edges[type == 'ALT']$junctions %&% '17:37639784-38137750')
expect_true(inherits(trans, 'gGraph'))
# TODO: this currently fails and I am not sure why
#sg = gg.jabba$copy$nodes[cluster == 2]$subgraph
#trans = transplant(gg.jabba, donor = sg)
#expect_true(inherits(trans, 'gGraph'))
expect_error(transplant(gG(), gg.jabba))
# test nodestats
nstat = nodestats(gg.jabba, gg.jabba$nodes$gr[, 'cn'])
})
##
gr2 = GRanges(1, IRanges(c(1,9), c(6,14)), strand=c('+','-'), seqinfo=Seqinfo("1", 25), field=c(1,2))
dt = data.table(seqnames=1, start=c(2,5,10), end=c(3,8,15))
pr=gGraph$new(prego=prego)
## FIXME: REQUIREMENTS FOR THE BELOW TESTS
## TEST FOR GGRAPH DEFAULT CONSTRUCTOR
## TEST FOR QUERYLOOKUP
test_that('Constructors', {
setDTthreads(1)
expect_is(gGraph$new(jabba = jab), "gGraph")
expect_is(gGraph$new(weaver = weaver), "gGraph")
expect_is(pr, "gGraph")
expect_is(gGraph$new(remixt = remixt), "gGraph")
})
test_that('gNode Class Constructor/length, gGraph length/active $nodes', {
setDTthreads(1)
nodes1 = c(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(101,200),"*"),
GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(301,400),"*"),
GRanges("1",IRanges(401,500),"*"))
edges = data.table(n1 = c(3,2,4,1,3), n2 = c(3,4,2,5,4), n1.side = c(1,1,0,0,1), n2.side = c(0,0,0,1,0))
gg = gGraph$new(nodes = nodes1, edges = edges)
## Testing some errors here
expect_error(gNode$new(0, gg))
expect_error(gNode$new(100, gg))
expect_error(gNode$new(-30, gg))
expect_error(gNode$new(4, gGraph$new()))
expect_error(gNode$new(c(1,2,-10), gg))
## Testing with no snode.id
gn = gNode$new(graph = gg)
expect_equal(length(gn), 0)
expect_identical(gn$graph, gg)
expect_equal(length(gn$sid), 0)
## Testing building using active fields of gg
gn = gg$nodes
gn$mark(col="purple")
expect_is(gn, "gNode")
expect_equal(length(gn), length(gg))
expect_equal(gn$gr, gg$gr %Q% (strand == "+"))
expect_equal(gn$id, (gg$gr %Q% (strand == "+"))$snode.id)
expect_equal(gn$id, gn$sid)
##gNode ego
gn=gNode$new(3, gg)
expect_equal(gg[c(3:4)]$nodes$dt[, start], gn$ego(1)$dt[, start])
expect_equal(gg[c(3, 4, 2)]$nodes$dt[, start], gn$ego(2)$dt[, start])
##loose.left, loose right
gn=gNode$new(1, gg)
expect_equal(gn$loose.left, FALSE)
expect_equal(gn$loose.right, TRUE)
expect_equal(gn$degree, 1)
##terminal, degrees
expect_equal(gr2dt(gn$terminal)[, start], 100)
expect_equal(gn$ldegree, 1)
expect_equal(gn$rdegree, 0)
##unioning gNodes
## gn2=gNode$new(2, gg)
## expect_equal(union(gn, gn2)$dt, gg$nodes[c(1:2)]$dt)
## gg=gGraph$new(nodes=nodes1, edges=edges)
## expect_error(union(gg$nodes, gn2))
# seqinfo
seqinfo(gn)
})
test_that('gNode subsetting', {
setDTthreads(1)
nodes1 = c(GRanges("1",IRanges(1,100),"*", cn=1), GRanges("1",IRanges(101,200),"*",cn=1),
GRanges("1",IRanges(201,300),"*", cn=1), GRanges("1",IRanges(301,400),"*", cn=1),
GRanges("1",IRanges(401,500),"*",cn=1))
edges = data.table(n1 = c(3,2,4,1,3), n2 = c(3,4,2,5,4), n1.side = c(1,1,0,0,1), n2.side = c(0,0,0,1,0))
gg = gGraph$new(nodes = nodes1, edges = edges)
expect_equal(dim(gg[1, ]), c(1, 0))
gn = gg$nodes
gn2= gNode$new(2, gg)
gn3= gNode$new(1, gg)
##Right and Left
expect_equal(gn2$right$dt[, start], 301)
expect_equal(gn2$left$dt[, start], 301)
expect_equal(length(gn %&% gn2), 1)
expect_equal(length(gn %&% '1:101-200'), 1)
expect_equal(length(gn %&% gg$edges[1]), 1)
expect_equal(length(gn %&% gg$edges[1]$grl), 1)
expect_equal(sum(gn %^% '1:101-200'), 1)
expect_equal(sum(gn %^% gg$edges[1]$grl), 1)
##Quick subgraph test
sub=gn$subgraph
expect_equal(length(sub), length(gg))
##Various overriden functions
node1=gn[1]
nodes2=gn[c(1:4)]
expect_equal(length(c(gn2, gn2)), 2)
expect_equal(length(setdiff(gn, gn)), 0)
expect_identical(intersect.gNode(gn3, gg$nodes)$dt, gg$nodes[1]$dt)
## Testing positive indicies
expect_equal(gn[1:5]$gr, gn$gr)
expect_equal(length(gn[1:5]), 5)
expect_identical(gn[1:5]$graph, gg)
expect_equal(gn[c(2,4)]$gr, gn$gr[c(2,4)])
expect_equal(length(gn[c(2,4)]), 2)
expect_equal(gn[c(2,4)]$id, c(2,4))
expect_equal(gn[1]$gr, gn$gr[1])
expect_equal(length(gn[1]), 1)
expect_equal(gn[1]$graph, gg)
expect_error(gn[6])
expect_error(gn[-10])
expect_error(gn[0])
## Indexing via snode.id name
expect_equal(gn["4"]$gr, gg$gr[4])
expect_equal(gn["-1"]$gr, gg$gr[6])
expect_equal(gn[c("1","-3")]$gr, gg$gr[c(1,8)])
expect_error(gn["10"])
expect_error(gn["-6"])
## Some complex indexing
expect_equal(gn["1"][-1], gn[-1])
expect_equal(gn[2:4]["-2"][-1], gn[2])
expect_equal(gn["4"][-1][-1], gn["4"])
expect_equal(gn[c(-1,-4)]$gr, gg$gr[c(6,9)])
## Indexing via queries
## expect_identical(gn[loose.left == FALSE]$dt, gn[c(1:4)]$dt) ## causing problems on travis only
# expect_equal(gn[snode.id > 3], gn[4:5]) #### this syntax is not playing well with Travis
## expect_identical(gn[start > 150 & end < 450 & loose.left == FALSE]$dt, gn[3:4]$dt) #### this syntax is not playing well with Travis
})
test_that('gEdge works',{
setDTthreads(1)
nodes1 = c(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(101,200),"*"),
GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(301,400),"*"),
GRanges("1",IRanges(401,500),"*"))
edges = data.table(n1 = c(3,2,4,1,3), n2 = c(3,4,2,5,4), n1.side = c(1,1,0,0,1), n2.side = c(0,0,0,1,0))
gg = gGraph$new(nodes = nodes1, edges = edges)
ge=gEdge$new(1, gg)
ge2=gEdge$new(2, gg)
ge3=c(ge, ge2)
##Mark
ge$mark(changed=TRUE)
expect_equal(gg$edges[1]$dt[, changed], TRUE)
##Basic active fields
expect_equal(ge$length, 1)
expect_equal(length(ge), 1)
expect_equal(ge$left, gg$nodes[3])
expect_equal(ge$right, gg$nodes[3])
##Overriden functions
expect_equal(c(ge, ge2)$dt[, sedge.id], gg$edges[c(1, 2)]$dt[, sedge.id])
expect_equal(length(setdiff(ge, ge)), 0)
expect_equal(intersect.gEdge(c(ge, ge3), ge)$dt[, sedge.id], 1)
##Miscellaneous functions
starts=gr2dt(ge$junctions$grl)[, start]
expect_equal(gr2dt(ge$junctions$grl)[, start][1], 300)
expect_equal(gr2dt(ge$junctions$grl)[, end][2], 201)
expect_equal(class(ge$subgraph)[1], "gGraph")
# edge.queries
expect_equal(length(ge3 %&% ge2), 1)
expect_equal(length(ge3 %&% ge2$junctions), 1)
expect_equal(length(ge %&% ge2), 0)
expect_equal(length(ge %&% ge2$junctions), 0)
expect_true(ge %^% '1:1-400')
})
test_that('Junction', {
setDTthreads(1)
juncs = readRDS(jab)$junctions
badjuncs = GRangesList(GRanges("1", IRanges(1,100), "+"))
## Some errors
expect_error(Junction$new(GRanges("1", IRanges(1,100), "+")))
expect_error(Junction$new(badjuncs))
## Empty Junctions
jj = Junction$new(GRangesList())
expect_equal(length(jj), 0)
## Build
jj = Junction$new(juncs)
expect_equal(length(setdiff(jj, jj)), 0)
expect_equal(length(intersect.Junction(jj, jj)),length(jj))
jgw = jj$gw()
expect_true(inherits(jgw, 'gWalk') & length(jgw) == length(jj))
expect_equal(length(jj), 500)
expect_equal(unlist(jj$grl), unlist(juncs))
## expect_equal(jj$dt, as.data.table(values(juncs)))
## c() / +
jj2 = c(jj, jj)
expect_equal(length(jj2), length(jj)*2)
expect_equal(as.matrix(as.data.table(jj2$grl)), as.matrix(as.data.table(c(jj$grl, jj$grl))))
juncs.delly = Junction$new(delly)
juncs.novobreak = Junction$new(novobreak)
juncs.svaba = Junction$new(svaba)
expect_true(length(juncs.delly)==210)
expect_true(length(juncs.novobreak)==421)
expect_true(length(juncs.svaba)==500)
juncs = readRDS(jab)$junctions
badjuncs = GRangesList(GRanges("1", IRanges(1,100), "+"))
## Some errors
expect_error(Junction$new(GRanges("1", IRanges(1,100), "+")))
expect_error(Junction$new(badjuncs))
## Empty Junctions
jj = Junction$new(GRangesList())
expect_equal(length(jj), 0)
## Build
jj = Junction$new(juncs)
expect_equal(length(setdiff(jj, jj)), 0)
expect_equal(length(intersect.Junction(jj, jj)),length(jj))
expect_equal(length(jj), 500)
expect_equal(unlist(jj$grl), unlist(juncs))
expect_equal(jj$dt, as.data.table(values(juncs)))
## c() / +
jj2 = c(jj, jj)
expect_equal(length(jj2), length(jj)*2)
expect_equal(as.matrix(as.data.table(jj2$grl)), as.matrix(as.data.table(c(jj$grl, jj$grl))))
jj2 = jj + 100
expect_true(all(all(width(jj2$grl)==101)))
## $breakpoints
bps = jj$breakpoints
bps = c(GenomicRanges::shift(bps %Q% (strand == "+"), 1), bps %Q% (strand == "-"))
expect_equal(length(findOverlaps(unlist(juncs), bps)), length(juncs)*2)
bps = jj2$breakpoints
bps = c(GenomicRanges::shift(bps %Q% (strand == "+"), 1), bps %Q% (strand == "-"))
expect_equal(length(findOverlaps(unlist(juncs), bps)), length(juncs)*2)
## $gGraph
gg = jj$graph
gg1 = gGraph$new(juncs = juncs)
expect_is(gg, "gGraph")
expect_equal(length(gg), length(gg1))
##subset
expect_equal(gr2dt(jj[1]$grl)[,group][1], 1)
# set
jj$set(myField = 'myValue')
expect_equal(jj[1]$dt$myField, 'myValue')
expect_error(jj$set(junc = 'NONO.FIELDS'))
# print
jj$print()
# footprint
jj$footprint
# shadow,span of empty junction
expect_equal(jJ()$shadow, GRanges())
expect_null(jJ()$span)
expect_null(jJ()$sign)
# junc
expect_true(is.character(jj$junc))
# flip
a = gr2dt(jj$copy$flip[1]$grl)
b = gr2dt(jj[1]$grl)
expect_true(all(a$strand == c('+', '-') & b$strand == c('-', '+')))
expect_error(c(jj, 'Not a Junction'))
jju=unique(jj, pad = 10)
expect_equal(length(jju), 494)
})
test_that('gGraph, empty constructor/length', {
setDTthreads(1)
## Test with unspecified genome - seqinfo(default values)
gg = gGraph$new()
expect_true(is(gg, 'gGraph'))
## Check the active bindings
expect_equal(length(seqinfo(gg)), 0)
## Test with specified genome - valid - just check seqinfo (set.seqinfo w/valid genome)
##gg = gGraph$new(genome = HGSL)
##expect_equal(length(gg$seqinfo), 25)
})
## TESTING TRIM
test_that('gGraph, trim', {
setDTthreads(1)
## 1) trim within single node
## 2) trim across multiple nodes
## 3) Trim is not continuous
## Build a gGraph
gr = c(GRanges("1", IRanges(1001,2000), "*"), GRanges("1", IRanges(2001,3000), "*"),
GRanges("1", IRanges(3001,4000), "*"), GRanges("1", IRanges(4001,5000), "*"))
gr = gr.fix(gr, HGSL)
es = data.table(n1 = c(1,2,3,4,4), n2 = c(2,3,4,1,3), n1.side = c(1,1,1,0,1), n2.side = c(0,0,0,1,0))
graph = gGraph$new(nodes = gr, edges = es)
## CASE 1
gr1 = GRanges("1", IRanges(1200,1500), "+")
gr1 = gr.fix(gr1, HGSL)
tmp = graph$copy$trim(gr1)
expect_identical(as.data.table(streduce(tmp$nodes$gr)), as.data.table(streduce(gr1)))
##keep as is expect_equal(granges(tmp$nodes$gr), granges(gr1))
##keep as is expect_equal(length(gg$edges), 0)
expect_equal(length(tmp), 1)
## CASE 2
gr2 = GRanges("1", IRanges(2200,4500), "+")
gr2 = gr.fix(gr2, HGSL)
edges = data.table(n1 = c(1,2), n2 = c(2,3), n1.side = c(1,1), n2.side = c(0,0))
tmp2 = graph$copy$trim(gr2)
expect_identical(as.data.table(streduce(tmp2$nodes$gr)), as.data.table(streduce(gr2)))
es = tmp2$edges$dt[order(n1,n2,n1.side,n2.side),][, c("type") := NULL]
## expect_equal(es, edges[order(n1,n2,n1.side,n2.side),])
expect_equal(length(tmp2), 3)
## Case 3
ranges(gr2) = IRanges(1800,2200)
gr2 = c(gr2, GRanges("1", IRanges(2800,4500), "+"))
edges = data.table(n1 = c(2,4,5,6), n2 = c(3,5,6,2), n1.side = c(1,1,1,0), n2.side = c(0,0,0,1))
graph$trim(c(gr1,gr2))
expect_equal(streduce(graph$nodes$gr), streduce(c(gr1,gr2)))
es = graph$edges$dt[order(n1,n2,n1.side,n2.side),][, c("type") := NULL]
## expect_equal(es, edges[order(n1,n2,n1.side,n2.side),])
expect_equal(length(graph), 6)
})
test_that('some public gGraph fields, gGraph.subset',{
setDTthreads(1)
nodes1 = c(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(101,200),"*"),
GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(301,400),"*"),
GRanges("1",IRanges(401,500),"*"))
edges = data.table(n1 = c(3,2,4,1,3), n2 = c(3,4,2,5,4), n1.side = c(1,1,0,0,1), n2.side = c(0,0,0,1,0))
##gTrack
gg = gGraph$new(nodes = nodes1, edges = edges)
expect_is(gg$gtrack(), "gTrack")
expect_is(gg$gt, "gTrack")
expect_equal(gg$gtrack()$ygap, 2)
expect_equal(gg$gtrack()$name, "gGraph")
#gwalks
expect_is(gg$walks(), "gWalk")
expect_equal(gg$walks()$dt[, wid], c(200, 300, 100))
##subgraph
gr1=gg$nodes$gr[1]
sub=gg$subgraph(gr1, 100)
expect_equal(sub$dt[c(1:2), start], c(1, 402))
expect_equal(sub$dt[2, loose.right], FALSE)
expect_equal(sub$dt[2, loose.left], TRUE)
## subgraph on a reference genome (each chr a node, no edge)
gg.jabba.ref = gG(jabba = system.file("extdata/jabba.ref.rds", package = "gGnome"))
sub.ref = gg.jabba.ref$copy$subgraph(gr1, 100)
expect_equal(length(sub.ref$nodes), 1)
expect_equal(length(sub.ref$edges), 0)
## ##addJuncs
## graph=copy(gg)
## graph$addJuncs(graph$junctions)
## starts=data.table(r=duplicated(as.data.table(unlist(graph$junctions$grl))[, start]))
## expect_equal(nrow(starts[r==TRUE,]), 2)
##clusters
gg=gGraph$new(nodes=nodes1, edges=edges)
gg$clusters()
expect_equal(gg$dt[c(1:5), cluster], c(2, 1, 1, 1, 2))
##dim
expect_equal(dim(gg), c(5, 5))
##mergeOverlaps
## expect_identical(gg$mergeOverlaps(), gg)
## nodes1 = c(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(50,200),"*"),
# GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(250,400),"*"),
## GRanges("1",IRanges(401,500),"*"))
## gg=gGraph$new(nodes=nodes1, edges=edges)
## expect_equal(length(gg$mergeOverlaps()), 7)
# gGraph.subset
gg %&% '1:1-100'
})
test_that('gWalk works', {
setDTthreads(1)
##create gWalk with null grl
nodes1 = c(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(101,200),"*"),
GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(301,400),"*"),
GRanges("1",IRanges(401,500),"*"))
edges = data.table(n1 = c(3,2,4,1,3), n2 = c(3,4,2,5,4), n1.side = c(1,1,0,0,1), n2.side = c(0,0,0,1,0))
gg = gGraph$new(nodes = nodes1, edges = edges)
grl=GRangesList(GRanges("1",IRanges(1,100),"*"), GRanges("1",IRanges(101,200),"*"),
GRanges("1",IRanges(201,300),"*"), GRanges("1",IRanges(301,400),"*"),
GRanges("1",IRanges(401,500),"*"))
col=data.table(x=1)
gw=gWalk$new(snode.id=2,sedge.id=NULL, grl=NULL, graph=gg)
expect_identical(gw$graph, gg)
expect_equal(gw$length, 1)
expect_equal(gw$lengths, c('1'=1))
expect_identical(gw$nodes$dt, gg$nodes[2]$dt)
gw=gWalk$new(snode.id=NULL,sedge.id=1, grl=NULL, graph=gg)
expect_identical(gw$graph, gg)
expect_equal(gw$length, 1)
expect_equal(gw$lengths, c('1'=2))
expect_identical(gw$edges$dt, gg$edges[1]$dt)
expect_error(gWalk$new(snode.id=NULL,sedge.id=10000000, grl=NULL, graph=gg))
expect_equal(length(gWalk$new(snode.id=NULL,sedge.id=c(), grl=NULL, graph=gg)), 0)
##empty gWalk
empt=gWalk$new()
expect_equal(length(empt), 0)
##set function
expect_error(gw$set("walk.id"=1))
gw$set(x=3)
expect_equal(gw$dt[, x], 3)
##gWalk from grl
gw2=gWalk$new(grl=grl)
expect_is(gw2, "gWalk")
expect_equal(lengths(gw2), rep(1, 5))
##subsetting
expect_equal(unlist(gw2[1:3]$dt[, snode.id]), c(1, 2, 3))
expect_equal(gw2[walk.id==3]$dt[, name], "3")
##dts
expect_equal(gw2$dts(makelists=FALSE), gw2$dts()[, snode.id:=NULL])
##disjoin
gw3=gWalk$new(snode.id=c(1:4), graph=gg)
gr=GRanges("1", IRanges(50, 250), "+")
gw3$disjoin(gr=gr)
expect_equal(unlist(gw3$dt[1, snode.id]), c(1, 2))
expect_equal(unlist(gw3$dt[3, snode.id]), c(4, 5))
gw3=gWalk$new(snode.id=c(1:4), graph=gg)
gw3$disjoin(gr=gr, collapse = FALSE)
expect_true('node.id.old' %in% names(gw3$nodes$dt))
##simplify
gw2$simplify()
# seqinfo
seqinfo(gw2)
seqlengths(gw2)
##gTrack
expect_is(gw2$gtrack(), "gTrack")
## json
expect_warning(gw2$json('test.json')) # no edges warning
expect_warning(gW()$json('test.json')) # empty gWalk warning
expect_vector(jsonlite::read_json(gw3$json('test.json')))
expect_vector(gw3$json(save = FALSE))
expect_vector(gw3$json(save = FALSE, include.graph = FALSE))
# test rep
# TODO: not testing rep because it errors
# gw_rep = gw2$rep(2)
# test print
gw2$print()
# test fix
gwchr = gw2$copy$fix(1, 'chr1')
expect_equal(seqlevels(gwchr), 'chr1')
##create gWalk with null sedge.id
## gw1=gWalk$new(snode.id=1, sedge.id=NULL, grl=NULL, graph=gg, meta=col)
## expect_equal(unlist(gw1$dt[, snode.id]), 1)
##create gWalk with null snode.id
## col=data.table(x=1:3)
## gw4=gWalk$new(snode.id=NULL, sedge.id=c(1:3), grl=NULL, graph=gg, meta=col)
## expect_identical(gw4$dt[,walk.id], c(1:3))
##subsetting
## gw2=gWalk$new(snode.id=c(1:3),sedge.id=NULL, grl=NULL, graph=gg, meta=col)
## expect_identical(gw[1]$dt, gw$dt)
})
test_that('querying functions work', {
setDTthreads(1)
##gNode querying %&%
nodes = c(GRanges("1", IRanges(1001,2000), "*"), GRanges("1", IRanges(2001,3000), "*"),
GRanges("1", IRanges(3001,4000), "*"), GRanges("1", IRanges(4001,5000), "*"),
GRanges("1", IRanges(5001,6000), "*"), GRanges("1", IRanges(6001,7000), "*"),
GRanges("1", IRanges(7001,8000), "*"), GRanges("1", IRanges(8001,9000), "*"),
GRanges("1", IRanges(9001,10000), "*"))
edges = data.table(n1 = c(1,2,3,5,6,7,8,1,4,6,3),
n2 = c(2,3,4,6,7,8,9,4,8,6,2),
n1.side = c(1,1,1,1,1,1,1,1,1,0,1),
n2.side = c(0,0,0,0,0,0,0,0,0,1,0))
graph = gGraph$new(nodes = nodes, edges = edges)
gr=GRanges("1", IRanges(3500, 8500))
grl=GRangesList(gr)
gn=graph$nodes
gr1=gn %&% gr
gr1=gr1$gr
expect_equal(graph$nodes$gr[3:8], gr1)
##gEdge querying %&%
##1. gEdge with gEdge
ge1=graph$edges[4:7]
ge2=graph$edges[5:8]
ge3=ge1 %&% ge2
expect_equal(ge3, graph$edges[5:7])
##2. gEdge with Junction
ge4=ge1 %&% ge2$junctions
expect_equal(ge4, graph$edges[5:7])
##gWalk querying %&%
##junction querying %&%
##gedge %^%
##1. gEdge with gEdge
expect_equal(ge1 %^% ge2, c(FALSE, TRUE, TRUE, TRUE))
expect_equal(ge1 %^% grl, c(FALSE, FALSE, FALSE, FALSE))
##2. gEdge with junction
expect_equal(ge1 %^% graph$junctions, c(TRUE, TRUE, TRUE, TRUE))
expect_equal(ge1 %^% ge2, ge1 %^% ge2$junctions)
##3. gEdge with gNode
expect_equal(ge1 %^% gn[7:8], c(FALSE, TRUE, TRUE, TRUE))
expect_equal(ge1[1] %^% gn[5], TRUE)
##gNode %^%
##1. gNode with gNode
expect_equal(gn[1:4] %^% gn [4:9], c(FALSE, FALSE, FALSE, TRUE))
##2. gNode with gEdge
expect_equal(gn[4:6] %^% ge1, c(FALSE, TRUE, TRUE))
##3. gNode with GRangesList
expect_equal(gn %^% gr, c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE))
##junction %^%
expect_equal(ge1$junctions %^% ge2$junctions, ge1 %^% ge2)
##gWalk %^%
gw=gWalk$new(grl=grl)
##gWalk with junction
expect_equal(gw %^% graph$junctions[7], FALSE)
expect_equal(gw %^% graph$junctions[4], TRUE)
##gWalk with gEdge
expect_equal(gw %^% ge1, TRUE)
expect_equal(gw %^% ge2[3], FALSE)
##gWalk with gNode
expect_equal(gw %^% gn[3], TRUE)
expect_equal(gw %^% gn[1], FALSE)
})
test_that('gGraph, simplify, fix, gdist', {
setDTthreads(1)
nodes = c(GRanges("1", IRanges(1001,2000), "*"), GRanges("1", IRanges(2001,3000), "*"),
GRanges("1", IRanges(3001,4000), "*"), GRanges("1", IRanges(4001,5000), "*"),
GRanges("1", IRanges(5001,6000), "*"), GRanges("1", IRanges(6001,7000), "*"),
GRanges("1", IRanges(7001,8000), "*"), GRanges("1", IRanges(8001,9000), "*"),
GRanges("1", IRanges(9001,10000), "*"))
edges = data.table(n1 = c(1,2,3,5,6,7,8,1,4,6,3),
n2 = c(2,3,4,6,7,8,9,4,8,6,2),
n1.side = c(1,1,1,1,1,1,1,1,1,0,1),
n2.side = c(0,0,0,0,0,0,0,0,0,1,0))
graph = gGraph$new(nodes = nodes, edges = edges)
g=copy(graph)
graphSimple = graph$simplify()
## Check to make sure the simplifed version correctly merged everything
nodes = c(GRanges("1", IRanges(1001,2000), "*"), GRanges("1", IRanges(2001,4000), "*"),
GRanges("1", IRanges(4001,5000), "*"),
GRanges("1", IRanges(5001,6000), "*"), GRanges("1", IRanges(6001,7000), "*"),
GRanges("1", IRanges(7001,8000), "*"), GRanges("1", IRanges(8001,10000), "*"))
nodes = gr.fix(nodes, hg_seqlengths())
edges = data.table(n1 = c(1,2,2,3,1,4,5,6,5),
n2 = c(2,3,2,7,3,5,6,7,5),
n1.side = c(1,1,1,1,1,1,1,1,0),
n2.side = c(0,0,0,0,0,0,0,0,1))
expect_equal(length(graphSimple), 7)
expect_equal(length(graphSimple$edges), 9)
dt1=gr2dt(nodes)
dt2=gr2dt(graphSimple$nodes$gr)
expect_equal(dt1[, start], dt2[, start])
expect_equal(dt1[, end], dt2[, end])
g$disjoin()
g1 = graph$copy
g1$nodes$mark(cn = 1)
g1$edges$mark(cn = 1)
g2 = graph$copy
g2$nodes$mark(cn = 2)
g2$edges$mark(cn = 2)
expect_equal(gdist(g1,g1), 0)
expect_equal(gdist(g1,g2), 1)
nodes = c(GRanges("1", IRanges(1001,2500), "*"), GRanges("1", IRanges(2001,3000), "*"),
GRanges("1", IRanges(3001,4000), "*"), GRanges("1", IRanges(4001,5000), "*"),
GRanges("1", IRanges(5001,6000), "*"), GRanges("1", IRanges(6001,7000), "*"),
GRanges("1", IRanges(7001,8000), "*"), GRanges("1", IRanges(8001,9000), "*"),
GRanges("1", IRanges(1001,3000), "*"))
edges = data.table(n1 = c(1,2,3,5,6,7,8,1,4,6,3),
n2 = c(2,3,4,6,7,8,9,4,8,6,2),
n1.side = c(1,1,1,1,1,1,1,1,1,0,1),
n2.side = c(0,0,0,0,0,0,0,0,0,1,0))
graph = gGraph$new(nodes = nodes, edges = edges)
g=graph$copy
g$nodes$mark(disjoinBy = c(rep(1,5), rep(2,4)))
g$disjoin(by = 'disjoinBy')
expect_equal(length(g$nodes), 12)
expect_error(g$disjoin(by = g)) # by must be a character
gchr = g$copy$fix(1, 'chr1')
expect_equal(seqlevels(gchr), 'chr1')
})
test_that('gGnome tutorial', {
setDTthreads(1)
pdf('test.pdf')
## SvAbA
svaba = jJ(system.file('extdata', "HCC1143.svaba.somatic.sv.vcf", package = "gGnome"))
expect_equal(length(svaba), 500)
## DELLY
delly = jJ(system.file('extdata', "delly.final.vcf.gz", package = "gGnome"))
expect_equal(length(delly), 210)
## novobreak
novobreak = jJ(system.file('extdata', "novoBreak.pass.flt.vcf", package = "gGnome"))
expect_equal(length(novobreak), 421)
## BEDPE
bedpe = jJ(system.file('extdata', "junctions.bedpe", package = "gGnome"))
expect_equal(length(bedpe), 83)
## any names work in the arguments to merge, these will be reflected in metadata as a $seen.by column
## (using padding of 1kb and c() to remove existing metadata)
res = merge(svaba = svaba[, c()], delly = delly[, c()],
novo = novobreak[, c()], anynameworks = bedpe[,c()], pad = 1e3)
expect_equal(res$dt$seen.by.svaba[1] & !res$dt$seen.by.delly[1] & !res$dt$seen.by.novo[1] & !res$dt$seen.by.anynameworks[1], TRUE)
# merge with metadata
res = merge(svaba, delly, pad = 1e3)
expect_true('MATEID.ra1' %in% names(res$dt) & 'MATEID.ra2' %in% names(res$dt))
# test cartesian merging.
res = merge(svaba, delly, cartesian = TRUE, pad = 1e3)
# we expect the field query.id to map back to the junction in svaba
expect_equal(length(res[1] %&% svaba[res[1]$dt[, query.id]]), 1)
res.all = merge(svaba, delly, cartesian = TRUE, pad = 1e3, all = TRUE)
expect_true(length(res.all) > length(res))
## can use both row and column subsetting on Junction metadata
expect_equal(as.character(head(novobreak[1:2, 1:10])$dt$CHROM[1]), '10')
expect_equal(length(unique(bedpe)), 83)
## can use data.table style expressions on metadata to subset Junctions
## here, filter novobreak translocations with quality greater than 50
expect_equal(novobreak[ALT == "<TRA>" & QUAL>50, 1:10][1:2, 1:5]$dt$POS[1], 29529472)
## subsetting SvAbA junctions with >5 bases of homologous sequence
expect_equal(svaba[nchar(INSERTION)>10, ][1:2, 1:5]$dt$ALT[[1]], "C[3:85232671[")
## subsetting SVabA junctions with same sign and nearby breakpoints (i.e. small $span)
expect_equal(svaba[svaba$sign>0 & svaba$span<1e5][1:2, 1:5]$dt$REF[1], 'T')
## subsetting junctions with infinite span (ie different chromosome) and homology length >5
expect_equal(as.character(delly[is.infinite(delly$span) & HOMLEN>5, ][1:2,1:5]$dt$CHROM[1]), '6')
## subset svaba by those intersect with DELLY using gUtils subset %&% operator
expect_equal(length(svaba %&% delly), 7)
## increase the overlap substanntially by padding delly calls with 100bp (using + operator)
expect_equal(length(svaba %&% (delly+100)), 103)
## basic set operations also work
expect_equal(length(S4Vectors::setdiff(svaba, delly+100)), 397)
expect_equal(length(S4Vectors::union(svaba, delly+100)), 710)
## gGraph from svaba input
gg = gG(juncs = svaba)
## we use gTrack to plot the gTrack associated with this gGraph
## the second argument to gTrack plot is a string or GRanges representing the
## window to plot, the links argument enables drawing of junctions from GRangesList
## generate breaks using gUtils function to tile genome at evenly spaced 1MB intervals
breaks = gr.tile(seqinfo(svaba), 1e6)
expect_equal(length(breaks), 3173)
## gGraph from svaba input
gg2 = gG(breaks = breaks, juncs = svaba)
## set gGraph metadata
gg2$set(name = 'with breaks')
expect_equal(gg2$meta$name, 'with breaks')
## compare graphs towards the beginning of chromosome 1
## (gTracks can be concatenated to plot multiple tracks)
nodes = gr.tile(seqlengths(svaba)["1"], 1e7)
## generate 20 random edges (n1, n2, n1.side, n2.side)
edges = data.table(
n1 = sample(length(nodes), 20, replace = TRUE),
n2 = sample(length(nodes), 20, replace = TRUE))
edges[, n1.side := ifelse(runif(.N)>0.5, 'right', 'left')]
edges[, n2.side := ifelse(runif(.N)>0.5, 'right', 'left')]
gg3 = gG(nodes = nodes, edges = edges)
pad = runif(length(nodes))*width(nodes)
gg3 = gG(nodes = nodes + pad , edges = edges)
## PREGO is the original cancer SV graph caller from Oesper et al 2012
gg.prego = gG(prego = system.file('extdata/hcc1954', 'prego', package='gGnome'))
## Weaver is from Li et al 2016
gg.weaver = gG(weaver = system.file('extdata/hcc1954', 'weaver', package='gGnome'))