-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign_reads.sh
167 lines (131 loc) · 9.92 KB
/
align_reads.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
export PATH=$PATH:~/samtools-0.1.19
export PATH=$PATH:~/bwa
read_1=$1
read_2=$2
reference=$3
##################################################################################
#
# USAGE: bash align_reads.sh [read 1] [read 2] [reference]
#
# bash /home/sheltonj/scripts/align_reads.sh /home/sheltonj/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds/reads/Tribolium3kb_1_prinseq_good_P7uO.fastq /home/sheltonj/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds/reads/Tribolium3kb_2_prinseq_good_36G8.fastq /home/sheltonj/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds/tcas.scaffolds.fasta
# Created by jennifer shelton
#
##################################################################################
##################################################################################
############## retrive reads: from the VM on NGS1 ##################
##################################################################################
# sudo mount -t vboxsf ubuntu /home/sheltonj/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds/reads #from the VM
##################################################################################
############## retrive reads: from NGS1 ##################
##################################################################################
# cd /home/sheltonj/ubuntu # from NGS1
# scp [email protected]:/homes/bioinfo/Tcas/Tribolium3kb_*_prinseq_good_*.fastq ./
# scp [email protected]:/homes/bioinfo/Tcas/sanger_reads/Trib_cast_R*_*_good_good.fastq ./
# scp [email protected]:/homes/bioinfo/Tcas/Tribolium20kb_*_prinseq_good_*.fastq ./
# scp [email protected]:/homes/bioinfo/Tcas/Tribolium8kb_*_prinseq_good_*.fastq ./
##################################################################################
############## get path to reads ##################
##################################################################################
filename_1="${1##*/}" # Strip longest match of */ from start
dir_1="${1:0:${#1} - ${#filename_1}}" # Substring from 0 thru pos of filename
base_1="${filename_1%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end
ext_1="${filename_1:${#base_1} + 1}" # Substring from len of base thru end
if [[ -z "$base_1" && -n "$ext_1" ]]; then # If we have an extension and no base, it's really the base
base_1=".$ext_1"
ext_1=""
fi
echo "${filename_1}";
echo "${dir_1}";
filename_2="${2##*/}" # Strip longest match of */ from start
dir_2="${2:0:${#2} - ${#filename_2}}" # Substring from 0 thru pos of filename
base_2="${filename_2%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end
ext_1="${filename_2:${#base_2} + 1}" # Substring from len of base thru end
if [[ -z "$base_2" && -n "$ext_2" ]]; then # If we have an extension and no base, it's really the base
base_1=".$ext_2"
ext_1=""
fi
echo "${filename_2}";
echo "${dir_2}";
##################################################################################
############## get path to reference ##################
##################################################################################
ref_filename="${3##*/}" # Strip longest match of */ from start
ref_dir="${3:0:${#3} - ${#ref_filename}}" # Substring from 0 thru pos of filename
ref_base="${ref_filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end
ref_ext="${ref_filename:${#ref_base} + 1}" # Substring from len of base thru end
if [[ -z "$ref_base" && -n "$ref_ext" ]]; then # If we have an extension and no base, it's really the base
ref_base=".$ref_ext"
ref_ext=""
fi
##################################################################################
############## create output directory ##################
##################################################################################
if [ ! -d "${dir_1}Alignments/${ref_base}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir -p "${dir_1}Alignments/${ref_base}"
fi
#####################################################
################# align reads to ref ################
#####################################################
cd ${dir_1}
# ~/bwa/bwa index ${reference}
~/bwa/bwa aln -o 0 -t 4 ${reference} ${filename_1} > "${dir_1}Alignments/${ref_base}/${base_1}.sai"
~/bwa/bwa aln -o 0 -t 4 ${reference} ${filename_2} > "${dir_1}Alignments/${ref_base}/${base_2}.sai"
~/bwa/bwa sampe ${reference} "${dir_1}Alignments/${ref_base}/${base_1}.sai" "${dir_1}Alignments/${ref_base}/${base_2}.sai" ${read_1} ${read_2} | samtools view -Shu -@ 4 - | samtools sort -@ 4 - "${dir_1}Alignments/${ref_base}/${base_1}.bwa.sorted"
~/samtools-0.1.19/samtools index "${dir_1}Alignments/${ref_base}/${base_1}.bwa.sorted.bam"
# #!/bin/bash
# export PATH=$PATH:~/samtools-0.1.19
# export PATH=$PATH:~/bwa
# # align_reads.sh
# #
# #
# # Created by jennifer shelton on 11/12/13.
# #
# #####################################################
# ################# retrive reads #####################
# #####################################################
# # scp [email protected]:/homes/bioinfo/Tcas/Tribolium3kb_1_prinseq_good_P7uO.fastq ./
# # scp [email protected]:/homes/bioinfo/Tcas/Tribolium3kb_2_prinseq_good_36G8.fastq ./
# #####################################################
# ################# align reads to ref ################
# #####################################################
# cd ~/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds
# mkdir -p ./Alignments2/tcas_4.0_scaffolds
# ~/bwa/bwa index tcas.scaffolds.fasta
# ~/bwa/bwa aln -o 0 -t 4 ./tcas.scaffolds.fasta ./Tribolium3kb_1_prinseq_good_P7uO.fastq > ./Alignments2/tcas_4.0_scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai
# ~/bwa/bwa aln -o 0 -t 4 ./tcas.scaffolds.fasta ./Tribolium3kb_2_prinseq_good_36G8.fastq > ./Alignments2/tcas_4.0_scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai
# ~/bwa/bwa sampe ./tcas.scaffolds.fasta ./Alignments2/tcas_4.0_scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai ./Alignments2/tcas_4.0_scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai ./Tribolium3kb_1_prinseq_good_P7uO.fastq ./Tribolium3kb_2_prinseq_good_36G8.fastq | samtools view -Shu -@ 4 - | samtools sort -@ 4 - ./Alignments2/tcas_4.0_scaffolds/tcas_4.0_scaff_3kb.bwa.sorted
# ~/samtools-0.1.19/samtools index ./Alignments2/tcas_4.0_scaffolds/tcas_4.0_scaff_3kb.bwa.sorted.bam
# # #####################################################
# # ################# align reads to slave ##############
# # #####################################################
# # mkdir -p ./Alignments2/Kmer_merges_81-scaffolds
# #
# # ~/bwa/bwa index Kmer_merges_81-scaffolds.fa
# # ~/bwa/bwa aln -o 0 -t 4 ./Kmer_merges_81-scaffolds.fa ./Tribolium3kb_1_prinseq_good_P7uO.fastq > ./Alignments2/Kmer_merges_81-scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai
# #
# # ~/bwa/bwa aln -o 0 -t 4 ./Kmer_merges_81-scaffolds.fa ./Tribolium3kb_2_prinseq_good_36G8.fastq > ./Alignments2/Kmer_merges_81-scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai
# #
# # ~/bwa/bwa sampe ./Kmer_merges_81-scaffolds.fa ./Alignments2/Kmer_merges_81-scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai ./Alignments2/Kmer_merges_81-scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai ./Tribolium3kb_1_prinseq_good_P7uO.fastq ./Tribolium3kb_2_prinseq_good_36G8.fastq | samtools view -Shu -@ 4 - | samtools sort -@ 4 - ./Alignments2/Kmer_merges_81-scaffolds/Kmer_merges_81_scaff_3kb.bwa.sorted
# #
# # ~/samtools-0.1.19/samtools index ./Alignments2/Kmer_merges_81-scaffolds/Kmer_merges_81_scaff_3kb.bwa.sorted.bam
# #####################################################
# ################# gapped align reads to ref ################
# #####################################################
# cd ~/tca_ref_chrLG_all_to_Kmer_merges_81-scaffolds
# mkdir -p ./Alignments_gap/tcas_4.0_scaffolds
# ~/bwa/bwa index tcas.scaffolds.fasta
# ~/bwa/bwa aln -o 3 -t 4 ./tcas.scaffolds.fasta ./Tribolium3kb_1_prinseq_good_P7uO.fastq > ./Alignments_gap/tcas_4.0_scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai
# ~/bwa/bwa aln -o 3 -t 4 ./tcas.scaffolds.fasta ./Tribolium3kb_2_prinseq_good_36G8.fastq > ./Alignments_gap/tcas_4.0_scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai
# ~/bwa/bwa sampe ./tcas.scaffolds.fasta ./Alignments_gap/tcas_4.0_scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai ./Alignments_gap/tcas_4.0_scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai ./Tribolium3kb_1_prinseq_good_P7uO.fastq ./Tribolium3kb_2_prinseq_good_36G8.fastq | samtools view -Shu -@ 4 - | samtools sort -@ 4 - ./Alignments_gap/tcas_4.0_scaffolds/tcas_4.0_scaff_3kb.bwa.sorted
# ~/samtools-0.1.19/samtools index ./Alignments_gap/tcas_4.0_scaffolds/tcas_4.0_scaff_3kb.bwa.sorted.bam
# #####################################################
# ################# gapped lign reads to slave ##############
# #####################################################
# mkdir -p ./Alignments_gap/Kmer_merges_81-scaffolds
# ~/bwa/bwa index Kmer_merges_81-scaffolds.fa
# ~/bwa/bwa aln -o 3 -t 4 ./Kmer_merges_81-scaffolds.fa ./Tribolium3kb_1_prinseq_good_P7uO.fastq > ./Alignments_gap/Kmer_merges_81-scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai
# ~/bwa/bwa aln -o 3 -t 4 ./Kmer_merges_81-scaffolds.fa ./Tribolium3kb_2_prinseq_good_36G8.fastq > ./Alignments_gap/Kmer_merges_81-scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai
# ~/bwa/bwa sampe ./Kmer_merges_81-scaffolds.fa ./Alignments_gap/Kmer_merges_81-scaffolds/Tribolium3kb_1_prinseq_good_P7uO.sai ./Alignments_gap/Kmer_merges_81-scaffolds/Tribolium3kb_2_prinseq_good_36G8.sai ./Tribolium3kb_1_prinseq_good_P7uO.fastq ./Tribolium3kb_2_prinseq_good_36G8.fastq | samtools view -Shu -@ 4 - | samtools sort -@ 4 - ./Alignments_gap/Kmer_merges_81-scaffolds/Kmer_merges_81_scaff_3kb.bwa.sorted
# ~/samtools-0.1.19/samtools index ./Alignments_gap/Kmer_merges_81-scaffolds/Kmer_merges_81_scaff_3kb.bwa.sorted.bam