forked from sbotond/phylosim
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhyloSim.R
6741 lines (6241 loc) · 165 KB
/
PhyloSim.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
##
## Copyright 2009 Botond Sipos
## See the package description for licensing information.
##
##########################################################################/**
#
# @RdocClass PhyloSim
# \alias{phylosim}
#
# @title "The PhyloSim class"
#
# \description{
#
# PhyloSim is an extensible object-oriented framework for the Monte Carlo simulation
# of sequence evolution written in 100 percent \code{R}.
# It is built on the top of the \code{\link{R.oo}} and \code{\link{ape}} packages and uses
# Gillespie's direct method to simulate substitutions, insertions and deletions.
#
# Key features offered by the framework:
# \itemize{
# \item Simulation of the evolution of a set of discrete characters with arbitrary states evolving
# by a continuous-time Markov process with an arbitrary rate matrix.
# \item Explicit implementations of the most popular substitution models (for nucleotides, amino acids and codons).
# \item Simulation under the popular models of among-sites rate variation, like the gamma (+G) and invariants plus gamma (+I+G) models.
# \item The possibility to simulate with arbitrarily complex patterns of among-sites rate variation by setting the site specific rates according to any \code{R} expression.
# \item Simulation with one or more separate insertion and/or deletion processes acting on the sequences, which sample the insertion/deletion length from an arbitrary discrete distribution or an \code{R} expression (so all the probability distributions implemented in \code{R} are readily available for this purpose).
# \item Simulation of the effects of variable functional constraints over the sites by site-process-specific insertion and deletion tolerance parameters, which determine the rejection probability of a proposed insertion/deletion.
# \item The possibility of having a different set of processes and site-process-specific parameters for every site, which allow for an arbitrary number of partitions in the simulated data.
# \item Simulation of heterotachy and other cases of non-homogeneous evolution by allowing the user to set "node hook" functions altering the site properties at internal nodes of the phylogeny.
# \item The possibility to export the counts of various events ("branch statistics") as phylo objects (see \code{\link{exportStatTree.PhyloSim}}).
# }
#
# General notes:
# \itemize{
# \item The \code{Sequence} objects have no "immortal links". The simulation
# is aborted if the sequence length shrinks to zero. It is up to the user
# to choose sensible indel rates and sequence lengths to prevent that.
# \item The sites near the beginning and end of the sequences have less sites proposing
# insertion and deletion events around the so the insertion and deletion processes
# have an "edge effect". The user can simulate
# realistic flanking sequences to alleviate the edge effect in the simulation settings where
# it may be an issue.
# }
#
# Notes on performance:
# \itemize{
# \item The pure \code{R} implementation offers felxibility, but also comes
# with a slower simulation speed. If the \code{PSIM_FAST} object is present in the environment, a "fast & careless"
# mode is enabled. In this mode most of the error checking is skipped, increasing the speed.
# It is recomended that simulations are only run in fast mode if you are sure that the simulation
# settings are free from errors. It is probably a good practice to set up the simulations in normal mode
# with short sequences and enable fast mode when running the actual simulation with long sequences.
# \item Please note, that no "branch statistics" are saved in fast mode.
# \item Logging also has a negative impact on performance, so it's not a good idea to run
# large simulations with the logging enabled.
# \item The time needed to run a simulation depends not only on the number of the sites,
# but also on the length of the tree.
# \item Constructing \code{Sequence} objects with large number of sites is expensive. Avoid doing
# that inside a cycle.
# \item In the case of \code{Sequence} objects with a large number of sites (more than 10 000) the
# amount of available memory can be limiting as well.
# }
#
# The examples below demonstrate only some more common simulation settings,
# the framework offers much more flexibility. See the package
# vignette (\code{vignette("PhyloSim",package="phylosim")}) and the
# examples directory (\url{http://github.com/bsipos/phylosim/tree/master/examples/})
# for additional examples.
#
# @classhierarchy
# }
#
#
# \references{
# Gillespie, DT (1977) Exact stochastic simulation of coupled chemical reactions -
# J. Phys. Chem. 81 (25):2340-2361 \url{http://dx.doi.org/10.1021/j100540a008}
# }
#
# @synopsis
#
# \arguments{
# \item{phylo}{A rooted phylo object, constructed by the APE package.}
# \item{root.seq}{A valid Sequence object with Process objects attached. Used as the starting sequence during simulation.}
# \item{name}{The name of the object (a character vector of length one).}
# \item{log.file}{Name of the file used for logging.}
# \item{log.level}{An integer specifying the verbosity of logging (see \code{\link{setLogLevel.PhyloSim}}).}
# \item{...}{Not used.}
# }
#
# \section{Fields and Methods}{
# @allmethods
# }
#
# \examples{
# set.seed(1)
# ## The following examples demonstrate
# ## the typical use of the framework.
# ## See the package vignette and
# ## \url{http://github.com/bsipos/phylosim/tree/master/examples/}
#
# ## The ll() method gives information about the methods defined
# ## in the immediate class of an object.
# ## Useful when exploring the framework.
#
# s<-Sequence()
# ll(s)
# ll(PhyloSim())
# ll(GTR())
#
# ## Example 1 - A short simulation:
# ## simulate nucleotide seqeunces and display
# ## the resulting alignment matrix.
#
# Simulate(
# PhyloSim(phy=rcoal(3),
# root=NucleotideSequence(string="ATGC", proc=list(list(JC69())) ) )
# )$alignment
#
# # Construct a phylo object for the following
# # simulations, scale total tree length to 1:
#
# tmp<-PhyloSim(phylo=rcoal(3))
# scaleTree(tmp,1/tmp$treeLength)
# tmp$treeLength
# t<-tmp$phylo
#
# ## Example 3 - simulating rate variation,
# ## insertions and deletions.
# ## See the examples/example_3_clean.R file
# ## in the phylosim GitHub repository.
#
# # construct a GTR process object
# gtr<-GTR(
# name="MyGTR",
# rate.params=list(
# "a"=1, "b"=2, "c"=3,
# "d"=1, "e"=2, "f"=3
# ),
# base.freqs=c(2,2,1,1)/6
# )
# # get object summary
# summary(gtr)
# # display a bubble plot
# plot(gtr)
#
# # construct root sequence object
# s<-NucleotideSequence(length=20)
# # attach process via virtual field
# s$processes<-list(list(gtr))
# # sample states from the equilibrium
# # distribution of the attached processes
# sampleStates(s)
# # create among-site rate variation by sampling
# # the "rate.multiplier" site-process-specific parameter
# # from a discrete gamma distribution (GTR+G).
# plusGamma(s,gtr,shape=0.1)
# # make the range 11:12 invariable
# setRateMultipliers(s,gtr,0,11:12)
# # get the rate multipliers for s and gtr
# getRateMultipliers(s,gtr)
#
# construct a deletion process object
# # proposing lengths in the range 1:3
# d<-DiscreteDeletor(
# rate=0.1,
# name="MyDel",
# sizes=c(1:3),
# probs=c(3/6,2/6,1/6)
# )
# # get object
# summary(d)
# # plot deletion length distribution
# plot(d)
# # attach deletion process d to sequence s
# attachProcess(s,d)
# # create a region rejecting all deletions
# setDeletionTolerance(s,d,0,11:12)
#
# # construct an insertion process object
# # proposing lengths in the range 1:3
# i<-DiscreteInsertor(
# rate=0.1,
# name="MyDel",
# sizes=c(1:2),
# probs=c(1/2,1/2),
# template.seq=NucleotideSequence(length=1,processes=list(list(JC69())))
# )
# # states will be sampled from the JC69 equilibrium distribution
# # get object
# summary(i)
# # plot insertion length distribution
# plot(i)
# # attach insertion process i to sequence s
# attachProcess(s,i)
# # create a region rejecting all insertions
# setInsertionTolerance(s,i,0,11:12)
#
# # plot total site rates
# plot(s)
# # construct simulation object
# sim<-PhyloSim(root.seq=s, phylo=t)
# # get object summary
# summary(sim)
# # plot tree
# plot(sim)
# # run simulation
# Simulate(sim)
# # get the list of recorded per-branch event counts
# getBranchEvents(sim)
# # export the number of substitutions as a phylo object
# subst<-exportStatTree(sim,"substitution")
# # plot the exported phylo object
# plot(subst)
# # plot tree and alignment
# plot(sim)
# # save and display alingment
# file<-paste("PhyloSim_dummy_fasta_",Sys.getpid(),".fas",sep="");
# saveAlignment(sim,file=file);
# # print out the Fasta file
# cat(paste(scan(file=file,what=character(),sep="\n"),collapse="\n"));cat("\n");
# # delete Fasta file
# unlink(file);
#
# # See \url{http://github.com/bsipos/phylosim/tree/master/examples/examples_class.R}
# # for the full list of PhyloSim constructor examples.
#
# ## See the package vignette and
# ## the GitHub repository for even more examples.
# }
#
# @author
#
# \seealso{
# \code{\link{PSRoot} \link{Alphabet} \link{AminoAcidAlphabet}
# \link{AminoAcidSequence} \link{AminoAcidSubst}
# \link{AnyAlphabet} \link{BinaryAlphabet} \link{BinarySequence}
# \link{BinarySubst} \link{BrownianInsertor} \link{CodonAlphabet}
# \link{CodonSequence} \link{CodonUNREST} \link{ContinuousDeletor}
# \link{ContinuousInsertor} \link{cpREV} \link{DiscreteDeletor}
# \link{DiscreteInsertor} \link{Event} \link{F81} \link{F84}
# \link{FastFieldDeletor} \link{GeneralDeletor}
# \link{GeneralInDel} \link{GeneralInsertor} \link{GeneralSubstitution}
# \link{GTR} \link{GY94} \link{HKY} \link{JC69} \link{JTT} \link{JTT.dcmut}
# \link{K80} \link{K81} \link{LG} \link{mtArt} \link{mtMam} \link{mtREV24}
# \link{MtZoa} \link{NucleotideAlphabet} \link{NucleotideSequence} \link{PAM}
# \link{PAM.dcmut} \link{PhyloSim} \link{Process} \link{QMatrix} \link{Sequence}
# \link{Site} \link{T92} \link{TN93} \link{UNREST} \link{WAG}}
# }
#
#*/###########################################################################
setConstructorS3(
"PhyloSim",
function(
phylo=NA,
root.seq=NA,
name=NA,
log.file=NA,
log.level=-1, # no loggin is performed by default
...
) {
this<-PSRoot();
this<-extend(this,
"PhyloSim",
.name="Anonymous",
.phylo=NA,
.root.sequence=NA,
.sequences=list(), # references to the sequence objects
.node.hooks=list(), # references to the node hook functions.
.branch.stats=list(), # branch statistics.
.alignment=NA, # the resulting alignment in fasat format.
.log.file=NA, # the name of the log file.
.log.connection=NA, # connection for the log file.
.log.level=NA # log level
);
if(!all(is.na(phylo))){
this$phylo<-phylo;
}
if(!all(is.na(root.seq))){
this$rootSeq<-root.seq;
}
if(!missing(name)){
this$name<-name;
}
if(!missing(log.file)){
this$logFile<-log.file;
} else {
# Setting default log file:
tmp<-this$id;
tmp<-gsub(":","_",tmp);
this$logFile<-paste(tmp,".log",sep="");
}
# Setting log level:
this$logLevel<-log.level;
return(this);
},
enforceRCC=TRUE
);
##
## Method: checkConsistency
##
###########################################################################/**
#
# @RdocMethod checkConsistency
#
# @title "Check object consistency"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{this}{An object.}
# \item{...}{Not used.}
# }
#
#
# \value{
# Returns an invisible TRUE if no inconsistencies found in the object, throws
# an error otherwise.
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#
#*/###########################################################################
setMethodS3(
"checkConsistency",
class="PhyloSim",
function(
this,
...
){
may.fail<-function(this) {
# Checking the name:
this$name<-this$name;
# Checking the phylo object:
if (!any(is.na(this$.phylo)) & !is.phylo(this$.phylo) ){
throw("The phylo object is invalid!\n");
}
# Checking the log level:
if(!is.numeric(this$.log.level) | (length(this$.log.level) != 1) ){
throw("The log level must be numeric vector of length 1!\n");
}
# Checking lof file:
if(!is.character(this$.log.file) | (length(this$.log.level) != 1) ){
throw("The log file must be charcter vector of length 1!\n");
}
# Checking the sequences:
for (seq in this$.sequences){
if(is.Sequence(seq)){
checkConsistency(seq);
}
}
# Checking node hooks:
for (hook in this$.node.hooks){
if(!is.null(hook) & !is.function(hook)){
throw("Invalid node hook found!\n");
}
}
# Checking the alignment:
if(!any(is.na(this$.alignment))){
.checkAlignmentConsistency(this, this$.alignment);
}
}
tryCatch(may.fail(this));
return(invisible(TRUE));
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: is.phylo.default
##
###########################################################################/**
#
# @RdocDefault is.phylo
#
# @title "Check if an object is an instance of the phylo class"
#
# \description{
# @get "title".
# Phylo objects are created by the \pkg{APE} package. This method just return the value of \code{inherits(this,"phylo")}.
# }
#
# @synopsis
#
# \arguments{
# \item{this}{An object.}
# \item{...}{Not used.}
# }
#
# \value{
# TRUE or FALSE.
# }
#
# \examples{
# # load APE
# library(ape);
# # create some objects
# o1<-Object();
# o2<-rcoal(3);
# # check if they are phylo objects
# is.phylo(o1);
# is.phylo(o2);
#
# }
#
# @author
#
# \seealso{
# The \pkg{ape} package.
# }
#
#*/###########################################################################
setMethodS3(
"is.phylo",
class="default",
function(
this,
...
){
inherits(this,"phylo");
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: setPhylo
##
###########################################################################/**
#
# @RdocMethod setPhylo
#
# @title "Set the phylo object for a PhyloSim object"
#
# \description{
# @get "title".
#
# The internal structure of the provided phylo object is reordered in a cladeweise fashion.
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{value}{A phylo object created by the \pkg{ape} package.}
# \item{...}{Not used.}
# }
#
# \value{
# A phylo object or FALSE.
# }
#
# \examples{
# #create a PhyloSim object
# sim<-PhyloSim();
# # creat a phylo object
# tree<-rcoal(3);
# # get/set phylo object
# setPhylo(sim,tree);
# getPhylo(sim,tree);
# # get/set phylo object via virtual field
# sim$tree<-rcoal(5);
# sim$tree;
# }
#
# @author
#
# \seealso{
# The PhyloSim class, the \pkg{ape} package.
# }
#
#*/###########################################################################
setMethodS3(
"setPhylo",
class="PhyloSim",
function(
this,
value,
...
){
if(missing(value)){
throw("No object provided!\n");
}
else if(!is.phylo(value)){
throw("The new value must be a \"phylo\" object!\n");
}
else if(!is.rooted(value)){
throw("The new value must be a rooted \"phylo\" object!\n");
}
else {
.checkTipLabels(value);
this$.phylo<-value;
this$.phylo<-reorder(this$.phylo, order="cladewise");
for (i in this$nodes){
this$.sequences[[i]]<-NA;
}
return(this$.phylo);
}
return(FALSE);
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
);
##
## Method: .checkTipLabels
##
setMethodS3(
".checkTipLabels",
class="phylo",
function(
this,
...
){
for(label in this$tip.label){
if(length(grep("^Node \\d+$",label,perl=TRUE,value=FALSE)) > 0){
throw("Sorry, but the node labels matching \"Node \\d+\" are reserved for internal nodes! Blaming label: ",label,".\n");
}
else if(length(grep("^Root node \\d+$",label,perl=TRUE,value=FALSE)) > 0){
throw("Sorry, but the node labels matching \"Root node \\d+\" are reserved for the root node! Blaming label: ",label,".\n");
}
}
},
private=TRUE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: getPhylo
##
###########################################################################/**
#
# @RdocMethod getPhylo
#
# @title "Get the phylo object aggregated in a PhyloSim object"
#
# \description{
# @get "title".
#
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{...}{Not used.}
# }
#
# \value{
# A phylo object or NA.
# }
#
# \examples{
# #create a PhyloSim object
# sim<-PhyloSim();
# # creat a phylo object
# tree<-rcoal(3);
# # get/set phylo object
# setPhylo(sim,tree);
# getPhylo(sim,tree);
# # get/set phylo object via virtual field
# sim$tree<-rcoal(5);
# sim$tree;
# }
#
# @author
#
# \seealso{
# The PhyloSim class, the \pkg{ape} package.
# }
#
#*/###########################################################################
setMethodS3(
"getPhylo",
class="PhyloSim",
function(
this,
...
){
this$.phylo;
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: setRootSeq
##
###########################################################################/**
#
# @RdocMethod setRootSeq
#
# @title "Set the root sequence for a PhyloSim object"
#
# \description{
# @get "title".
#
# The root sequence will be used as a starting point for the simulation. The phylo object must be set before
# trying to set the root sequence object.
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{value}{A valid Sequence object.}
# \item{...}{Not used.}
# }
#
# \value{
# The root Sequence object if succesfull, FALSE otherwise.
# }
#
# \examples{
# # create some objects
# sim<-PhyloSim(phylo=rcoal(3));
# seq<-NucleotideSequence(string="ATGCC");
# # set/get root sequence
# setRootSeq(sim, seq);
# getRootSeq(sim, seq);
# # set/get root sequence via virtual field
# sim$rootSeq<-BinarySequence(string="111000111000");
# sim$rootSeq;
#
# }
#
# @author
#
# \seealso{
# @seeclass Sequence Process
# }
#
#*/###########################################################################
setMethodS3(
"setRootSeq",
class="PhyloSim",
function(
this,
value,
...
){
if(missing(value)){
throw("No object provided!\n");
}
else if(!is.Sequence(value)){
throw("The new value must be a sequence object!\n");
}
else {
this$.root.sequence<-clone(value);
this$.root.sequence$name<-paste("Root node",this$rootNode);
# Call garbage collection:
gc();
gc();
return(this$.root.sequence);
}
return(FALSE);
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: getRootSeq
##
###########################################################################/**
#
# @RdocMethod getRootSeq
#
# @title "Get the root sequence aggregated by a PhyloSim object"
#
# \description{
# @get "title".
#
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{...}{Not used.}
# }
#
# \value{
# The root Sequence object or NA.
# }
#
# \examples{
# # create some objects
# sim<-PhyloSim(phylo=rcoal(3));
# seq<-NucleotideSequence(string="ATGCC");
# # set/get root sequence
# setRootSeq(sim, seq);
# getRootSeq(sim, seq);
# # set/get root sequence via virtual field
# sim$rootSeq<-BinarySequence(string="111000111000");
# sim$rootSeq;
#
# }
#
# @author
#
# \seealso{
# @seeclass Sequence Process
# }
#
#*/###########################################################################
setMethodS3(
"getRootSeq",
class="PhyloSim",
function(
this,
...
){
this$.root.sequence;
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: as.character.PhyloSim
##
###########################################################################/**
#
# @RdocMethod as.character
#
# @title "Return the character representation of a PhyloSim object"
#
# \description{
# @get "title".
#
# The character representation is the identifier of the PhyloSim object as returned by the \code{getId} method.
# }
#
# @synopsis
#
# \arguments{
# \item{x}{A PhyloSim object.}
# \item{...}{Not used.}
# }
#
# \value{
# A character vector of length one.
# }
#
# \examples{
# # create a PhyloSim object
# o<-PhyloSim(name="MySim");
# # get character representation
# as.character(o)
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#
#*/###########################################################################
setMethodS3(
"as.character",
class="PhyloSim",
function(
x,
...
){
return(getId(x));
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
)
##
## Method: getName
##
###########################################################################/**
#
# @RdocMethod getName
#
# @title "Get the name of a PhyloSim object"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{...}{Not used.}
# }
#
# \value{
# A character vector of length one.
# }
#
# \examples{
# # create a PhyloSim object
# o<-PhyloSim();
# # set/get name
# setName(o,"MySim");
# getName(o,"MySim");
# # set/get name via virtual field
# o$name<-"George";
# o$name
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#
#*/###########################################################################
setMethodS3(
"getName",
class="PhyloSim",
function(
this,
...
){
this$.name;
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
);
##
## Method: setName
##
###########################################################################/**
#
# @RdocMethod setName
#
# @title "Set the name of a PhyloSim object"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{new.name}{A character vector of length one.}
# \item{...}{Not used.}
# }
#
# \value{
# The new name.
# }
#
# \examples{
# # create a PhyloSim object
# o<-PhyloSim();
# # set/get name
# setName(o,"MySim");
# getName(o,"MySim");
# # set/get name via virtual field
# o$name<-"George";
# o$name
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#
#*/###########################################################################
setMethodS3(
"setName",
class="PhyloSim",
function(
this,
new.name,
...
){
this$.name<-as.character(new.name);
},
private=FALSE,
protected=FALSE,
overwrite=FALSE,
conflict="warning",
validators=getOption("R.methodsS3:validators:setMethodS3")
);
##
## Method: getId
##
###########################################################################/**
#
# @RdocMethod getId
#
# @title "Get the unique identifier of a PhyloSim object"
#
# \description{
# @get "title".
# The unique identifier is the concatenation of the class, the object name as returned by getName() and the object hash
# as returned by hashCode().
# }
#
# @synopsis
#
# \arguments{
# \item{this}{A PhyloSim object.}
# \item{...}{Not used.}
# }
#
# \value{
# A character vector of length one.
# }
#
# \examples{
# # create a PhyloSim object
# o<-PhyloSim(name="MySim");
# # get id
# getId(o);
# # get id via virtual field
# o$id;
# }
#
# @author
#
# \seealso{
# @seeclass
# }