Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
UNIX command line
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CAN
UNIX command line
Commits
9fd8ff32
Commit
9fd8ff32
authored
2 weeks ago
by
Gilquin
Browse files
Options
Downloads
Patches
Plain Diff
fix: harmonize filenames in awk exercises
parent
b5bd764b
No related branches found
No related tags found
1 merge request
!2
fix: correct some errors
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
9_batch_processing.Rmd
+7
-7
7 additions, 7 deletions
9_batch_processing.Rmd
with
7 additions
and
7 deletions
9_batch_processing.Rmd
+
7
−
7
View file @
9fd8ff32
...
@@ -184,13 +184,13 @@ awk -vFS='\t' -vOFS='' '{print $1 "\n";}' two_column_sample_tab.txt > seq_name.t
...
@@ -184,13 +184,13 @@ awk -vFS='\t' -vOFS='' '{print $1 "\n";}' two_column_sample_tab.txt > seq_name.t
Convert a multiline fasta file into a single line fasta file
Convert a multiline fasta file into a single line fasta file
```sh
```sh
awk '!/^>/ { printf "%s", $0; n = "\n" } /^>/ { print n $0; n = "" } END { printf "%s", n }' sample.fa > sample
1
_singleline.fa
awk '!/^>/ { printf "%s", $0; n = "\n" } /^>/ { print n $0; n = "" } END { printf "%s", n }' sample.fa > sample_singleline.fa
```
```
Convert fasta sequences to uppercase
Convert fasta sequences to uppercase
```sh
```sh
awk '/^>/ {print($0)}; /^[^>]/ {print(toupper($0))}'
fi
le.fa
sta
>
fi
le_upper.fa
sta
awk '/^>/ {print($0)}; /^[^>]/ {print(toupper($0))}'
samp
le.fa >
samp
le_upper.fa
```
```
Modify this command to only get a list of sequence names in a fasta file un lowercase
Modify this command to only get a list of sequence names in a fasta file un lowercase
...
@@ -198,7 +198,7 @@ Modify this command to only get a list of sequence names in a fasta file un lowe
...
@@ -198,7 +198,7 @@ Modify this command to only get a list of sequence names in a fasta file un lowe
<details><summary>Solution</summary>
<details><summary>Solution</summary>
<p>
<p>
```sh
```sh
awk '/[^>]/ {print(tolower($0))}'
fi
le.fa
sta
> seq_name_lower.txt
awk '/[^>]/ {print(tolower($0))}'
samp
le.fa > seq_name_lower.txt
```
```
</p>
</p>
</details>
</details>
...
@@ -206,19 +206,19 @@ awk '/[^>]/ {print(tolower($0))}' file.fasta > seq_name_lower.txt
...
@@ -206,19 +206,19 @@ awk '/[^>]/ {print(tolower($0))}' file.fasta > seq_name_lower.txt
Return a list of sequence_id sequence_length from a fasta file
Return a list of sequence_id sequence_length from a fasta file
```sh
```sh
awk 'BEGIN {OFS = "\n"}; /^>/ {print(substr(sequence_id, 2)" "sequence_length); sequence_length = 0; sequence_id = $0}; /^[^>]/ {sequence_length += length($0)}; END {print(substr(sequence_id, 2)" "sequence_length)}'
fi
le.fa
sta
awk 'BEGIN {OFS = "\n"}; /^>/ {print(substr(sequence_id, 2)" "sequence_length); sequence_length = 0; sequence_id = $0}; /^[^>]/ {sequence_length += length($0)}; END {print(substr(sequence_id, 2)" "sequence_length)}'
samp
le.fa
```
```
Count the number of bases in a fastq.gz file
Count the number of bases in a fastq.gz file
```sh
```sh
(gzip -dc $0) | awk 'NR%4 == 2 {basenumber += length($0)} END {print basenumber}'
sample.fq.gz |
(gzip -dc $0) | awk 'NR%4 == 2 {basenumber += length($0)} END {print basenumber}'
```
```
Only
read with more than 20bp from a fastq
Extract the
read
s
with more than 20bp from a fastq
```sh
```sh
awk 'BEGIN {OFS = "\n"} {header = $0 ; getline seq ; getline qheader ; getline qseq ; if (length(seq) >= 20){print header, seq, qheader, qseq}}' < input.f
ast
q > output.f
ast
q
awk 'BEGIN {OFS = "\n"} {header = $0 ; getline seq ; getline qheader ; getline qseq ; if (length(seq) >= 20){print header, seq, qheader, qseq}}' < input.fq > output.fq
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment