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