Thank you for your answer! I have met the same question, but I don't know how to use the function genotype, could you give the examples? I appreciate. Deletion should be reserved to errors or inappropriate content.
I created the files similar to en example given in http://cran.r-project.org/web/packages/LDheatmap/vignettes/LDheatmap.pdf. Which are CEUDist (only one column of distance) and CEUSNP (genotypic data, with the markers name). However, I obtained the error saying "column 1 is not a genotype object"
CEUSNP
snp1 snp2 snp3 snp4 snp5 snp6
G/G A/A C/C G/G G/G G/G
A/A G/G C/C G/G A/A G/G
G/G G/G C/C G/G G/G G/G
G/G G/G C/C G/G A/A G/G
G/G G/G C/C T/T A/A G/G
G/G G/G A/A T/T G/G G/G
G/G G/G A/A G/G G/G G/G
A/A G/G C/C T/T A/A G/G
A/A G/G C/C G/G G/G G/G
A/A G/G <NA> G/G A/A G/G
A/A G/G A/A G/G A/A G/G
G/G G/G A/A G/G G/G G/G
G/G G/G C/C G/G A/A G/G
and
CEUDist
123456
123524
123457
123525
123458
123526
Could you tell me what I did wrong in this case?
Also, can I use CC instead of C/C and NA instead of <NA> in the genotypic file?
It will be great if any of you can share an example files with me.
Thank you in advance.
Jane
2 answers
The vignette for that package is terrible. You need to load the genetics package and then use genotype() when creating the data.frame. In short, you need two columns for each individual, one column per allele. That genotype function will then return a properly formatted genotype object. You'll do that for each SNP and save the results in a data.frame. They really should have given an example in the vignette.
Devon Ryan, Hi Devon Ryan. I am trying to add genotype object to my SNP data set. I am unable to use the codes described in the subsequent comment as my map file is not generated from the vcf tools. I used tassel generated VCF files instead where the V2 column contains the alleles (either form separated by /). The error in R says Error in expectedGenotypes(alleles = alleles, haplotype = TRUE) : Zero length alleles vector. when I use the following codes to construct the dataframe
> class(SNPdata[,1])
> for(i in 1:num){SNPdata[,i]<-as.genotype(SNPdata[,i])}
Error in expectedGenotypes(alleles = alleles, haplotype = TRUE) :
Zero length alleles vector.
Can you kindly help me with the same. Thank you in advance.
I was wondering if you had the chance to look at my request pertaining to problem in plotting LD plot using LDheatmap package. Your kind help is greatly appreciated. If you need more clarity on the specific issue with my problem, please do let me know. Many thanks for your help.
Bornali
I came across the same question as you do. I convert the data.frame of my own data into a genotype object using the Devon Ryan's suggestion and It works! There is a as.genotype() function in genetics package.I use this function to convert the normal data.frame to a genotype object. The example is
num<-ncol(SNPdata) # SNPdata is a data.frame which looks like the CEUSNP above.
colnames(SNPdata)<-map$V2 # Name the SNPdata columns with the 2nd column of map file(produced by vcftools).
class(SNPdata[,1]) # You will get "factor".
for(i in 1:num){
SNPdata[,i]<-as.genotype(SNPdata[,i]) # convert the columns of the original data frame into genotype objects
}
class(SNPdata[,1]) #Here you can see the class becomes "genotype factor".Then you can put the SNPdata into LDheatmap().
Thank you and Devon Ryan!
Glad it works :)
Log in to answer this question.
how can one create a data.frame which looks like the CEUSNP from a vcf file?.