R-示例

data=read.table(“TP53.vcf”,header=FALSE)

sample1=apply(matrix(data$V10),1,function(x)unlist(strsplit(x,split=”:”))[1])
sample1_info=data.frame(t(apply(t(t(sample1)),1,function(x)unlist(strsplit(x,split=”/”)))))

sample2=apply(matrix(data$V11),1,function(x)unlist(strsplit(x,split=”:”))[1])
sample2_info=data.frame(t(apply(t(t(sample2)),1,function(x)unlist(strsplit(x,split=”/”)))))

sample3=apply(matrix(data$V12),1,function(x)unlist(strsplit(x,split=”:”))[1])
sample3_info=data.frame(t(apply(t(t(sample3)),1,function(x)unlist(strsplit(x,split=”/”)))))

sample1_hom_num=0
sample2_hom_num=0
sample3_hom_num=0

sample1_het_num=0
sample2_het_num=0
sample3_het_num=0

non_vari=0

for(i in 1:nrow(sample1_info))
{
if((matrix(sample1_info[i,1])== matrix(sample1_info[i,2]))==’FALSE’)
         sample1_het_num=sample1_het_num+1
else
     sample1_hom_num=sample1_hom_num+1
     if(matrix(sample1_info[i,1])==0 && matrix(sample1_info[i,2])==0)
         non_vari=non_vari+1
}

for(i in 1:nrow(sample2_info))
{
if((matrix(sample2_info[i,1])== matrix(sample2_info[i,2]))==’FALSE’)
         sample2_het_num=sample2_het_num+1
else
     sample2_hom_num=sample2_hom_num+1
     if(matrix(sample2_info[i,1])==0 && matrix(sample2_info[i,2])==0)
         non_vari=non_vari+1
}

for(i in 1:nrow(sample3_info))
{
if((matrix(sample3_info[i,1])== matrix(sample3_info[i,2]))==’FALSE’)
         sample3_het_num=sample3_het_num+1
else
     sample3_hom_num=sample3_hom_num+1
     if(matrix(sample3_info[i,1])==0 && matrix(sample3_info[i,2])==0)
         non_vari=non_vari+1
}

hom_row=cbind(sample1_hom_num,sample2_hom_num,sample3_hom_num)
het_row=cbind(sample1_het_num,sample2_het_num,sample3_het_num)
hom_het_total=rbind(hom_row,het_row)
colnames(hom_het_total)=c(“27DMBDM4YT”,”APRDKV0LDS”,”7XKZJA3JWX”)
rownames(hom_het_total)=c(“Homozygous”,”Heterozygote”)

vari_num=sum(hom_het_total)- non_vari
print(vari_num)
write.table(hom_het_total,”sample_case”,quote=FALSE)