####Libraries#### packages = c("ggplot2","tidyr","jsonlite","tidyverse","reshape2","extrafont") invisible(lapply(packages, library, character.only = TRUE)) options(bitmapType="cairo") ####users selection#### lim_inf = 1 #select the minimum isenrtion size lim_sup = 700 #select the maximum insertion size ####define json files path#### json_paths <- read.delim("/users/project/precisiontox_008279/grape-MGI_comaprison/insertion_distribution/all_json_pipeline.db",header = FALSE,sep = "\t") json_paths <- json_paths[,c(1,3)] for(j in 1:nrow(json_paths)) { print(paste("processing sample",j,"of",nrow(json_paths),sep = " ")) json_sample <- json_paths[j,2] ####read files with jsonlite and retrieve insert size#### sample <- fromJSON(json_sample) sample_insertion_size <-sample$general$pairs$insert_sizes ####trasform insert size in data.frame#### insert_size_df <- data.frame(matrix(nrow = 50000, ncol = 1)) colnames(insert_size_df) <- c("insertion length") n=1 for(i in 1:nrow(insert_size_df)) { if(i == as.numeric(names(sample_insertion_size[n]))) { insert_size_df[i,1] <- sample_insertion_size[n] n=n+1 } } ####distribution plot#### insert_size_df[is.na(insert_size_df)] <- 0 insert_size_df <- melt(insert_size_df) insert_size_df <- insert_size_df[lim_inf:lim_sup,] insert_size_df$size <- as.numeric(rownames(insert_size_df)) #plot distribution_plot <- ggplot(insert_size_df,aes(x=size,y=value,col=variable)) + geom_bar(stat='identity',show.legend = FALSE) + xlab("insertion length") + xlim(lim_inf,lim_sup) + ylab("count") + ggtitle(paste(json_paths[j,1]," insertion length distribution",sep = " ")) ####save png#### ggsave(filename = paste("/users/project/precisiontox_008279/grape-MGI_comaprison/insertion_distribution/results/section_0-700/",json_paths[j,1],"_insertion_plot.png",sep = ""), plot = distribution_plot) }