Created
February 1, 2016 15:00
-
-
Save anpefi/fdb42713fa7e58d51769 to your computer and use it in GitHub Desktop.
A script to convert a gzipped FASTQ file in Solexa 1.3+ quality offset (QUAL+64 encoding) to a FASTQ with Phred/Sanger offset (QUAL+33 encoding).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
#$ -j y | |
#$ -v LD_LIBRARY_PATH | |
# | |
####################################################### | |
# rEncodeFASTQ.sh | |
# | |
# A script to convert a gzipped FASTQ file in Solexa 1.3+ | |
# quality offset (QUAL+64 encoding) to a FASTQ with | |
# Phred/Sanger offset (QUAL+33 encoding). | |
# | |
# agalma requires unzipped QUAL+33 datasets | |
# | |
# requires fastqSol2Phred | |
# (https://github.com/RobersonLab/fastqSol2Phred.git) | |
# | |
####################################################### | |
# PARSING THE ARGUMENTS | |
usage() { echo "Usage: $0 [-o OUTDIR=.] [-s SUFFIX] [.fq.gz files]" ; exit 1; } | |
while getopts ":ho:s:" opt; do | |
case $opt in | |
o) | |
OUTDIR=$OPTARG | |
;; | |
s) | |
SUFFIX=$OPTARG | |
;; | |
h) | |
usage | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" | |
usage | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
shift $(( OPTIND - 1 )) | |
# Defining defaults if arguments were not parsed | |
if [ -z "$OUTDIR" ]; then OUTDIR=. ; fi | |
if [ -z "$SUFFIX" ]; then SUFFIX=_Q33.fq ; fi | |
# iterate over files | |
for i in "$@" | |
do | |
if [ -f $i ]; | |
then | |
#catch the name of the file without the path before the first dot (.fq.gz) | |
F=$(echo $i | rev | cut -d'/' -f1 | rev | cut -d'.' -f1) | |
# Check if the file was previously recoded, if not then do it! | |
if [ ! -f $OUTDIR/$F$SUFFIX ]; | |
then | |
echo "recoding $i to Phred33 in $OUTDIR/$F$SUFFIX" | |
#Execute the converter | |
fastqSol2Phred <(gunzip -c $i) $OUTDIR/$F$SUFFIX | |
gzip $OUTDIR/$F$SUFFIX | |
else | |
echo "$OUTDIR/$F$SUFFIX already exists! Next one, please!" | |
fi; | |
else | |
echo "$i is not a file! Skipped!" | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment