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
@@ -63,10 +63,10 @@ $ for x in Mov10_oe_1.subset.fq Mov10_oe_2.subset.fq Mov10_oe_3.subset.fq
63
63
64
64
> **We don't explicitly see this, but the variable has been defined as `x=Mov10_oe_1.subset.fq`.**
65
65
66
-
2. Next, all of the commands in the body of the loop (between the `do` and `done`) are executed. Usually, the commands placed here will be using the temporary variable as input. **Remember, if you are using the value stored in the variable you need to use $ to reference it!** In the example, we are running two commands:
66
+
2. Next, all of the commands in the body of the loop (between the `do` and `done`) are executed. Usually, the commands placed here will be using the temporary variable as input. **Remember, if you are using the value stored in the variable you need to use ${} to reference it!** In the example, we are running two commands:
67
67
68
-
* `echo $x`: print out the value stored in `x`
69
-
* `wc -l $x`: count/report the number of lines in `x`
68
+
* `echo ${x}`: print out the value stored in `x`
69
+
* `wc -l ${x}`: count/report the number of lines in `x`
70
70
71
71
3. Once those two commands are complete, the temporary variable is assigned a new value. It now takes the value of the second item in the list.
72
72
@@ -102,8 +102,8 @@ Let's rewrite the for loop above using a more meaningful variable name and using
102
102
```bash
103
103
$ forfilein Mov10*.fq
104
104
do
105
-
echo$file
106
-
wc -l $file
105
+
echo${file}
106
+
wc -l ${file}
107
107
done
108
108
```
109
109
@@ -178,28 +178,27 @@ For each file that we process we can use `basename` to create a prefix from the
178
178
```bash
179
179
do
180
180
# create a prefix for all output files
181
-
samplename=`basename $filename .subset.fq`
181
+
samplename=`basename ${filename} .subset.fq`
182
182
```
183
183
184
184
Now we execute the command required to dump the bad reads to file, but first start with an `echo` statement to keep the user informed. We will use `grep` to find all the bad reads (in our case, bad reads are defined as those with 10 consecutive N's), and then extract the four lines associated with each sequence read and write them to a file. Our output file is named using the `samplename` variable we created earlier in the loop. We will also add a path to redirect output to the `badreads` directory.
>#### Why are we using curly brackets with the variable name?
195
-
> When we append a variable to some other free text, we need shell to know where our variable name ends. By encapsulating the variable name in curly brackets we are letting shell know that everything inside it is the variable name. This way when we reference it, shell knows to print the variable `$samplename` and not to look for a variable called `$samplename_badreads.fq`.
194
+
> Reminder: When we append a variable to some other free text, we need shell to know where our variable name ends. By encapsulating the variable name in curly brackets we are letting shell know that everything inside it is the variable name. This way when we reference it, shell knows to print the variable `samplename` and not to look for a variable called `samplename_badreads.fq`.
196
195
197
196
198
197
We'll also count the number of identified bad reads using the count flag of `grep`, `-c`, which will return the number of matches rather than the actual matching lines. Here, we also use a new `grep` flag `-H`; this will report the filename along with the count value. This is useful because we are writing this information to a running log summary file, so rather than just reporting a count value we also know which file it is associated with.
199
198
200
199
```bash
201
200
# grab the number of bad reads and write it to a summary file
0 commit comments