bedtools intersect -a ../../bam2bwfile/male_per_bin_rawcounts.tab -b ../allmale_ltr.bed -wb > male.ltr.bed
awk '{print $9"\t"$10"\t"$11"\t"$4}' heatmap/male.ltr.bed > heatmap/male.ltr.wt1.bed
awk '{print $9"\t"$10"\t"$11"\t"$5}' heatmap/male.ltr.bed > heatmap/male.ltr.wt2.bed
awk '{print $9"\t"$10"\t"$11"\t"$6}' heatmap/male.ltr.bed > heatmap/male.ltr.ko1.bed
awk '{print $9"\t"$10"\t"$11"\t"$7}' heatmap/male.ltr.bed > heatmap/male.ltr.ko2.bed
awk '{print $9"\t"$10"\t"$11"\t"$8}' heatmap/male.ltr.bed > heatmap/male.ltr.ko3.bed
for i in *.bed ; do i=${i%.bed*}; sort -k1,1 -k2,2n ${i}.bed -o sort.${i}.bed ;done
for i in *.bed ; do i=${i%.bed*}; bedops --partition ${i}.bed | bedmap --echo --echo-map-id-uniq --delim '\t' - ${i}.bed | awk '{ n = split($4, a, ";"); max = a[1]; for(i = 1; i <= n; i++) { if (a[i] > max) { max = a[i];} } print $1"\t"$2"\t"$3"\t"max; }' > ${i}.rpkm.bed ; done
paste sort.male.ltr.wt1.rpkm.bed sort.male.ltr.wt2.rpkm.bed sort.male.ltr.ko1.rpkm.bed sort.male.ltr.ko2.rpkm.bed sort.male.ltr.ko3.rpkm.bed > all.male.ltr.bed
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$8"\t"$12"\t"$16"\t"$20}' all.male.ltr.bed > all.male.ltr.rpkm.bed