Small comment on Jim's script


On Mon, Oct 21, 2013 at 10:50 AM, James W. MacDonald <jmacdon@uw.edu> wrote:

> gns <- select(org.Hs.eg.db, row.names(data), c("ENTREZID","SYMBOL"),
> "ACCNUM")
>
> You may get a warning that you have some one-to-many mappings here. How
> you deal with that is up to you. I normally take the most naive approach
> possible and just do
>
> gns <- gns[!duplicated(gns[,1]),]
>

Because duplicated is FALSE only for the second occurance of an object, ie
  > duplicated(c("a", "a"))
 [1] FALSE  TRUE
you are effectively resolving your one-to-many mappings by including only
the first mapping in the object.  This (of course) depends on the order of
the mappings. I may be wrong, but I don't think there is any implied order
of the mappings, and even if there is, I am not sure that the database
interface respects this order in how it returns things.  Unfortunately, the
code above hides the fact that you are just picking a random mapping, so I
would suggest something like

tapply(gns, gns[,1], function(xx) {
  xx[ sample(1:nrow(xx), size = 1), ]
})

which makes the random nature obvious, or, in case you want to discard
stuff,
  gns[ ! gns[,1] %in% gns[duplicated(gns[,1]),1],]

(code not fully tested)

Best,
Kasper

	[[alternative HTML version deleted]]

