Inflate gzipped fastq files

Fastq files are commonly zipped after they go through the de-multiplexing steps from sequencers.  For analysis programs that do not support those zipped files, bioinformatician needs to inflate those files first. Suppose we only want to inflate a certain zipped fastq files stored on a server directory to a user directory, the following bash script may help.

#!/bin/bash
PROJECT_NAME_LOW=1			# we only work on PROJECT_NAME-1-10
PROJECT_NAME_HIGH=10
OUT_DIR=/users/me/projects/PROJECT_NAME/reads

for f in /server_home/PROJECT_NAME/reads_origin/*.gz;
do
 STEM=$(basename "${f}" .gz)

 index=$(echo $STEM|tr "_" "\n")
 sample=$(echo $index|cut -f 1 -d " ")
 sample_id=${sample[@]#PROJECT_NAME-}		# remove PROJECT_NAME-
 
 if [ "$sample_id" -ge $PROJECT_NAME_LOW ] && [ "$sample_id" -le $PROJECT_NAME_HIGH ]
 then
     output=$OUT_DIR/$STEM
     echo Inflating $STEM
     gunzip -c $f > $output

 fi
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s