Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Last active December 19, 2015 02:39
Show Gist options
  • Save CnrLwlss/5884591 to your computer and use it in GitHub Desktop.
Save CnrLwlss/5884591 to your computer and use it in GitHub Desktop.
Aligning yeast sequences to a reference genome.
#!/bin/bash
echo Making indices...
# Set up path to include bowtie2 and samtools
export PATH=$PATH:/home/username/bowtie2-2.1.0:/home/username/samtools:/home/username/samtools/bcftools:/home/username/samtools/misc
# Generate an index file from the reference genome
bowtie2-build reference_SGD/S288C_reference_genome_R64-1-1_20110203/S288C_reference_sequence_R64-1-1_20110203.fsa indices/SGD_S288C
roots=(
SN7640178_10172_8183
SN7640178_10173_8265
SN7640178_10174_8266
SN7640178_10175_8267
)
# Paired-end alignment for each sample, output to .sam files
for x in ${roots[@]}; do
echo Align reads ${x}
bowtie2-align -x indices/SGD_S288C -1 data/"$x"_1_sequence.fq -2 data/"$x"_2_sequence.fq -S alignments/"$x".sam -p 12 --end-to-end
done
# Convert each .sam file to .bam file, sort and index each file
for x in ${roots[@]}; do
(
echo Convert .sam alignments to .bam, sort and index ${x}
samtools view -bS alignments/"$x".sam >alignments/"$x".bam
samtools sort alignments/"$x".bam alignments/"$x"_sorted.bam
samtools index alignments/"$x"_sorted.bam.bam indices/"$x"_sorted.bai
)&
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment