Here's a Linux bash script that will run the Python script on all .npy files in a directory, processing each one sequentially:
#!/bin/bash
# gene_coverage_batch.sh - Process all .npy files in a directory
# Check if Python script exists
PYTHON_SCRIPT="gene_coverage.py"
if [ ! -f "$PYTHON_SCRIPT" ]; then
echo "Error: Python script $PYTHON_SCRIPT not found in current directory"
exit 1
fi
# Directory containing .npy files (default to current directory)
NPY_DIR="${1:-.}"
# Check if directory exists
if [ ! -d "$NPY_DIR" ]; then
echo "Error: Directory $NPY_DIR does not exist"
exit 1
fi
# Process each .npy file
echo "Processing .npy files in $NPY_DIR..."
for npy_file in "$NPY_DIR"/*.npy; do
if [ -f "$npy_file" ]; then
echo "Processing $npy_file..."
python3 "$PYTHON_SCRIPT" "$npy_file"
echo "----------------------------------------"
fi
done
echo "Batch processing complete!"
How to Use This Script:
- Save this as
gene_coverage_batch.sh
- Make it executable:
chmod +x gene_coverage_batch.sh
- Run it:
# Process current directory
./gene_coverage_batch.sh
# Process specific directory
./gene_coverage_batch.sh /path/to/npy/files
Features:
- Automatic detection of all
.npy files in the specified directory (or current directory if none specified)
- Error handling for missing Python script or invalid directory
- Progress reporting showing which file is being processed
- Preserves the original behavior of the Python script (including default output naming)
Alternative Version with Parallel Processing:
If you have many files and want to process them in parallel (faster on multi-core systems):
#!/bin/bash
# gene_coverage_parallel.sh - Process all .npy files in parallel
PYTHON_SCRIPT="gene_coverage.py"
NPY_DIR="${1:-.}"
# Check requirements
if [ ! -f "$PYTHON_SCRIPT" ]; then
echo "Error: Python script $PYTHON_SCRIPT not found"
exit 1
fi
if [ ! -d "$NPY_DIR" ]; then
echo "Error: Directory $NPY_DIR does not exist"
exit 1
fi
# Get number of CPU cores
N_CORES=$(nproc)
echo "Processing .npy files in $NPY_DIR using $N_CORES parallel jobs..."
find "$NPY_DIR" -maxdepth 1 -name "*.npy" -print0 | xargs -0 -P "$N_CORES" -I {} python3 "$PYTHON_SCRIPT" {}
echo "Parallel processing complete!"
This parallel version will use all available CPU cores to process files simultaneously. Use it the same way as the sequential version.