Skip to content

Instantly share code, notes, and snippets.

@thanhleviet
Last active September 1, 2020 12:53
Show Gist options
  • Save thanhleviet/ef6a2f577a824c53fac97f4762aeea2e to your computer and use it in GitHub Desktop.
Save thanhleviet/ef6a2f577a824c53fac97f4762aeea2e to your computer and use it in GitHub Desktop.
Watch a folder, split fast5 into 150-file chunks and run guppy basecalling from a chunk list.
#!/usr/bin/env bash
# Author: Thanh Le Viet
# This script will split every consecutive fast5 files into a batch file list for basecalling with guppy
# It is used for "live" basecalling while the sequencing still running on another machine.
# Command: bash ./run_basecalling.sh
# summary_file="sequencing_summary_FAO15487_23198198.txt"
# Usage: run watch_and_basecalling.sh sequencing_summary_FAO15487_23198198.txt
# Note: each run has a different summary_file name.
summary_file=$1
#ROOT ONT
ONT=/home/prom/ont-software/ont-guppy-4.0.15/ont-guppy
while true; do
ls -tr $PWD/fast5/*.fast5 | split --lines=150 --numeric-suffixes=1 - rec_batch_
echo "Generated...."
wc -l rec_batch_*
echo "================================================="
batches=`ls -v rec_batch_*`
for b in $batches;
do
#echo "$b"
batch_folder="./fastq/${b}"
if [[ -d $batch_folder ]] && [[ -f "$batch_folder/sequencing_telemetry.js" ]]
then
echo "$b has been already basecalled"
else
items="x$(cat $b | wc -l)"
if [[ $items != "x150" ]] && [[ ! -f $summary_file ]]
then
echo "$b is not basecalled and fast5 files smaller than 150"
date
else
if [[ ! -f .lockbc ]]
then
echo "Start basecalling on $b"
echo "$b" > .lockbc
#Start guppy
"$ONT/bin/guppy_basecaller" \
--qscore_filtering \
--input_file_list $b \
-s "./fastq/${b}" \
-c "$ONT/data/dna_r9.4.1_450bps_hac.cfg" \
-x 'cuda:1,2,3,0' > "log_${b}.txt"
if [[ $? -eq 0 ]]
then
echo "Finished sucessfully $b"
rm .lockbc
else
echo "Basecalling for $b is failed"
fi
else
echo "Cannot start basecalling for $b. Please check .lockbc file"
fi
fi
fi
done
sleep 600
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment