-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenameInputFastq.sh
More file actions
executable file
·49 lines (36 loc) · 1.45 KB
/
RenameInputFastq.sh
File metadata and controls
executable file
·49 lines (36 loc) · 1.45 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
#!/bin/bash
#RenameInputFastq.sh
# This script is required because data coming from different facilities tends to have differently formatted filenames
# thus it is difficult to construct code which will work on all kinds of file names
# and we decided to adopt a convention:
# our workflow looks for _read?.fq or _read?.fastq or _read?.fq.gz or _read?.fastq.gz
# this script will rename files to gave _read?.fq or _read?.fq.gz
# first variable = input folder
# second variable = read name ending pattern;
# third variable = left read (1) or right read (2)
#for example: H7FCKCCXX-6-IDX706_S8_L006_R1_001_1_sequence.txt.gz has ending pattern _R1_001_1_sequence.txt.gz and $3=1
#for example: H7FCKCCXX-6-IDX706_S8_L006_R2_001_2_sequence.txt.gz has ending pattern _R2_001_2_sequence.txt.gz and $3=2
#
set -x
umask 0027
InputFolder=$1
EndingPattern=$2
ReadSide=$3
set +x; echo -e "\n\n####### loop for renaming fastq files #######\n\n" >&2; set -x;
for fastq in ${InputFolder}/*${EndingPattern}
do
#find the file name base
file_name_base=`basename $fastq $EndingPattern`
# determine if this is fastq or fastq.gz
if [[ ( $fastq == *.fq ) || ( $fastq == *.fastq ) ]]
then
file_extension="fq"
elif [[ ( $fastq == *.gz ) ]]
then
file_extension="gz"
fi
OldName=`basename $fastq`
NewName=${file_name_base}_read${ReadSide}.fq.${file_extension}
echo "renaming $OldName into $NewName"
mv $fastq ${InputFolder}/${NewName}
done