view summarize_gff_by_attribute.R @ 3:e955b40ad3a4 draft default tip

Uploaded
author petr-novak
date Tue, 12 Oct 2021 07:43:54 +0000
parents cf3cea0a3039
children
line wrap: on
line source

#!/usr/bin/env Rscript
suppressPackageStartupMessages(library(rtracklayer))
g = import(commandArgs(T)[1])
attribute_name = commandArgs(T)[2]

m = mcols(g)
w = width(g)
total_lengths = by(w, INDICES=m[,attribute_name] , sum)
total_counts =  by(w, INDICES=m[,attribute_name] , length)
d = data.frame(attribute = names(total_counts), cbind(counts = total_counts, length=total_lengths))
colnames(d)[1] = attribute_name
d = d[order(d$length, decreasing = TRUE),]
write.table(d, sep = "\t", row.names = FALSE, quote = FALSE)