0
|
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)
|