Mercurial > repos > kyost > atac_primer_tool
comparison window_coverage.bash @ 0:fd3ea97a96bc draft
planemo upload commit 103cb51ec368438642504c3f98b76c363db478bb
author | kyost |
---|---|
date | Sat, 28 Apr 2018 15:07:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fd3ea97a96bc |
---|---|
1 #!/bin/bash | |
2 | |
3 #Requires bam files and bed file containing coordinates of peaks of interest | |
4 #Determines regions within peaks where included fragement coverage best correlates | |
5 #with total read count under peak. Exports regions as bed file. | |
6 | |
7 #required arguements: | |
8 #($1): series of bam files | |
9 #($2): file names of bam files | |
10 #($3): window bed file | |
11 #($4): percent of window fragments must cover, default is 0.9 | |
12 #($5): output coverage file | |
13 #($6): output spanning fragment coverage file | |
14 | |
15 #Usage: ATAC_qPCR_regions.bash bam_series name_list qPCR_windows.bed 0.9 combined.o.bed.coverage combined.f9.bed.coverage | |
16 | |
17 bam_series=$1 | |
18 name_list=$2 | |
19 qPCR_windows=$3 | |
20 percent_overlap=${4:-0.9} | |
21 combined_o=$5 | |
22 combined_f9=$6 | |
23 | |
24 COUNTER=0 | |
25 echo $bam_series |tr , '\n' > bam_series.txt | |
26 echo $name_list | tr , '\n' > name_list.txt | |
27 paste name_list.txt bam_series.txt > bam_name_list.txt | |
28 sort -k1 bam_name_list.txt > sorted_bam_name_list.txt | |
29 cut -f 2 sorted_bam_name_list.txt > sorted_bam_list.txt | |
30 | |
31 cat sorted_bam_list.txt | while read file | |
32 do | |
33 | |
34 #create bed file of fragments for each bam file | |
35 | |
36 samtools sort -n -o - $file | samtools fixmate - - | bamToBed -i - -bedpe | cut -f 1,2,6 > "${file}".includeinsert.bed | |
37 | |
38 #determine window coverage for each bam file | |
39 #combined_o: Total reads in peak/window | |
40 #combined_f9: Spanning reads in window | |
41 | |
42 if [ $COUNTER -eq 0 ] | |
43 then | |
44 coverageBed -a $qPCR_windows -b $file | cut -f 1,2,3,4,5 > $combined_o | |
45 coverageBed -a $qPCR_windows -b "${file}".includeinsert.bed -f $percent_overlap | cut -f 1,2,3,4,5 > $combined_f9 | |
46 | |
47 else | |
48 coverageBed -a $qPCR_windows -b $file | cut -f 5 > temp.o.bed.coverage | |
49 coverageBed -a $qPCR_windows -b "${file}".includeinsert.bed -f $percent_overlap | cut -f 5 > temp.f9.bed.coverage | |
50 paste $combined_o temp.o.bed.coverage > combined.temp.o.bed.coverage | |
51 mv combined.temp.o.bed.coverage $combined_o | |
52 paste $combined_f9 temp.f9.bed.coverage > combined.temp.f9.bed.coverage | |
53 mv combined.temp.f9.bed.coverage $combined_f9 | |
54 | |
55 rm temp.o.bed.coverage | |
56 rm temp.f9.bed.coverage | |
57 | |
58 fi | |
59 | |
60 rm "${file}.includeinsert.bed" | |
61 | |
62 let COUNTER=COUNTER+1 | |
63 | |
64 done | |
65 | |
66 | |
67 rm *.txt |