Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding gc-percentage calculation and reporting to stdout #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs: # Define jobs for the workflow
# Save the expected output to a file
echo "Processing FASTQ file: ./data/sample.fastq" > expected_output.txt
echo "Number of reads in ./data/sample.fastq: 2" >> expected_output.txt
echo "GC Percent in ./data/sample.fastq: 0.5" >> expected_output.txt

# Capture the actual output of the script and save it to a file
./bin/fastq-peek.sh ./data/sample.fastq > actual_output.txt
Expand Down
14 changes: 13 additions & 1 deletion bin/fastq-peek.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Holly Halstead
# Western-WFD-2024 Week 01 Exercise

# Get the directory of the current script
SCRIPT_DIR=$(dirname "$0")

Expand All @@ -24,5 +27,14 @@ echo "Processing FASTQ file: $FASTQ_FILE"
LINE_COUNT=$(wc -l < "$FASTQ_FILE")
## Calculate the number of reads (4 lines per read)
READ_COUNT=$((LINE_COUNT / 4))
## Count GC in FASTQ file
GC_COUNT=$(awk '(NR%4==2) {gsub(/[ATnNat]/,"");N+=length($0);}END{print N;}' "$FASTQ_FILE")
## Count total number of bases in FASTQ file
TOTAL_BASE_COUNT=$(awk 'NR%4==2 {sum += length($0)} END {print sum}' "$FASTQ_FILE")
## Calculate GC percent in FASTQ file
GC_PERCENT=$(awk '(NR%4==2) {N1+=length($0);gsub(/[AT]/,"");N2+=length($0);}END{print N2/N1;}' "$FASTQ_FILE")

# Print results to terminal
echo -e "Number of reads in $FASTQ_FILE: $READ_COUNT\nGC Percent in $FASTQ_FILE: $GC_PERCENT"

echo "Number of reads in $FASTQ_FILE: $READ_COUNT"
exit 0
Loading