combine_bam_qc.R 847 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env Rscript
  2. args <- commandArgs(trailingOnly = TRUE)
  3. # Ensure at least one file is provided
  4. if(length(args) < 1) {
  5. stop("Please provide at least one TSV file as input.")
  6. }
  7. # Read the first file to get the statistics names (assuming all files have the same structure)
  8. first_file <- read.table(args[1], header = TRUE, sep="\t", stringsAsFactors = FALSE)
  9. stats_names <- first_file$Statistics
  10. # Initialize a data frame for results
  11. results <- data.frame(Statistics = stats_names)
  12. # Loop over all files and merge them into the results dataframe
  13. for(file in args) {
  14. sample_data <- read.table(file, header = TRUE, sep="\t", stringsAsFactors = FALSE)
  15. sample_name <- colnames(sample_data)[2]
  16. results[sample_name] <- sample_data[,2]
  17. }
  18. # Print the results
  19. write.table(results, sep="\t", quote=FALSE, row.names=FALSE, col.names=TRUE)