-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign_fasta.sh
More file actions
executable file
·50 lines (38 loc) · 1.21 KB
/
Copy pathalign_fasta.sh
File metadata and controls
executable file
·50 lines (38 loc) · 1.21 KB
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
#!/usr/bin/env bash
# align_fasta.sh
### bash script for aligning a fasta file to a reference genome.
### will output a .bam and a .bed file of alignment
### Use like so:
# ./align_fasta.sh seqs.fa ref_genome output_dir output_prefix
# Ben Ober-Reynolds
# Check that the proper number of parameters were given
if [ "$#" -ne 4 ]; then
echo " bash script for aligning a fasta file."
echo " Output is bam and bed file of original fasta sequences"
echo " Usage:"
echo " align_fasta.sh seqs.fa ref_genome output_dir output_prefix"
exit
fi
# input parameters
seqs=$1
ref_genome=$2
output_dir=$3
output_prefix=$4
# bowtie2 settings:
n_cores="8"
# working filenames:
sam_file="$output_dir$output_prefix.sam"
unsorted_bam_file="$output_dir$output_prefix.bam"
unsorted_bed_file="$output_dir$output_prefix.bed"
# align
echo ""
echo "Aligning with bowtie2..."
echo ""
# Redirect bowtie2 metrics (normally stderr) to stdout for better wrapper script handling:
bowtie2 -f --very-sensitive -p $n_cores -x $ref_genome -U $seqs -S $sam_file 2>&1
# Make bam file:
samtools view -b -S -o $unsorted_bam_file $sam_file 2>&1
# Make bed file:
bedtools bamtobed -i $unsorted_bam_file > $unsorted_bed_file
# clean up intermediate files:
rm $sam_file