########################################################################## # This program reads in two text files and output a simplied version of # table3 in the paper. # # The two input files: # vircotable3data.txt # virologictable3data.txt # # Output file format: # Refer to table3 # # Usage: # ftest(filename1, filename2) ## filename should involve directory # # In this program, Fisher's exact test was done to test # whether the proportions of isolates with a pattern of drug resistance # mutations that had levels of fold-resistance exceeding the biological cut-off # were significantly different between the two assays. ########################################################################## ftest <- function(file1, file2) { ## Read in virco and virologic data vircodata = read.table(file1, sep="\t", header=T) virologicdata = read.table(file2, sep="\t", header=T) ## Get simplized files uniqVirco = unique(vircodata[,c(1,2,3,6)]) uniqVirologic = unique(virologicdata[,c(1,2,3,6)]) pvalue<-numeric(nrow(uniqVirco)) ## Get fisher's exact test p-value for (i in 1:nrow(uniqVirco)) { ctable=rbind(uniqVirco[i,c(4,3)], uniqVirologic[i,c(4,3)]) ctable[,2]=ctable[,2]-ctable[,1] pvalue[i]=fisher.test(ctable)$p.value } ## Format output out.table = data.frame(uniqVirco[,c(1,2)], virco=paste(uniqVirco[,4],'/',uniqVirco[,3], sep=''), virologic=paste(uniqVirologic[,4],'/',uniqVirologic[,3], sep=''), pvalue=pvalue) write.table(out.table, file='out.txt', sep='\t', row.names=F, col.names=T, quote=F) }