...
Code Block |
---|
|
cat yeast_mrna.gene_coverage.almost.bedGraph | awk '
BEGIN{FS=OFS="\t"; chr=""; start=-1; end=-1; tot=0}
{if (chr != $1) { # new contig; finish previous
if (start > -1) { print chr,start,end,tot }
chr=$1; start=$2; end=$3; tot=$4
} else if ($2==startend|| $2==startend+1) { # same or adjacent position
tot = tot + $4; end=$3;
} else { # new region on same contig; finish prev
if (start > -1) { print chr,start,end,tot }
start=$2; end=$3; tot=$4
}
}
END{ # finish last
if (start > -1) { print chr,start,end,tot }
}' > yeast_mrna.gene_coverage.bedGraph
wc -l yeast_mrna.gene_coverage.bedGraph # 124,591 -- much better! |
Make sure the total counts match!
Code Block |
---|
|
cat yeast_mrna.gene_coverage.txt | awk '
BEGIN{tot=0}{tot=tot+$8}END{print tot}' # should be 86703686
cat yeast_mrna.gene_coverage.bedGraph | awk '
BEGIN{tot=0}{tot=tot+$4}END{print tot}' # should also be 86703686 |