-
Notifications
You must be signed in to change notification settings - Fork 1
/
recover_mate.sh
executable file
·139 lines (134 loc) · 1.89 KB
/
recover_mate.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
read1=$1
read2=$2
sample=`basename $read1 | sed -e 's/_1.fq/ /' |awk '{print $1}'`
outFile=`echo $read1 | sed 's/_1.fq/_2.fq/'`
echo $sample, $outFile
R2_type=`echo $read2 | awk '{if(match($1,".gz") > 0 ){print "gzfastq"}else{print "fastq"}}'`
if [[ $R2_type = "gzfastq" ]]
then
zcat $read2 | awk -v NAME=$read1 -v sample=$sample -v out=$outFile '
BEGIN{
sample="@"sample
cpt=1
while (getline < NAME > 0){
if(cpt==1){
tab[$1]=1
}
if (cpt==4){cpt=0}
cpt ++
}
name=""
cpt=1
}{
if (cpt==1){
if (name!=""){
print nameTot >> out
print seq >> out
print name2 >> out
print qual >> out
name=""
seq=""
name2=""
qual=""
}
name=$1
nameTot=$0
}else{
if (tab[name]==1){
if (seq==""){
seq=$0
}else{
if (name2==""){
name2=$0
}else{
if (qual==""){
qual=$0
}
}
}
}else{
name=""
}
}
if (cpt==4){cpt=0}
cpt ++
}END {
if (name!=""){
print nameTot >> out
print seq >> out
print name2 >> out
print qual >> out
name=""
seq=""
name2=""
qual=""
}
}
'
else
cat $read2 | awk -v NAME=$read1 -v sample=$sample -v out=$outFile '
BEGIN{
sample="@"sample
cpt=1
while (getline < NAME > 0){
if(cpt==1){
tab[$1]=1
}
if (cpt==4){cpt=0}
cpt ++
}
name=""
cpt=1
}{
if (cpt==1){
if (name!=""){
print nameTot >> out
print seq >> out
print name2 >> out
print qual >> out
name=""
seq=""
name2=""
qual=""
}
name=$1
nameTot=$0
}else{
if (tab[name]==1){
if (seq==""){
seq=$0
}else{
if (name2==""){
name2=$0
}else{
if (qual==""){
qual=$0
}
}
}
}else{
name=""
}
}
if (cpt==4){cpt=0}
cpt ++
}END {
if (name!=""){
print nameTot >> out
print seq >> out
print name2 >> out
print qual >> out
name=""
seq=""
name2=""
qual=""
}
}
'
fi
if [[ $R2_type = "fastq" ]]
then
gzip $read2
fi
gzip $read1 $outFile