Running Lastz (https://github.com/lastz/lastz) in parallel mode. This program is for single computer with multiple core processors.
parallelLastz is a Perl-based utility for running LASTZ sequence alignments in parallel. It is designed for large FASTA datasets where multiple target and query sequences need to be aligned efficiently while maintaining a resumable job manifest and detailed error reporting.
- 🚀 Run multiple LASTZ alignments in parallel
- 🧬 Supports multi-FASTA target and query files
- 📦 Automatically splits multi-FASTA targets into single-sequence temporary FASTA files
- ✂️ Supports query chunking based on a user-defined length
- ⚡ Control parallelism with
--jobs/-j - 🔄 Resume interrupted or incomplete runs
- 🔁 Retry failed LASTZ jobs
- 🧪 Dry-run mode for inspecting the planned jobs
- 📋 Maintains a job manifest for tracking execution
- 📝 Captures LASTZ stdout and stderr separately
- ❌ Reports the actual LASTZ error message instead of only an exit code
- 📊 Displays a compact progress indicator in non-verbose mode
- 🔍 Verbose mode for detailed execution information
- 🧹 Optional cleanup/wipe of previous results
- 🔤 Optional sequence unmasking
- 🛡️ Uses safe list-form command execution
The following software is required:
- Perl >= 5.20
- LASTZ
- Perl module
Parallel::ForkManager - Perl module
Bio::SeqIOfrom BioPerl
Using CPAN:
cpan Parallel::ForkManager Bio::SeqIOOr using CPAN Minus:
cpanm Parallel::ForkManager Bio::SeqIOCheck LASTZ:
lastz --versionClone the repository:
git clone https://github.com/jnarayan81/parallelLastz.git
cd parallelLastzMake the script executable:
chmod +x parallelLastz_v0.3.3.plTest the installation:
perl parallelLastz_v0.3.3.pl --helpperl parallelLastz_v0.3.3.pl \
-q query.fasta \
-t target.fasta \
-c conf \
-j 4 \
-l 100Where:
| Option | Description |
|---|---|
-q, --qfile |
Query FASTA file |
-t, --tfile |
Target FASTA file |
-c, --cfile |
LASTZ configuration file |
-j, --jobs |
Number of concurrent LASTZ jobs |
-l, --length |
Maximum query chunk length |
-w, --wipe |
Remove previous output before starting |
-r, --retry |
Number of retries for failed jobs |
-u, --unmask |
Convert lowercase sequence bases to uppercase |
-v, --verbose |
Display detailed execution information |
--resume |
Resume an existing run |
--dry-run |
Display planned jobs without executing LASTZ |
-o, --output |
Output directory |
-h, --help |
Display help |
The --jobs/-j option controls the maximum number of LASTZ processes running simultaneously.
For example:
-j 4allows up to four LASTZ jobs to run concurrently.
If there are eight alignment jobs:
Job 1 ─┐
Job 2 ─┤
Job 3 ─┤ Running
Job 4 ─┘
Job 5
Job 6
Job 7
Job 8
Waiting
As jobs finish, waiting jobs are started automatically.
The requested number of jobs cannot exceed the number of available CPUs.
A major feature of parallelLastz is automatic handling of multi-FASTA target files.
LASTZ expects a single sequence in the target position in the standard invocation. Therefore, if the target contains multiple sequences, parallelLastz first creates temporary single-record FASTA files.
For example:
target.fasta
├── chromosome_1
└── chromosome_2
is converted internally to:
targets/
├── target_000001_chromosome_1.fa
└── target_000002_chromosome_2.fa
Each LASTZ invocation then receives exactly one target sequence.
Query sequences can be processed in chunks using:
-l 100000For example:
Query sequence
────────────────────────────────────────
100 kb 100 kb 100 kb
↓ ↓ ↓
chunk_1 chunk_2 chunk_3
This allows very large query sequences to be processed without loading the entire alignment workload into a single LASTZ process.
For multiple target and query sequences, jobs are generated as:
Number of jobs =
Number of target sequences × Number of query chunks
For example:
Target:
T1
T2
Query:
Q1
Q2
Q3
Q4
produces:
T1 × Q1
T1 × Q2
T1 × Q3
T1 × Q4
T2 × Q1
T2 × Q2
T2 × Q3
T2 × Q4
Total:
2 × 4 = 8 alignment jobs
The -c/--cfile option specifies a configuration file containing LASTZ arguments.
Example:
--chain
--progress
--identity=90
--ambiguous=iupac
--format=general-
The configuration is parsed safely and passed to LASTZ as separate command-line arguments.
parallelLastz ensures that:
--format=general-
is retained for the alignment output.
Create a file named:
conf
with:
--chain
--progress
--identity=90
--ambiguous=iupac
--format=general-
Then run:
perl parallelLastz_v0.3.3.pl \
-q genomes/query.fna \
-t genomes/target.fna \
-c conf \
-j 4 \
-l 100000In normal mode, parallelLastz displays a compact progress indicator:
LASTZ: [###############.........] 6/8 completed | 2 running | 0 failed
This avoids flooding the terminal with individual commands.
For detailed information, use:
-vExample:
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 4 \
-vVerbose mode reports information such as:
- FASTA records
- Job IDs
- LASTZ commands
- Retry attempts
- Output files
- Errors
- Job status
A run can be resumed using:
--resumeExample:
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 4 \
--resumeThe program reads:
parallelLastz.manifest.tsv
and skips jobs that have already completed successfully.
This is particularly useful for large datasets where an alignment run may take several hours or days.
Failed LASTZ jobs can automatically be retried.
For example:
--retry 3means that a failed job can be attempted again up to three times.
Example:
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 8 \
--retry 3The manifest records the number of attempts for each job.
Use:
--dry-runto inspect the planned workload without running LASTZ.
Example:
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 4 \
--dry-runThis is useful for checking:
- Number of target sequences
- Number of query chunks
- Number of alignment jobs
- Output locations
- Parallelization settings
A typical output directory contains:
output/
├── chunks/
│ ├── targets/
│ │ ├── target_000001.fa
│ │ └── target_000002.fa
│ ├── job_000001.lz
│ ├── job_000002.lz
│ └── ...
│
├── logs/
│ ├── job_000001.stdout
│ ├── job_000001.stderr
│ ├── job_000002.stdout
│ └── job_000002.stderr
│
├── parallelLastz.manifest.tsv
└── finalAlign.tsv
Individual LASTZ results are stored as:
job_000001.lz
job_000002.lz
...
Successful alignment outputs are combined into:
finalAlign.tsv
The manifest tracks each job:
job_id
target_file
target_id
query_chunk
query_id
query_start
query_end
output
status
attempts
exit_code
stdout_file
stderr_file
message
This provides a persistent record of the complete analysis.
parallelLastz captures both:
STDOUT
STDERR
from LASTZ.
For example, instead of reporting only:
LASTZ failed with exit code 1
the program reports the actual diagnostic message from LASTZ.
This makes failures considerably easier to troubleshoot.
An important behavior is that an alignment producing zero records is still considered successful when LASTZ exits with code 0.
For example:
LASTZ exit code: 0
Alignment output: empty
Status: SUCCESS
This prevents biologically valid "no alignment found" results from being incorrectly classified as failed jobs.
By default, the program detects the number of available CPUs.
You can explicitly specify the number of parallel jobs:
-j 8It is recommended to choose a value appropriate for both:
- CPU availability
- available RAM
More parallel processes do not necessarily produce better performance if the system becomes memory or I/O constrained.
perl parallelLastz_v0.3.3.pl \
--qfile genomes/query.fna \
--tfile genomes/target.fna \
--cfile conf \
--jobs 8 \
--length 100000 \
--retry 2 \
--wipeFor detailed output:
perl parallelLastz_v0.3.3.pl \
--qfile genomes/query.fna \
--tfile genomes/target.fna \
--cfile conf \
--jobs 8 \
--length 100000 \
--retry 2 \
--wipe \
--verboseIf the previous run was interrupted:
perl parallelLastz_v0.3.3.pl \
--qfile genomes/query.fna \
--tfile genomes/target.fna \
--cfile conf \
--jobs 8 \
--length 100000 \
--resumeDo not use --wipe when you want to resume an existing run.
For a large genome comparison:
# 1. Test the configuration
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 8 \
--dry-run
# 2. Start the alignment
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 8 \
-l 100000 \
--retry 2
# 3. If interrupted, resume
perl parallelLastz_v0.3.3.pl \
-q query.fna \
-t target.fna \
-c conf \
-j 8 \
-l 100000 \
--resumeIf you use parallelLastz in your research, please cite the software repository and LASTZ.
Harris RS. Improved pairwise alignment of genomic DNA. PhD thesis, Pennsylvania State University.
LASTZ:
https://www.bx.psu.edu/~rsharris/lastz/
Jitendra Narayan and chatGPT for this v0.3.3 version
Please add the license appropriate for your project.
For example:
MIT License
See the LICENSE file for details.
parallelLastz v0.3.3
A parallel LASTZ workflow with multi-FASTA handling, resumable execution, retry support, job manifests, error capture, and terminal progress monitoring.
Harris, R.S. (2007) Improved pairwise alignment of genomic DNA. Ph.D. Thesis, The Pennsylvania State University.
Please feel free to give this repository a few likes as encouragement. 👍 🙏 👏
Contact me at jnarayan81@gmail.com or info@bioinformaticsonline.com