forked from trustodia/HPC416S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-paired-reads.sh
65 lines (57 loc) · 1.81 KB
/
merge-paired-reads.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# script: merges two fastq paired-reads files into one file
# prerequisites:
#
# (1) Scenario: Paired-end forward and reverse reads, 2 files
#
# READ 1
# |-------------->
# 5' |-------------------------------------------------| 3'
# | | | | | | | | | | | | | | | | | | | | | | | |
# 3' |-------------------------------------------------| 5'
# <--------------|
# READ 2
#
# See "Example 5: sortmerna on forward-reverse paired-end
# reads (2 input files)" of the SortMeRNA User Manual (version 1.7
# and higher)
#
# Use merge-paired-reads.sh to interweave the reads from
# both files into a single file, where READ 1 will be
# directly followed by READ 2
#
# command: bash merge-paired-reads.sh file1.fastq file2.fastq outputfile.fastq
#
# Use the outputfile.fastq as input reads to SortMeRNA
#
# date: March 26, 2013
# contact: [email protected]
#
# check all files are given
if [ $# -lt 3 ]; then
echo "usage: $0 forward-reads.fastq reverse-reads.fastq merged-reads.fastq"
exit 2
elif [ $# -gt 3 ]; then
echo "usage: $0 forward-reads.fastq reverse-reads.fastq merged-reads.fastq"
exit 2
fi
# quickly check file is not fasta
sig1="$(head -c 1 $1)"
sig2="$(head -c 1 $2)"
if [ "$sig1" == ">" ]; then
echo " Warning: $1 seems to be in fasta format (this script is for fastq reads only)"
fi
if [ "$sig2" == ">" ]; then
echo " Warning: $2 seems to be in fasta format (this script is for fastq reads only)"
fi
# merge the files
echo " Processing $1 .."
perl -pe 's/\n/\t/ if $. %4' $1 > $3.READS1
echo " Processing $2 .."
perl -pe 's/\n/\t/ if $. %4' $2 > $3.READS2
echo " Interleaving $1 and $2 .."
paste -d '\n' $3.READS1 $3.READS2 | tr "\t" "\n" > $3
rm $3.READS1 $3.READS2
echo " Done.
"