-
Notifications
You must be signed in to change notification settings - Fork 0
/
interleave_fastq
53 lines (51 loc) · 1.01 KB
/
interleave_fastq
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
#!/bin/bash
if [[ "$1" == "-h" ]]; then
echo "interleave_fastq [-h] filename.1.fq[.gz] filename.2.fq[.gz]"
exit 0
elif [ -z $1 ]; then
echo "interleave_fastq [-h] filename.1.fq[.gz] filename.2.fq[.gz]"
exit 1
fi
if [[ $1 =~ \.gz$ ]]; then
zcat $1 | awk -v second=$2 '
{
if (NR % 4 == 1){
file1 = $0;
if ("zcat "second | getline ){
file2 = $0;
}
} else if (NR %4 == 0){
file1 = file1"\n"$0;
print file1;
if ("zcat "second | getline ){
file2 = file2"\n"$0;
print file2;
}
} else {
file1 = file1"\n"$0;
if ("zcat "second | getline ){
file2 = file2"\n"$0;
}
}}' | gzip
else
awk -v second=$2 '
{
if (NR % 4 == 1){
file1 = $0;
if (getline < second){
file2 = $0;
}
} else if (NR %4 == 0){
file1 = file1"\n"$0;
print file1;
if (getline < second){
file2 = file2"\n"$0;
print file2;
}
} else {
file1 = file1"\n"$0;
if (getline < second){
file2 = file2"\n"$0;
}
}}' $1
fi