[BioC] Functions
James W. MacDonald
jmacdon at uw.edu
Mon Jun 10 23:06:03 CEST 2013
Hi Ipsitha,
On 6/7/2013 12:26 PM, Ipsitha [guest] wrote:
> Hi
>
> I am trying to do some data analysis using R and Bioconductor. I have a function to read my data called "ReadAffyData" and a function to plot the data called "preqc". I want to know if there is any way I can extract information (read: Data) from the ReadAffyData function into preqc in order to produce plots? I have not completely understood the inheritance in R and I am getting errors similar to the one below. I am new to R and could do with any help in this aspect!
>
> Code:
> ReadAffyData<- function( filename ) {
>
> require(affy)
> require(annotate)
>
> Cov<- read.table( filename, sep="\t", header=1, quote="", comment="" )
> if( ! all( c( "Filename", "Label", "Repl", "Trt" ) %in% colnames( Cov ) ) )
> {
> stop( "Missing mandatory column" )
> }
>
> Cov<- Cov[order(Cov$Trt),]
> i<- table(Cov$Trt)
> Cov$Repl<- unlist( lapply( i, function( j ) 1:j ) )
> Cov$Label<- paste( as.character( Cov$Trt ), Cov$Repl, sep=":" )
> rownames(Cov)<- as.character(Cov$Label)
>
> tmp1<- colnames( Cov )
> tmp2<- rep( "", length( Cov ) )
>
> for( i in 1:length( tmp2 ) )
> {
> tmp2[i]<- paste( sort( unique( as.character( Cov[,i] ) ) ), collapse="/" )
> }
>
> labelDescription<- data.frame( labelDescription=tmp2 )
>
> rownames( labelDescription )<- tmp1
> tmp<- new( "AnnotatedDataFrame", data=Cov, varMetadata=labelDescription)
>
> Data<- ReadAffy( sampleNames=as.character( Cov$Label ),phenoData=tmp, verbose=TRUE )
> }
This function doesn't return anything. You can end the function in one
of three ways. The last lines can be
ReadAffy(sampleNames=as.character( Cov$Label ),phenoData=tmp, verbose=TRUE )
}
or
Data <- ReadAffy( sampleNames=as.character( Cov$Label ),phenoData=tmp,
verbose=TRUE )
Data
}
or
Data <- ReadAffy( sampleNames=as.character( Cov$Label ),phenoData=tmp,
verbose=TRUE )
return(Data)
}
But your function as written creates the Data object and then closes
without returning that object to you.
>
> preQC<- function(name){
> ReadAffyData(name)
> plotDensity( log2( pm( Data ) ), xlab="Log2( Intensity )", ylab="Density", main="Raw(PM)")
> }
And even if you fix your ReadAffyData function to return the Data
object, this function won't work, because you aren't capturing the
output in an object. You need to do this:
preQC<- function(name){
Data<- ReadAffyData(name)
plotDensity( log2( pm( Data ) ), xlab="Log2( Intensity )", ylab="Density", main="Raw(PM)")
}
Best,
Jim
>
> preQC("cov.txt")
> 1 reading C:/CEL/GSM311471.CEL ...instantiating an AffyBatch (intensity a 506944x24 matrix)...done.
> Reading in : C:/CEL/GSM311471.CEL
> Reading in : C:/CEL/GSM311472.CEL
> Reading in : C:/CEL/GSM311473.CEL
> Reading in : C:/CEL/GSM311474.CEL
> Reading in : C:/CEL/GSM311475.CEL
> .
> .
> .
> Error in pm(Data) :
> error in evaluating the argument 'object' in selecting a method for function 'pm': Error: object 'Data' not found
>
>
> -- output of sessionInfo():
>
> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: i386-w64-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 LC_MONETARY=English_India.1252
> [4] LC_NUMERIC=C LC_TIME=English_India.1252
>
> attached base packages:
> [1] parallel stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] annotate_1.38.0 AnnotationDbi_1.22.6 affy_1.38.1 Biobase_2.20.0 BiocGenerics_0.6.0
>
> loaded via a namespace (and not attached):
> [1] affyio_1.28.0 BiocInstaller_1.10.1 DBI_0.2-7 IRanges_1.18.1 preprocessCore_1.22.0
> [6] RSQLite_0.11.4 stats4_3.0.1 tools_3.0.1 XML_3.96-1.1 xtable_1.7-1
> [11] zlibbioc_1.6.0
>
>
> --
> Sent via the guest posting facility at bioconductor.org.
>
> _______________________________________________
> 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
--
James W. MacDonald, M.S.
Biostatistician
University of Washington
Environmental and Occupational Health Sciences
4225 Roosevelt Way NE, # 100
Seattle WA 98105-6099
More information about the Bioconductor
mailing list