[adegenet-commits] r1016 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 9 16:07:15 CEST 2012


Author: jombart
Date: 2012-07-09 16:07:15 +0200 (Mon, 09 Jul 2012)
New Revision: 1016

Modified:
   pkg/DESCRIPTION
   pkg/R/haploGen.R
   pkg/man/haploGen.Rd
Log:
Added a as.igraph procedure for haploGen objects.
Dependency with igraph added to the package.


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-07-09 09:49:52 UTC (rev 1015)
+++ pkg/DESCRIPTION	2012-07-09 14:07:15 UTC (rev 1016)
@@ -7,7 +7,7 @@
   and contributed datasets from: Katayoun Moazami-Goudarzi, Denis Laloe,
   Dominique Pontier, Daniel Maillard, Francois Balloux
 Maintainer: Thibaut Jombart <t.jombart at imperial.ac.uk>
-Suggests: genetics, spdep, tripack, ape, pegas, seqinr, adehabitat, multicore, akima, maps, splancs
+Suggests: genetics, spdep, tripack, ape, pegas, seqinr, adehabitat, multicore, akima, maps, splancs, igraph
 Depends: R (>= 2.10), methods, MASS, ade4
 Description: Classes and functions for genetic data analysis within the multivariate framework.
 Collate: classes.R basicMethods.R handling.R auxil.R setAs.R SNPbin.R glHandle.R glFunctions.R glSim.R find.clust.R hybridize.R scale.R fstat.R import.R seqTrack.R chooseCN.R genind2genpop.R loadingplot.R sequences.R gstat.randtest.R makefreq.R colorplot.R monmonier.R spca.R coords.monmonier.R haploGen.R old2new.R spca.rtests.R dapc.R haploPop.R PCtest.R dist.genpop.R Hs.R propShared.R export.R HWE.R propTyped.R inbreeding.R glPlot.R zzz.R

Modified: pkg/R/haploGen.R
===================================================================
--- pkg/R/haploGen.R	2012-07-09 09:49:52 UTC (rev 1015)
+++ pkg/R/haploGen.R	2012-07-09 14:07:15 UTC (rev 1016)
@@ -11,7 +11,7 @@
 haploGen <- function(seq.length=10000, mu=0.0001, t.max=20,
                      gen.time=function(){round(rnorm(1,5,1))},
                      repro=function(){round(rnorm(1,2,1))}, max.nb.haplo=1e3,
-                     geo.sim=TRUE, grid.size=5, lambda.xy=0.5,
+                     geo.sim=FALSE, grid.size=5, lambda.xy=0.5,
                      mat.connect=NULL,
                      ini.n=1, ini.xy=NULL){
 
@@ -564,6 +564,42 @@
 
 
 
+as.igraph.haploGen <- function(x, ...){
+    if(!require(igraph)) stop("package igraph is required for this operation")
+    if(!require(ape)) stop("package ape is required for this operation")
+    if(!require(ade4)) stop("package ape is required for this operation")
+
+    ## GET DAG ##
+    from <- x$ances
+    to <- x$id
+    isNotNA <- !is.na(from) & !is.na(to)
+    dat <- data.frame(from,to,stringsAsFactors=FALSE)[isNotNA,,drop=FALSE]
+    vnames <- as.character(unique(unlist(dat)))
+    out <- graph.data.frame(dat, directed=TRUE, vertices=data.frame(names=vnames, dates=x$dates[vnames]))
+
+    ## SET WEIGHTS ##
+    D <- as.matrix(dist.dna(x$seq,model="raw")*ncol(x$seq))
+    temp <- mapply(function(i,j) return(D[i,j]), as.integer(from), as.integer(to))
+    E(out)$weight <- temp[isNotNA]
+
+    ## SET ARROW WIDTH ##
+    temp <- max(E(out)$weight) - E(out)$weight
+    temp <- temp/max(temp) * 4
+    E(out)$width <- round(temp)+1
+
+
+    ## ## SET LAYOUT ##
+    ## xcoord <- x$dates
+    ## ##ycoord <- dudi.pco(suppressWarnings(cailliez(as.dist(D))),scannf=FALSE,nf=1)$li[,1]
+    ## ycoord <- 1:length(xcoord)
+    ## set.graph.attribute(out, "layout", as.matrix(data.frame(xcoord,ycoord)))
+
+    return(out)
+}
+
+
+
+
 ##########################
 ## as("haploGen", "graphNEL")
 ##########################

Modified: pkg/man/haploGen.Rd
===================================================================
--- pkg/man/haploGen.Rd	2012-07-09 09:49:52 UTC (rev 1015)
+++ pkg/man/haploGen.Rd	2012-07-09 14:07:15 UTC (rev 1016)
@@ -9,6 +9,7 @@
 % \alias{seqTrackG.haploGen}
 % \alias{optimize.seqTrack.haploGen}
 \alias{as.seqTrack.haploGen}
+\alias{as.igraph.haploGen}
 \alias{plotHaploGen}
 \alias{sample.haploGen}
 %\alias{as,haploGen,graphNEL-method}
@@ -48,6 +49,7 @@
 as.seqTrack.haploGen(x)
 plotHaploGen(x, annot=FALSE, date.range=NULL, col=NULL, bg="grey", add=FALSE, \dots)
 sample.haploGen(x, n)
+\method{as.igraph}{haploGen}(x, \dots)
 %\S4method{coerce}{haploGen,graphNEL}(from, to, strict=TRUE)
 }
 \arguments{



More information about the adegenet-commits mailing list