snpMatrix - Creating a 1-column snp.matrix by subsetting a larger snp.matrix
2
0
Entering edit mode
@richard-pearson-1304
Last seen 10.3 years ago
Is there any way of subsetting a snp.matrix on just one column, and ending up with a snp.matrix object (rather than a snp object)? Put another way, is there a way of coercing a snp object to be a snp.matrix object? The following example might illustrate the sort of thing I'm trying to do: > library(snpMatrix) > data(testdata) > subsets <- list("none" = NULL, "one" = 1, "two" = 1:2) > sapply(subsets, function(x) class(Autosomes[,x])) none one two "snp.matrix" "snp" "snp.matrix" I couldn't find anything in the documentation, and am struggling figuring out how to do this by coercing to a regular matrix and then back. Thanks Richard -- Richard D. Pearson richard.pearson at postgrad.manchester.ac.uk School of Computer Science, http://www.cs.man.ac.uk/~pearsonr University of Manchester, Tel: +44 161 275 6178 Oxford Road, Mob: +44 7971 221181 Manchester M13 9PL, UK. Fax: +44 161 275 6204
SNP SNP • 1.4k views
ADD COMMENT
0
Entering edit mode
@vincent-j-carey-jr-4
Last seen 3 months ago
United States
use the old chestnut [,1,drop=FALSE] --- Vince Carey, PhD Assoc. Prof Med (Biostatistics) Harvard Medical School Channing Laboratory - ph 6175252265 fa 6177311541 181 Longwood Ave Boston MA 02115 USA stvjc at channing.harvard.edu On Wed, 4 Jun 2008, Richard Pearson wrote: > Is there any way of subsetting a snp.matrix on just one column, and ending up with a snp.matrix object (rather than a snp object)? Put another way, is there a way of coercing a snp object to be a snp.matrix object? The following example might illustrate the sort of thing I'm trying to do: > > > library(snpMatrix) > > data(testdata) > > subsets <- list("none" = NULL, "one" = 1, "two" = 1:2) > > sapply(subsets, function(x) class(Autosomes[,x])) > none one two > "snp.matrix" "snp" "snp.matrix" > > I couldn't find anything in the documentation, and am struggling figuring out how to do this by coercing to a regular matrix and then back. > > Thanks > > Richard > > -- > Richard D. Pearson richard.pearson at postgrad.manchester.ac.uk > School of Computer Science, http://www.cs.man.ac.uk/~pearsonr > University of Manchester, Tel: +44 161 275 6178 > Oxford Road, Mob: +44 7971 221181 > Manchester M13 9PL, UK. Fax: +44 161 275 6204 > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > The information transmitted in this electronic communica...{{dropped:10}}
ADD COMMENT
0
Entering edit mode
Perfect - a very elegant old chestnut that I'd not tasted previously. Please ignore my later post! Many thanks Vince. Vincent Carey 525-2265 wrote: > use the old chestnut [,1,drop=FALSE] > > --- > Vince Carey, PhD > Assoc. Prof Med (Biostatistics) > Harvard Medical School > Channing Laboratory - ph 6175252265 fa 6177311541 > 181 Longwood Ave Boston MA 02115 USA > stvjc at channing.harvard.edu > > On Wed, 4 Jun 2008, Richard Pearson wrote: > >> Is there any way of subsetting a snp.matrix on just one column, and ending up with a snp.matrix object (rather than a snp object)? Put another way, is there a way of coercing a snp object to be a snp.matrix object? The following example might illustrate the sort of thing I'm trying to do: >> >>> library(snpMatrix) >>> data(testdata) >>> subsets <- list("none" = NULL, "one" = 1, "two" = 1:2) >>> sapply(subsets, function(x) class(Autosomes[,x])) >> none one two >> "snp.matrix" "snp" "snp.matrix" >> >> I couldn't find anything in the documentation, and am struggling figuring out how to do this by coercing to a regular matrix and then back. >> >> Thanks >> >> Richard >> >> -- >> Richard D. Pearson richard.pearson at postgrad.manchester.ac.uk >> School of Computer Science, http://www.cs.man.ac.uk/~pearsonr >> University of Manchester, Tel: +44 161 275 6178 >> Oxford Road, Mob: +44 7971 221181 >> Manchester M13 9PL, UK. Fax: +44 161 275 6204 >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > The information transmitted in this electronic communi...{{dropped:19}}
ADD REPLY
0
Entering edit mode
@richard-pearson-1304
Last seen 10.3 years ago
I had done something daft when trying to convert to a regular matrix and back, but have now figured out how to do this - apologies for the noise! For the record here's what I did: subsetSnpMatrix <- function(snpmat, subsetColumns) { new("snp.matrix", matrix( as(snpmat[,subsetColumns], "matrix"), nrow = dim(snpmat)[1], dimnames = list( dimnames(snpmat)[[1]], dimnames(snpmat)[[2]][subsetColumns] ) ) ) } sapply(subsets, function(x) class(subsetSnpMatrix(Autosomes, x))) none one two "snp.matrix" "snp.matrix" "snp.matrix" If anyone has a more elegant solution that doesn't involve coercing to a regular matrix I'd still find it useful. Best wishes Richard. Richard Pearson wrote: > Is there any way of subsetting a snp.matrix on just one column, and > ending up with a snp.matrix object (rather than a snp object)? Put > another way, is there a way of coercing a snp object to be a snp.matrix > object? The following example might illustrate the sort of thing I'm > trying to do: > >> library(snpMatrix) >> data(testdata) >> subsets <- list("none" = NULL, "one" = 1, "two" = 1:2) >> sapply(subsets, function(x) class(Autosomes[,x])) > none one two "snp.matrix" "snp" > "snp.matrix" > I couldn't find anything in the documentation, and am struggling > figuring out how to do this by coercing to a regular matrix and then back. > > Thanks > > Richard > -- Richard D. Pearson richard.pearson at postgrad.manchester.ac.uk School of Computer Science, http://www.cs.man.ac.uk/~pearsonr University of Manchester, Tel: +44 161 275 6178 Oxford Road, Mob: +44 7971 221181 Manchester M13 9PL, UK. Fax: +44 161 275 6204
ADD COMMENT

Login before adding your answer.

Traffic: 651 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6