comparison summarize_gff_by_attribute.R @ 0:cf3cea0a3039 draft

Uploaded
author petr-novak
date Thu, 07 Oct 2021 06:07:34 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cf3cea0a3039
1 #!/usr/bin/env Rscript
2 suppressPackageStartupMessages(library(rtracklayer))
3 g = import(commandArgs(T)[1])
4 attribute_name = commandArgs(T)[2]
5
6 m = mcols(g)
7 w = width(g)
8 total_lengths = by(w, INDICES=m[,attribute_name] , sum)
9 total_counts = by(w, INDICES=m[,attribute_name] , length)
10 d = data.frame(attribute = names(total_counts), cbind(counts = total_counts, length=total_lengths))
11 colnames(d)[1] = attribute_name
12 d = d[order(d$length, decreasing = TRUE),]
13 write.table(d, sep = "\t", row.names = FALSE, quote = FALSE)