Back to Manny's Bioinformatics Workshop Home

Converting SNP Format

This is not the most efficient way to process this, however intuitively its the simplest.

Initialize vectors to save output which can be combined later

snpcol=character()
gencol=character()
allelesa=character()
allelesb=character()
confcol=character()

The number of rows for final output

rowcounter=1

Foreach snp

for (i in 1:ncol(snponly)) {
    #foreach genotype
    for (j in 1:nrow(snponly)) {
      
      #only do steps if value is not NA
      if (!is.na(snponly[j,i])) {              
        alleles = unlist(strsplit(as.character(snponly[1,1]), ""))
        snpcol[rowcounter]=colnames(snponly)[i]
        gencol[rowcounter]=rownames(snponly)[j]
        allelesa[rowcounter]=alleles[1]
        allelesb[rowcounter]=alleles[2]
        confcol[rowcounter]="1"
        rowcounter=rowcounter+1
      } 
      
    }
}