You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The prompt should sit there a little bit, and then it should look like nothing
204
-
happened. But type `ls`. You should see a new file called `bad_reads.txt`.
190
+
Type `ls`. You should see a new file called `metadata.txt`.
205
191
206
192
We can check the number of lines in our new file using a command called `wc`.
207
193
`wc` stands for **word count**. This command counts the number of words, lines, and characters
208
-
in a file. The FASTQ file may change over time, so given the potential for updates,
209
-
make sure your file matches your instructor's output.
210
-
211
-
As of Sept. 2020, wc gives the following output:
194
+
in a file.
212
195
213
196
```bash
214
-
$ wc bad_reads.txt
197
+
$ wc metadata.txt
215
198
```
216
199
217
200
```output
218
-
802 1338 24012 bad_reads.txt
201
+
1 31 228 metadata.txt
219
202
```
220
203
221
204
This will tell us the number of lines, words and characters in the file. If we
222
205
want only the number of lines, we can use the `-l` flag for `lines`.
223
206
224
207
```bash
225
-
$ wc -l bad_reads.txt
208
+
$ wc -l metadata.txt
226
209
```
227
210
228
211
```output
229
-
802 bad_reads.txt
212
+
1 metadata.txt
230
213
```
231
214
232
215
::::::::::::::::::::::::::::::::::::::: challenge
233
216
234
217
## Exercise
235
218
236
-
How many sequences are there in `SRR098026.fastq`? Remember that every sequence is formed by four lines.
219
+
How many sequences are there in `SraRunTable.txt`? Remember that every sequence is formed by four lines.
237
220
238
221
::::::::::::::: solution
239
222
240
223
## Solution
241
224
242
225
```bash
243
-
$ wc -l SRR098026.fastq
226
+
$ wc -l SraRunTable.txt
244
227
```
245
228
246
229
```output
247
-
996
248
-
```
249
-
250
-
Now you can divide this number by four to get the number of sequences in your fastq file.
251
-
252
-
This can be done using [shell integer arithmetic](https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html)
253
-
254
-
```bash
255
-
$ echo$((996/4))
256
-
```
257
-
258
-
Note, this will do integer division - if you need floating point arithmetic you can use [bc - an arbitrary precision calculator](https://www.gnu.org/software/bc/manual/html_mono/bc.html)
259
-
260
-
261
-
```bash
262
-
$ echo"996/4"| bc
263
-
```
264
-
265
-
```output
266
-
249
230
+
37 SraRunTable.txt
267
231
```
268
232
269
233
:::::::::::::::::::::::::
@@ -274,98 +238,76 @@ $ echo "996/4" | bc
274
238
275
239
## Exercise
276
240
277
-
How many sequences in `SRR098026.fastq` contain at least 3 consecutive Ns?
241
+
How many paired-end read samples are there in `SraRunTable.txt`? These samples will have metadata that contains the keyword `PAIRED`.
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
321
-
because the second file we searched (`SRR097977.fastq`) does not contain any lines that match our
322
-
search sequence. So our file was overwritten and is now empty.
281
+
Notice that the paired-end samples are no longer present in the output `metadata.txt` file. This is
282
+
because the our second search overwrote the results of the first search.
323
283
324
-
We can avoid overwriting our files by using the command `>>`. `>>` is known as the "append redirect" and will
325
-
append new output to the end of a file, rather than overwriting it.
284
+
We can avoid overwriting our files by using the command `>>`. `>>` is known as the "append redirect" and will append new output to the end of a file, rather than overwriting it.
The `-v` option in the second `grep` search stands for `--invert-match` meaning `grep` will now only display the
461
-
lines which do not match the searched pattern, in this case `'^--'`. The caret (`^`) is an **anchoring**
462
-
character matching the beginning of the line, and the pattern has to be enclose by single quotes so `grep` does
463
-
not interpret the pattern as an extended option (starting with --).
364
+
Notice that you now get the header line and the paired-end samples, because these do not match the
365
+
pattern `SINGLE`.
464
366
465
367
::::::::::::::::::::::::::::::::::::::::: callout
466
368
@@ -530,7 +432,7 @@ foo is abcEFG
530
432
Let's write a for loop to show us the first two lines of the fastq files we downloaded earlier. You will notice the shell prompt changes from `$` to `>` and back again as we were typing in our loop. The second prompt, `>`, is different to remind us that we haven't finished typing a complete command yet. A semicolon, `;`, can be used to separate two commands written on a single line.
Copy file name to clipboardExpand all lines: 05-writing-scripts.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,6 +152,8 @@ $ nano bad-reads-script.sh
152
152
153
153
Bad reads have a lot of N's, so we're going to look for `NNNNNNNNNN` with `grep`. We want the whole FASTQ record, so we're also going to get the one line above the sequence and the two lines below. We also want to look in all the files that end with `.fastq`, so we're going to use the `*` wildcard.
154
154
155
+
`--` is the default action for `grep` to separate groups of lines matching the pattern. The caret (`^`) is an **anchoring** character matching the beginning of the line, and the pattern has to be enclosed by single quotes so `grep` does not interpret the pattern as an extended option (starting with --).
0 commit comments