Mercurial > repos > greg > multilocus_genotype
comparison multilocus_genotype.R @ 15:62ad61eac1ff draft
Uploaded
author | greg |
---|---|
date | Thu, 20 Dec 2018 11:29:13 -0500 |
parents | 96ee9122823e |
children | c4ec8727b50c |
comparison
equal
deleted
inserted
replaced
14:96ee9122823e | 15:62ad61eac1ff |
---|---|
270 par(mar = c(8, 4, 4, 2)); | 270 par(mar = c(8, 4, 4, 2)); |
271 x <- barplot(miss96, las=2, col=cols, ylim=c(0, 3), cex.axis=0.8, space=0.8, ylab="Missingness (%)", xaxt="n"); | 271 x <- barplot(miss96, las=2, col=cols, ylim=c(0, 3), cex.axis=0.8, space=0.8, ylab="Missingness (%)", xaxt="n"); |
272 text(cex=0.6, x=x-0.25, y=-.05, name96, xpd=TRUE, srt=60, adj=1); | 272 text(cex=0.6, x=x-0.25, y=-.05, name96, xpd=TRUE, srt=60, adj=1); |
273 dev.off() | 273 dev.off() |
274 | 274 |
275 # Generate 96 pie charts. Make a table to subset the numerical | 275 # Generate a pie chart for each sample with a genotype. |
276 # and user_specimen_id values out of report_user for the 96 pies | 276 # Store the numerical and user_specimen_id values from |
277 # (user_specimen_id names will be used to label each pie). | 277 # report_user for the charts (user_specimen_id names |
278 # will be used to label each chart). | |
278 dt1 <- data.table(report_user); | 279 dt1 <- data.table(report_user); |
279 dt1 <- report_user[c(-2, -3, -4)]; | 280 dt1 <- report_user[c(-2, -3, -4)]; |
280 dt1 <- na.omit(dt1); | 281 dt1 <- na.omit(dt1); |
281 # Translate to 96 columns and 5 rows. | 282 # Translate to N (i.e., number of samples with a |
283 # genotype) columns and 5 rows. | |
282 tdt1 <- t(dt1); | 284 tdt1 <- t(dt1); |
283 # Make another data table and transpose it the same as dt1 to | 285 # Make another data table and transpose it the same as dt1 to |
284 # just get numerics; these will feed into the creation of 96 | 286 # get numerics. These will feed into the creation of N vectors. |
285 # vectors, "x" in the for loop below. | |
286 dt2 <- data.table(report_user); | 287 dt2 <- data.table(report_user); |
287 dt2 <- report_user[c(-1, -2, -3, -4)]; | 288 dt2 <- report_user[c(-1, -2, -3, -4)]; |
288 # Translate to 96 columns and 5 rows. | 289 # Translate to N columns and 5 rows. |
289 tdt2 <- t(dt2); | 290 tdt2 <- t(dt2); |
290 # Create 96 vectors | |
291 x <- tdt2[1:96]; | |
292 tdt1_matrix <- as.matrix(tdt1[-1,]); | 291 tdt1_matrix <- as.matrix(tdt1[-1,]); |
292 # The number of columns is the number of samples with genotypes. | |
293 nc <- ncol(tdt1_matrix); | |
293 mode(tdt1_matrix) <- "numeric"; | 294 mode(tdt1_matrix) <- "numeric"; |
294 spy <- rowMeans(tdt1_matrix); | 295 spy <- rowMeans(tdt1_matrix); |
295 dev.new(width=10, height=7); | 296 dev.new(width=10, height=7); |
296 file_path = get_file_path("percent_breakdown.pdf"); | 297 file_path = get_file_path("percent_breakdown.pdf"); |
297 pdf(file=file_path, width=10, height=7); | 298 pdf(file=file_path, width=10, height=7); |
300 col <- c("GREY", "#006DDB", "#24FF24", "#920000"); | 301 col <- c("GREY", "#006DDB", "#24FF24", "#920000"); |
301 main <- "Average breakdown of SNP assignments across all samples"; | 302 main <- "Average breakdown of SNP assignments across all samples"; |
302 pie(spy, labels=labels, radius=0.60, col=col, main=main, cex.main=.75); | 303 pie(spy, labels=labels, radius=0.60, col=col, main=main, cex.main=.75); |
303 par(mfrow=c(3, 2)); | 304 par(mfrow=c(3, 2)); |
304 col <- c("GREY", "#006DDB", "#24FF24", "#920000"); | 305 col <- c("GREY", "#006DDB", "#24FF24", "#920000"); |
305 for (i in 1:96) { | 306 for (i in 1:nc) { |
306 tmp_labels <- paste(labels, " (", round(tdt1_matrix[,i], 1), "%)", sep=""); | 307 tmp_labels <- paste(labels, " (", round(tdt1_matrix[,i], 1), "%)", sep=""); |
307 main <- paste("Breakdown of SNP assignments for", tdt1[1, i]); | 308 main <- paste("Breakdown of SNP assignments for", tdt1[1, i]); |
308 pie(tdt1_matrix[,i], labels=tmp_labels, radius=0.90, col=col, main=main, cex.main=.85, cex=0.75); | 309 pie(tdt1_matrix[,i], labels=tmp_labels, radius=0.90, col=col, main=main, cex.main=.85, cex=0.75); |
309 } | 310 } |
310 dev.off() | 311 dev.off() |