library(haplotypes) library(ape) rm(list = ls()) dir() #load data seq<-read.fas("c02AOwog.fas") #define haplotypes hap<-haplotypes::haplotype(seq) hap length(hap@haplist) #change name of haplotype from 01 to... names(hap@haplist) Hnum<-sprintf('%0.2d', seq(1:base::nrow(hap@sequence))) names(hap@haplist)<-Hnum names(hap@haplist) #Now obtain genotype table for this marker hap.tab<-data.frame(lNames = rep(names(hap@haplist), lapply(hap@haplist, length)), lVal = unlist(hap@haplist)) head(hap.tab) dim(hap.tab) #table hap.tab2<-hap.tab[order(hap.tab[,2]),] head(hap.tab2) base::as.data.frame(gsub("(2)","",seq@seqnames, fixed=T))->id dim(id) dim(hap.tab2) table(id[,1],hap.tab2[,1])->tab dim(tab) head(tab,100) #write table write.table(tab,"C02_geno.txt") #write DNA seq of haplotypes hap@sequence->haplo rownames(haplo)<-Hnum write.dna(haplo, "hapC02.fas", format="fasta")