[BioC] XOR or intersect for several vectors

Hervé Pagès hpages at fhcrc.org
Wed Mar 30 22:41:12 CEST 2011


Hi Wendy,

What about first generating a logical matrix describing the
appartenance of each of your genes to each of your groups:

   > allgenes <- unique(c(A, B, C))
   > m <- cbind(A=allgenes %in% A, B=allgenes %in% B, C=allgenes %in% C)
   > rownames(m) <- allgenes
   > m
         A     B     C
   a  TRUE  TRUE  TRUE
   b  TRUE FALSE FALSE
   c  TRUE FALSE FALSE
   e FALSE  TRUE FALSE
   f FALSE  TRUE FALSE
   g FALSE FALSE  TRUE
   l FALSE FALSE  TRUE

Then it's easy to query this matrix in any way you like. For example,
to get the genes that belong to A and C:

   > m[ , "A"] & m[ , "C"]
       a     b     c     e     f     g     l
    TRUE FALSE FALSE FALSE FALSE FALSE FALSE

The genes that belong to A or C:

   > m[ , "A"] | m[ , "C"]
       a     b     c     e     f     g     l
    TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE

The number of groups that each gene belongs to:

   > rowSums(m)
   a b c e f g l
   3 1 1 1 1 1 1

The genes that belong to all the groups:

   > rowSums(m) == ncol(m)
       a     b     c     e     f     g     l
    TRUE FALSE FALSE FALSE FALSE FALSE FALSE

etc...

H.


On 03/29/2011 08:02 PM, Wendy Qiao wrote:
> Hi all,
>
> I am trying to get a list of genes that can distinguish 24 cell types. After
> comparing each cell type to the grand mean, I got a list of genes for each
> cell type. I want to check the intersect of all the lists and the unique
> genes for each cell type. I thought to use logical operators, such as XOR
> and intersect, but I found that all these operators are for two vectors
> only. Does anybody know if there is operator functions for several vectors.
>
> To explain my problem more clearly, here is an example...
>
> A = c("a","b","c")
> B = c("e","f","a")
> C = c("a","g","l")
>
> I want the outputs to be
>
> intersect_output = c("a")
> xor_output = c("b","c","e","f","g","l")
>
> Thank you in advance,
> Wendy
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor


-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioconductor mailing list