Skip to content

Commit 7082178

Browse files
committed
update 04-redirection.md
1 parent 12d2eda commit 7082178

1 file changed

Lines changed: 49 additions & 5 deletions

File tree

_episodes/04-redirection.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ CNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
8686

8787
> ## Exercise
8888
>
89-
> 1) Search for the sequence GNATNACCACTTCC in the SRR098026.fastq.
89+
> 1) Search for the sequence `GNATNACCACTTCC` in the `SRR098026.fastq` file.
9090
> Have your search return all matching lines and the name (or identifier) for each sequence
9191
> that contains a match.
9292
>
93-
> 2) Search for the sequence AAGTT in both FASTQ files.
93+
> 2) Search for the sequence `AAGTT` in both FASTQ files.
9494
> Have your search return all matching lines and the name (or identifier) for each sequence
9595
> that contains a match.
9696
>
@@ -148,6 +148,11 @@ $ wc bad_reads.txt
148148
~~~
149149
{: .bash}
150150

151+
~~~
152+
537 1073 23217 bad_reads.txt
153+
~~~
154+
{: .output}
155+
151156
This will tell us the number of lines, words and characters in the file. If we
152157
want only the number of lines, we can use the `-l` flag for `lines`.
153158

@@ -156,12 +161,17 @@ $ wc -l bad_reads.txt
156161
~~~
157162
{: .bash}
158163

164+
~~~
165+
537 bad_reads.txt
166+
~~~
167+
{: .output}
168+
159169
Because we asked `grep` for all four lines of each FASTQ record, we need to divide the output by
160170
four to get the number of sequences that match our search pattern.
161171

162172
> ## Exercise
163173
>
164-
> How many sequences in SRR098026.fastq contain at least 3 consecutive Ns?
174+
> How many sequences in `SRR098026.fastq` contain at least 3 consecutive Ns?
165175
>
166176
>> ## Solution
167177
>> We can do it in one step, using the `|` pipe:
@@ -172,7 +182,7 @@ four to get the number of sequences that match our search pattern.
172182
>> {: .bash}
173183
>>
174184
>> ~~~
175-
>> 250
185+
>> 249
176186
>> ~~~
177187
>> {: .output}
178188
>>
@@ -188,13 +198,27 @@ of your kid's first birthday party, you also want to avoid overwriting your data
188198
~~~
189199
$ grep -B1 -A2 NNNNNNNNNN SRR098026.fastq > bad_reads.txt
190200
$ wc -l bad_reads.txt
201+
~~~
202+
{: .bash}
203+
204+
~~~
205+
537 bad_reads.txt
206+
~~~
207+
{: .output}
208+
209+
~~~
191210
$ grep -B1 -A2 NNNNNNNNNN SRR097977.fastq > bad_reads.txt
192211
$ wc -l bad_reads.txt
193212
~~~
194213
{: .bash}
195214
215+
~~~
216+
0 bad_reads.txt
217+
~~~
218+
{: .output}
219+
196220
Here, the output of our second call to `wc` shows that we no longer have any lines in our bad_reads.txt file. This is
197-
because the second file we searched (SRR097977.fastq) does not contain any lines that match our
221+
because the second file we searched (`SRR097977.fastq`) does not contain any lines that match our
198222
search sequence. So our file was overwritten and is now empty.
199223
200224
We can avoid overwriting our files by using the command `>>`. `>>` is known as the "append redirect" and will
@@ -203,20 +227,40 @@ append new output to the end of a file, rather than overwriting it.
203227
~~~
204228
$ grep -B1 -A2 NNNNNNNNNN SRR098026.fastq > bad_reads.txt
205229
$ wc -l bad_reads.txt
230+
~~~
231+
{: .bash}
232+
233+
~~~
234+
537 bad_reads.txt
235+
~~~
236+
{: .output}
237+
238+
~~~
206239
$ grep -B1 -A2 NNNNNNNNNN SRR097977.fastq >> bad_reads.txt
207240
$ wc -l bad_reads.txt
208241
~~~
209242
{: .bash}
210243
244+
~~~
245+
537 bad_reads.txt
246+
~~~
247+
{: .output}
248+
211249
The output of our second call to `wc` shows that we have not overwritten our original data.
212250
213251
We can also do this with a single line of code by using a wildcard.
214252
215253
~~~
216254
$ grep -B1 -A2 NNNNNNNNNN *.fastq > bad_reads.txt
255+
$ wc -l bad_reads.txt
217256
~~~
218257
{: .bash}
219258
259+
~~~
260+
537 bad_reads.txt
261+
~~~
262+
{: .output}
263+
220264
> ## File extensions - part 2
221265
>
222266
> This is where we would have trouble if we were naming our output file with a `.fastq` extension.

0 commit comments

Comments
 (0)