Search code examples
plotsubsetbioconductor

Plotting subsets of an AffyRNAdeg {affy} object with plot AffyRNAdeg?


library(affy)    
microarrays <- ReadAffy()         # 98 CEL files are read into the same object
RNAdeg <- AffyRNAdeg(microarrays)

Now I want to plot subsets of RNAdeg

plotAffyRNAdeg(RNAdeg[.......?])   # What can I do?

I've tried various 'for' loops without success.

But if plot line colors are specified then plotAffyRNAdeg plots a subset of 1:(number of colors specified), but I haven't thought of a way to use that effectively. For example, below plots the first through the sixth AffyRNAdeg'd set of microarray data (first through sixth .CEL file read in by ReadAffy() )

plotAffyRNAdeg(RNAdeg,col=c(2,2,2,3,3,3))

Solution

  • OK, one way was found by running AffyRNAdeg() on subsets of the object the CEL files are in and putting the resulting data in a list of lists organized by experiment, then plotting the list elements. Maybe there is an easier way, but this worked (I'm quite new to R).

    library(affy)    
    library(RColorBrewer)
    
    > sampleNames(ARTHwoundMA[,11:14])
    [1] "GSE18960_05_GSM469416_trt_rep2.CEL" "GSE18960_06_GSM469418_trt_rep3.CEL"
    [3] "GSE5525_GSM128715_ctrl12h.CEL"      "GSE5525_GSM128716_ctrl24h.CEL
    
    # RNA DEG
    
    # Indices to subset by experiment
    
    cel_names <- substr(sampleNames(ARTHwoundMA),1,7)
    unique_exp <- unique(substr(sampleNames(ARTHwoundMA),1,7))
    exp_ind <- list()
    for (i in 1:length(unique_exp))
      { 
      tempvec <- vector()
      for (j in 1:length(cel_names))
      {
        if (cel_names[j]==unique_exp[i])
        {
          tempvec <- append(tempvec,j)
        }
      }
      exp_ind[[(length(exp_ind)+1)]] <- tempvec
    }
    
    
    # Calculating
    
    RNAdeg_exp <- list()
    for(i in 1:length(exp_ind))
    {
      RNAdeg_exp[[i]] <- AffyRNAdeg(ARTHwoundMA[,exp_ind[[i]]]) 
    }
    
    
    # Plotting
    
    colors <- colorRampPalette(rev(brewer.pal(9, "Reds")))(length(exp_ind[[i]])
    pdf(file="C:\\R working directory\\TEST\\RNAdeg_plots.pdf")
    for(i in 1:length(exp_ind))
    {
      par(bg="gray")
      colors <- colorRampPalette(rev(brewer.pal(9, "Reds")))(length(exp_ind[[i]]))
      plotAffyRNAdeg(RNAdeg_exp[[i]], col=colors)
      plot.new()
      legend("topleft", lty=1, lwd=2,col=colors,
         legend=paste(sampleNames(ARTHwoundMA[,exp_ind[[i]]])))
    }
    
    dev.off()