Varlens Documentation
varlens
A collection of Python tools for working with genomic variants and next-generation sequencing reads. Not particularly fast for large datasets. The emphasis is on extracting what you need from BAMs and VCFs into a CSV file for further analysis.
- varlens-variants
Combine, annotate, and filter variants from VCF or CSV files. Available annotations include genes, variant effects, surrounding sequence context, counts of supporting reads from specified BAM files, and MHC I binding affinity prediction of mutant peptides.
- varlens-reads
Display, filter, and copy reads from a SAM/BAM file. Partial replacement for
samtools view.- varlens-allele-support
Count reads supporting each allele at specified sites in BAM files.
Installation
Varlens 1.1 requires Python 3.11 or newer, pandas 3, and MHCTools 4.1.1 or newer (below 5). The package uses the current Topiary 5 prediction API.
Install the validated wheel from the Varlens 1.1.0 GitHub release:
python -m pip install https://github.com/openvax/varlens/releases/download/v1.1.0/varlens-1.1.0-py3-none-any.whl
PyPI currently serves the older 0.0.2 release. Publishing the current version there is blocked by account permissions, tracked in issue 55. Use the GitHub wheel above for the current Python and OpenVax stack.
Or from a git checkout:
pip install .
The examples below use test data from the tests/data directory of a git
checkout.
varlens-variants
Given variants from one or more VCF or CSV files, apply filters, add additional columns, and output to CSV.
Currently we can only output to CSV, not VCF.
A number of useful annotations can be added for each variant by specifying options of the form ‘–include-XXX’, e.g. ‘–include-gene’. See detailed help (run with -h).
Examples
Print basic info for the variants found in two VCF files. Note that variants found in both files are listed in one row, and the ‘sources’ column lists the files each variant was found in:
$ varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf tests/data/CELSR1/vcfs/vcf_2.vcf
genome,contig,interbase_start,interbase_end,ref,alt,sources
GRCh37,22,21829554,21829555,T,G,1
GRCh37,22,45309892,45309893,T,G,2
GRCh37,22,46931059,46931060,A,C,1
GRCh37,22,46931061,46931062,G,A,1 2
GRCh37,22,50636217,50636218,A,C,1
GRCh37,22,50875932,50875933,A,C,1
Same as the above but include additional columns giving varcode variant effect annotations and the genes the variants overlap, and write to a file:
$ varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf tests/data/CELSR1/vcfs/vcf_2.vcf \
--include-effect \
--include-gene \
--out /tmp/result.csv
Wrote: /tmp/result.csv
$ cat /tmp/result.csv
genome,contig,interbase_start,interbase_end,ref,alt,sources,effect,effect_candidates,gene
GRCh37,22,21829554,21829555,T,G,1,non-coding-transcript,NoncodingTranscript: non-coding-transcript,PI4KAP2
GRCh37,22,45309892,45309893,T,G,2,p.T214P,Substitution: p.T214P,PHF21B
GRCh37,22,46931059,46931060,A,C,1,p.S670A,Substitution: p.S670A,CELSR1
GRCh37,22,46931061,46931062,G,A,1 2,p.S669F,Substitution: p.S669F,CELSR1
GRCh37,22,50636217,50636218,A,C,1,intronic,Intronic: intronic,TRABD
GRCh37,22,50875932,50875933,A,C,1,p.A562fs,FrameShift: p.A562fs; Unresolved: unresolved-intron-retention; Unresolved: unresolved-cryptic; Intronic: intronic,PPP6R2
effect is the producer-preferred consequence on the selected transcript.
effect_candidates lists that consequence and its alternatives in Varcode’s
order, including unresolved outcomes. For example, an intronic primary can
retain a protein-changing exon-skip deletion. These are predicted alternatives, not observed products or
calibrated probabilities. MHC predictions use Topiary’s shared candidate-aware
selection and can therefore use a coding alternative to that primary.
Print counts for number of reads supporting reference/variant/other alleles from the specified BAM, counting only reads with mapping quality >= 10:
$ varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf \
--include-read-evidence \
--reads tests/data/CELSR1/bams/bam_1.bam \
--min-mapping-quality 10
genome,contig,interbase_start,interbase_end,ref,alt,sources,num_alt,num_ref,total_depth
GRCh37,22,21829554,21829555,T,G,vcf_1.vcf,0,0,0
GRCh37,22,46931059,46931060,A,C,vcf_1.vcf,0,216,320
GRCh37,22,46931061,46931062,G,A,vcf_1.vcf,0,321,321
GRCh37,22,50636217,50636218,A,C,vcf_1.vcf,0,0,0
GRCh37,22,50875932,50875933,A,C,vcf_1.vcf,0,0,0
varlens-reads
Filter reads from one or more BAMs and output a CSV or a new BAM.
Loci and VCF files may be specified, in which case reads are filtered to overlap the specified loci or variants.
Examples
Print basic fields for the reads in a BAM:
$ varlens-reads tests/data/CELSR1/bams/bam_0.bam
query_name,reference_start,reference_end,cigarstring
HISEQ:142:C5822ANXX:3:2116:16538:101199,46929962,46930062,100M
HISEQ:142:C5822ANXX:3:1106:18985:32932,46929964,46930064,100M
HISEQ:142:C5822ANXX:3:2201:21091:67220,46929966,46930066,100M
HISEQ:142:C5822ANXX:4:1304:5363:12786,46929966,46930066,100M
HISEQ:142:C5822ANXX:4:1104:9008:85114,46929969,46930069,100M
HISEQ:142:C5822ANXX:3:2304:9921:94828,46929970,46930070,100M
HISEQ:142:C5822ANXX:3:2211:6266:74633,46929973,46930073,100M
HISEQ:142:C5822ANXX:3:1305:8982:42729,46929974,46930074,100M
HISEQ:142:C5822ANXX:4:2316:5630:7371,46929978,46930078,100M
...
Same as above but filter only to reads aligned on the (-) strand, write to a file instead of stdout, and also include the mapping quality and sequenced bases in the output:
$ varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--is-reverse \
--field mapping_quality query_alignment_sequence \
--out /tmp/result.csv
Wrote: /tmp/result.csv
$ head /tmp/result.csv
query_name,reference_start,reference_end,cigarstring,mapping_quality,query_alignment_sequence
HISEQ:142:C5822ANXX:3:2116:16538:101199,46929962,46930062,100M,60,CATGATCTGGGCATTAGGGCCTTCATCAGGGTCGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCG
HISEQ:142:C5822ANXX:3:1106:18985:32932,46929964,46930064,100M,60,TGATCTGGGCATTAGGGCCTTCATCAGGGTCGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTC
HISEQ:142:C5822ANXX:4:1104:9008:85114,46929969,46930069,100M,60,TGGGCATTAGGGCCTTCATCAGGGTCGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCT
HISEQ:142:C5822ANXX:4:1202:18451:91174,46929979,46930079,100M,60,GGCCTTCATCAGGGTCGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCTCAAACATGGG
HISEQ:142:C5822ANXX:3:1211:18522:54773,46929987,46930087,100M,60,TCAGGGTCGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCTCAAACATGGGGGCATTGT
HISEQ:142:C5822ANXX:3:2114:19455:45093,46929987,46930087,100M,60,TCAGGGTCGTTAGCACGAATCTTTGCCACCGCCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCTCAAACATGGGGGCATTGT
HISEQ:142:C5822ANXX:4:2115:9153:21593,46929994,46930094,100M,60,CGTTAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCTCAAACATGGGGGCATTGTCATTAAT
HISEQ:142:C5822ANXX:4:1212:15644:87227,46929995,46930095,100M,60,GTTAGCACGTATGTTTGCCACCACCGACCCCACTGAGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTGCTTCTCAAACATGGGGGCAGTGTCATTAATG
HISEQ:142:C5822ANXX:3:1103:4717:26369,46929997,46930097,100M,60,TAGCACGAATCTTTGCCACCACCGACCCCACTGGGTTGTTCTCCTCAACAAACAGCTCCAGTTCGTCCTTCTCAAACATGGGGGCATTGTCATTAATGTC
Write a bam file consisting of reads with mapping quality >=30 and overlapping a certain locus:
$ varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--min-mapping-quality 30 \
--locus 22:46932040-46932050 \
--out /tmp/result.bam
Write a bam file consisting of reads overlapping variants from a VCF:
$ varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--variants tests/data/CELSR1/vcfs/vcf_1.vcf \
--out /tmp/result.bam
Print just the header for a BAM in csv format:
$ varlens-reads tests/data/CELSR1/bams/bam_0.bam --header
varlens-allele-support
Given one or more BAMs and some genomic sites to consider, write a csv file giving counts of reads supporting each allele at each site for each BAM.
The genomic sites to consider may be specified by locus (–locus option), or via one or more VCF files.
The positions outputted by this command are in interbase coordinates, i.e. starting at 0, inclusive on first index, exclusive on second (as opposed to the one-based inclusive coordinates used in VCF files).
Insertions use an empty interval at the insertion boundary. For example,
VCF 1:100 A>AT becomes interbase_start=100, interbase_end=100 with
ref="" and alt="T". The pileup reads the base immediately to the left
and counts only the inserted sequence. Version 1.0 corrects the older
single-base insertion intervals; CSV input still accepts that older encoding.
Examples
varlens-allele-support \
--reads tests/data/CELSR1/bams/bam_1.bam \
--locus 22:46931061 22:46931063
source,contig,interbase_start,interbase_end,allele,count
bam_1.bam,22,46931060,46931061,,1
bam_1.bam,22,46931060,46931061,G,329
bam_1.bam,22,46931062,46931063,A,327
bam_1.bam,22,46931062,46931063,AC,1
bam_1.bam,22,46931062,46931063,AG,2
Structural variants and empty inputs
varlens-variants loads symbolic SV alleles and paired/single breakends from
VCF using Varcode. A mixed SNV/SV file retains both kinds of event. A malformed
structural allele that Varcode cannot parse causes an error before output is
written. Empty or all-filtered sources produce a header-only CSV, including
when --chunk-rows is used. By default, non-PASS calls are excluded; use
--include-failing-variants to include them. VCF . and * ALT
placeholders are not independent variant calls. --max-variants-per-source
explicitly limits the number of loaded alleles.
Structural rows add two JSON-valued CSV columns:
structural_variant: thevarlens.structural_variant.v1envelope and Varcode constructor fields, including type, original alleles, affected span, partner breakpoint, orientation, uncertainty, assembly and INFO data. Genome objects are represented by their canonical assembly name.vcf_records: source paths and retained Varcode VCF metadata, including record ID, filter, INFO and sample fields, plus the original VCF line. Every retained record is kept when identical events are merged, within or across sources.
These columns are retained without --include-metadata and are required for
a structural CSV round trip. Do not edit the displayed locus/alleles independently
of the typed payload. Custom --columns output can deliberately omit fields,
but then cannot necessarily be reloaded. Ordinary variant CSVs retain their
existing schema.
For SVs, --variant-locus selects known breakpoint bases, including a
remote mate, rather than every base in a deleted/duplicated interval. Confidence
intervals are preserved but do not widen this filter. Raw contig spellings are
retained in the payload; displayed contigs follow Varcode normalization.
SV export, reload, REF/ALT filtering and breakpoint filtering are supported.
Gene/effect/context annotations, the best-affinity variant summary, and
single-interval read evidence currently reject SV rows with an actionable
diagnostic. Likewise, varlens-reads --variants and
varlens-allele-support --variants reject structural events. Explicit
--locus read export remains available: those alignments are raw observations,
not counts of molecules supporting a junction.
varlens-fusions
Install the optional Isovar adapter and reconstruct supplied fusion RNA:
python -m pip install 'varlens[fusion] @ https://github.com/openvax/varlens/releases/download/v1.1.0/varlens-1.1.0-py3-none-any.whl'
varlens-fusions fusion.json.gz --out reconstruction.json
Optionally predict junction-overlapping peptides with Topiary and mhctools:
varlens-fusions fusion.json.gz --hla 'HLA-A*02:01' 'HLA-B*07:02' \
--peptide-lengths 8 9 10 11 --out predictions.json
NetMHCpan and its model data must be installed for the second command. The
reconstruction-only command does not invoke it. Multiple JSON/JSON.gz input
files can be supplied, and --out also accepts JSON.gz; omitted output goes
to stdout. A failed input or prediction prevents writing a partial report.
Each input is an Isovar supplied-fusion input: a JSON object
with fusion, references and reads (plus optional reference_names).
fusion supplies event identity, assembly, oriented donor/acceptor breakpoints,
RNA sequence, mapped blocks, half-open junction coordinates and provenance with
a sample ID. References supply annotated transcript sequence/mapping and CDS
coordinates; reads supply observed RNA sequence/mapping and sample/library/read/
fragment identity. Isovar validates these fields and transfers frames only from
compatible annotated donors. The note and original_records fields in
the Sid fixture audit envelopes are retained in the report, but are not counted
as additional RNA evidence. Unknown fields are rejected.
The output varlens.fusions.v1 report contains an events list. Each
varlens.fusion.v1 event retains the entire input, the unmodified
isovar.fusion_rna.v3 reconstruction, software versions, Topiary fragments,
and full peptide prediction rows. prediction_status distinguishes
not_requested, no_coding_products and completed; a completed run may
have no target-overlapping predictions.
Unresolved and insufficient-support outcomes keep their reasons and measured evidence. Ambiguous or partial-CDS coding hypotheses remain separate fragments with explicit status on every prediction; Varlens does not choose an isoform. Junction read/fragment counts retain their supplied-observation scope. Unknown reference counts, protein-observation evidence, UMI/cell counts and comparator sequences are not filled with zero or inferred from alignment counts. Junction overlap is not a claim of proteome-wide novelty or tumor specificity. This command does not discover fusions, assemble arbitrary BAMs, translate structural VCFs, or establish whole-sample expression from selected reads.
Python callers can use the same workflow:
from varlens.fusions import analyze_fusion
result = analyze_fusion(payload, alleles=["HLA-A*02:01"])
analyze_fusion(payload) performs reconstruction only. A configured
topiary.TopiaryPredictor can be passed as predictor= instead of alleles.
varlens.mhc_binding.fragment_predictions also accepts existing
topiary.ProteinFragment objects and returns target-overlapping prediction
rows with source, sample and evidence metadata intact.
The bundled Sid regressions cover ATP5MG–KMT2A (a coding hypothesis with
ambiguous donor annotation), GABBR1–SLC29A1 T1 (unresolved frame with direct
junction support), and the latter’s unchanged raw alignment export. Their
upstream sources and checksums are in tests/data/fusions/manifest.json.
Note on coordinate systems
varlens uses 0-based half-open coordinates internally. Many tools
(including samtools and VCF files) use inclusive 1-based coordinates. We try to
keep the confusion to a minimum by using the term “interbase” whenever we’re
using 0-based half open coordinates and “inclusive” when we’re using 1-based
inclusive coordinates.
One particularly sticky place this comes up is when specifying loci on the
commandline using e.g. --locus chr22:43243-43244. To maintain consistency
with the most common other tools, when you specify a locus like
chr22:10-20, we interpret that as a 1-based inclusive coordinate. To
specify 0-based half-open coordinates, use this syntax: chr22/11-20 (i.e. a
slash instead of a colon).
See this blog post for more details on coordinate systems.
Python read-support API
varlens.support.variant_support(variants, counts) returns a pandas DataFrame
with variants as its row index and two column levels named measurement and
source. This replaces the removed pandas Panel API in Varlens 1.0:
evidence = variant_support(variants, counts)
alt_counts = evidence["num_alt"] # one column per read source
tumor_depth = evidence[("total_depth", "tumor")]
The metrics are num_alt, num_ref, num_other, total_depth,
alt_fraction, and any_alt_fraction. Commandline CSV columns retain their
existing names. Counts include low-quality bases and overlapping mates unless
read filters are requested. Common chr aliases resolve to BAM references;
alternate and unplaced contig names are preserved.
MHC binding uses the current Topiary API with a local NetMHCpan installation. It reports the lowest affinity in nM among peptides overlapping the mutation, and the corresponding input allele. Variants without predictions have missing values. Prediction caches distinguish peptide-length requests. Effect labels come from the installed Varcode version and may change as its annotations improve.
Development
To run the tests from a git checkout:
pip install -e '.[test,fusion]'
pyensembl install --release 75 --species human
./lint.sh
./test.sh
External NetMHCpan tests are opt-in: run ./test.sh --run-netmhcpan with
NetMHCpan and its model data installed. The other tests do not require it.
CI tests Python 3.11 through 3.14, the pandas 3.0.0 floor and current 3.x,
and reference-dependent annotation in a separate job. A shared-stack job
also installs Varlens, Vaxrank, MHCTools, and Trufflepig together with normal
dependency resolution and runs pip check. To reproduce that check in a
fresh environment:
python -m pip install -e '.[test,fusion]' -r requirements-openvax.txt
python -m pip check
./test.sh
Refresh editable metadata from the existing checkout with pip install -e .
after changing its requirements. The metadata test checks every visible
Varlens distribution against the source version, including stale editable
metadata in site-packages.
In a shared environment, resolve all installed OpenVax consumers together and preserve existing editable checkouts. Varlens 1.1 requires the coordinated Varcode 11.2, Isovar 1.78 (for fusions), and Topiary 5.109 stack; installations with Vaxrank need its compatible 3.49 release. Current Topiary and Trufflepig 1.30 require pandas 3; the older Trufflepig 1.28 pandas cap is incompatible with this stack. Do not force incompatible versions or silently downgrade another consumer. Repository-local release environments remain separate from the shared environment.
To build the documentation (just this README plus the commandline tool help):
pip install -e '.[docs]'
python -m sphinx -W --keep-going -b html docs docs/_build/html
The docs will be written to docs/_build/html. Maintainers with push access
can publish them using ./deploy-gh-pages.sh; it builds in a temporary
directory and updates the existing GitHub Pages branch without rewriting its
history. Set PYTHON to select a particular environment’s Python executable.
Commandline tool help
varlens-variants
$ varlens-variants -h
usage:
Given variants from one or more VCF or CSV files, apply filters, add additional
columns, and output to CSV.
Currently we can only output to CSV, not VCF.
A number of useful annotations can be added for each variant by specifying
options of the form '--include-XXX', e.g. '--include-gene'. See detailed help
below.
Examples:
Print basic info for the variants found in two VCF files. Note that variants
found in both files are listed in one row, and the 'sources' column lists
the files each variant was found in:
varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf tests/data/CELSR1/vcfs/vcf_2.vcf
Same as the above but include additional columns giving varcode variant effect
annotations and the genes the variants overlap, and write to a file:
varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf tests/data/CELSR1/vcfs/vcf_2.vcf \
--include-effect \
--include-gene \
--out /tmp/result.csv
Print counts for number of reads supporting reference/variant/other alleles
from the specified BAMs, counting only reads with mapping quality >= 10:
varlens-variants tests/data/CELSR1/vcfs/vcf_1.vcf \
--include-read-evidence \
--reads tests/data/CELSR1/bams/*.bam \
--min-mapping-quality 10
options:
-h, --help show this help message and exit
variant loading:
variants Path to VCF file. Any number of VCF files may be
specified. CSV files in the format outputted by the
varlens-variants tool are also supported.
--genome GENOME Genome for the variants (e.g. b37). Required when the
genome cannot be guessed from the metadata in the VCF.
--include-failing-variants
Include variants with a non-PASS filter field.
--variant-source-name VARIANT_SOURCE_NAME [VARIANT_SOURCE_NAME ...]
Names for variant sources. Must specify one name per
variant source. If not specified, the filenames are
used.
--max-variants-per-source N
Load at most N variants from each source.
--single-variant X X X
Literal variant specified as three arguments: LOCUS
REF ALT. Can be specified any number of times by
repeating the --single-variant option.
variant filtering:
If multiple filters are specified, the variants must pass *all* filters.
For filtering by loci, any variants that overlap the specified loci are
included. Structural variants match known breakpoint bases (including
remote mates), not the full SV span.
--ref REF [REF ...] Include only variants where ref is one of the given
values.
--alt ALT [ALT ...] Include only variants where alt is one of the given
values.
--variant-locus VARIANT_LOCUS [VARIANT_LOCUS ...]
Genomic locus, like chr1:2342332 or chr1:2342-23423.
Any number of loci may be specified.
variant output:
--no-standard-columns
Don't write standard columns (genome, contig, start,
end, ref, alt)
--chunk-rows N Write out current results after processing N rows.
--limit N Process only the first N variants (useful for testing)
--columns COLUMNS Column separated list of columns to output
--rename-column COL COL
Rename output column first argument to second. Can be
specified multiple times by repeating the --rename-
column option.
--out OUT Output file. If not specified the CSV is written to
stdout.
--include-metadata Output variant metadata when loading from VCF (info
column, etc).
-v, --verbose
variant effect annotations:
--include-effect Include the primary Varcode annotation and its
candidate consequences
gene annotations:
--include-gene Include gene names
variant sequence context:
--include-context Include variant sequence context
--reference REFERENCE
Path to reference fasta (required for sequence
context)
--context-num-bases N
Num bases of context to include on each side of the
variant
MHC binding affinity:
--include-mhc-binding
Include MHC binding (tightest affinity and allele)
--hla HLA Space separated list of MHC alleles, e.g. 'A:02:01
A:02:02'
--hla-file HLA_FILE Load HLA types from the specified CSV file. It must
have columns: 'donor' and 'hla'
read evidence:
--include-read-evidence
Include counts of supporting / contradicting reads
--read-sources-file READ_SOURCES_FILE
Load paths to BAMs from the given csv file.
--read-sources-id-column READ_SOURCES_ID_COLUMN
Column to use to join read sources with the variants
dataframe.
--read-sources-column READ_SOURCES_COLUMN
Column containing path to reads (e.g. path to a BAM).
Can be specified any number of times. If not
specified, all columns are used.
--always-prefix-column
Always prefix the column names with the source name
and count group, even when there is only one of each.
--survive-errors If an error is encountered log it and try to continue.
read loading:
--reads READS [READS ...]
Paths to bam files. Any number of paths may be
specified.
--read-source-name READ_SOURCE_NAME [READ_SOURCE_NAME ...]
Names for each read source. The number of names
specified must match the number of bam files. If not
specified, filenames are used for names.
read filtering:
A number of read filters are available. See the pysam documentation
(http://pysam.readthedocs.org/en/latest/api.html) for details on what
these fields mean. When multiple filter options are specified, reads must
match *all* filters.
--is-paired Only reads where is_paired is True
--not-is-paired Only reads where is_paired is False
--is-proper-pair Only reads where is_proper_pair is True
--not-is-proper-pair Only reads where is_proper_pair is False
--is-qcfail Only reads where is_qcfail is True
--not-is-qcfail Only reads where is_qcfail is False
--is-read1 Only reads where is_read1 is True
--not-is-read1 Only reads where is_read1 is False
--is-read2 Only reads where is_read2 is True
--not-is-read2 Only reads where is_read2 is False
--is-reverse Only reads where is_reverse is True
--not-is-reverse Only reads where is_reverse is False
--is-secondary Only reads where is_secondary is True
--not-is-secondary Only reads where is_secondary is False
--is-unmapped Only reads where is_unmapped is True
--not-is-unmapped Only reads where is_unmapped is False
--mate-is-reverse Only reads where mate_is_reverse is True
--not-mate-is-reverse
Only reads where mate_is_reverse is False
--mate-is-unmapped Only reads where mate_is_unmapped is True
--not-mate-is-unmapped
Only reads where mate_is_unmapped is False
--is-duplicate Only reads where is_duplicate is True
--not-is-duplicate Only reads where is_duplicate is False
--cigarstring STRING Only reads with the specified cigarstring
--cigarstring-contains STRING
Only reads where cigarstring contains the given string
--query-alignment-sequence STRING
Only reads with the specified query_alignment_sequence
--query-alignment-sequence-contains STRING
Only reads where query_alignment_sequence contains the
given string
--query-name STRING Only reads with the specified query_name
--query-name-contains STRING
Only reads where query_name contains the given string
--inferred-length N Only reads with the specified inferred_length
--min-inferred-length N
Only reads where inferred_length >=N
--max-inferred-length N
Only reads where inferred_length <=N
--mapping-quality N Only reads with the specified mapping_quality
--min-mapping-quality N
Only reads where mapping_quality >=N
--max-mapping-quality N
Only reads where mapping_quality <=N
--query-alignment-length N
Only reads with the specified query_alignment_length
--min-query-alignment-length N
Only reads where query_alignment_length >=N
--max-query-alignment-length N
Only reads where query_alignment_length <=N
--query-alignment-start N
Only reads with the specified query_alignment_start
--min-query-alignment-start N
Only reads where query_alignment_start >=N
--max-query-alignment-start N
Only reads where query_alignment_start <=N
--query-length N Only reads with the specified query_length
--min-query-length N Only reads where query_length >=N
--max-query-length N Only reads where query_length <=N
--reference-length N Only reads with the specified reference_length
--min-reference-length N
Only reads where reference_length >=N
--max-reference-length N
Only reads where reference_length <=N
--reference-start N Only reads with the specified reference_start
--min-reference-start N
Only reads where reference_start >=N
--max-reference-start N
Only reads where reference_start <=N
--template-length N Only reads with the specified template_length
--min-template-length N
Only reads where template_length >=N
--max-template-length N
Only reads where template_length <=N
varlens-reads
$ varlens-reads -h
usage:
Filter reads from one or more BAMs and output a CSV or a new BAM.
Loci and VCF files may be specified, in which case reads are filtered to
overlap the specified loci or variants.
Examples:
Print basic fields for the reads in a BAM:
varlens-reads tests/data/CELSR1/bams/bam_0.bam
Same as above but filter only to reads aligned on the (-) strand, write to a
file instead of stdout, and also include the mapping quality and sequenced
bases in the output:
varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--is-reverse \
--field mapping_quality query_alignment_sequence \
--out /tmp/result.csv
Write a bam file consisting of reads with mapping quality >=30 and
overlapping a certain locus:
varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--min-mapping-quality 30 \
--locus 22:46932040-46932050 \
--out /tmp/result.bam
Write a bam file consisting of reads overlapping variants from a VCF:
varlens-reads tests/data/CELSR1/bams/bam_0.bam \
--variants tests/data/CELSR1/vcfs/vcf_1.vcf \
--out /tmp/result.bam
Print just the header for a BAM in csv format:
varlens-reads tests/data/CELSR1/bams/bam_0.bam --header
options:
-h, --help show this help message and exit
output:
--out OUT Output file. Format is guessed from file extension:
must be csv or bam. If not specified, csv is written
to stdout.
--field FIELD [FIELD ...]
Additional read fields to output as columns in the
csv. See pysam documentation
(http://pysam.readthedocs.org/en/latest/api.html) for
the meaning of these fields. Valid fields include:
cigarstring flag inferred_length is_duplicate
is_paired is_proper_pair is_qcfail is_read1 is_read2
is_reverse is_secondary is_unmapped mapping_quality
mate_is_reverse mate_is_unmapped next_reference_id
next_reference_start query_alignment_end
query_alignment_length query_alignment_qualities
query_alignment_sequence query_alignment_start
query_length query_name reference_end reference_id
reference_length reference_start template_length
--no-standard-fields Do not include the standard fields (source,
query_name, reference_start, reference_end,
cigarstring) in csv output.
--no-sort When outputting a bam, do not call samtools sort.
--header Output BAM/SAM header only.
--header-set HEADER_SET HEADER_SET HEADER_SET HEADER_SET
When outputting a bam, set a particular header field
to the given value. Example: --header-set RG . SM
my_sample
-v, --verbose
read loading:
reads Paths to bam files. Any number of paths may be
specified.
--read-source-name READ_SOURCE_NAME [READ_SOURCE_NAME ...]
Names for each read source. The number of names
specified must match the number of bam files. If not
specified, filenames are used for names.
read filtering:
A number of read filters are available. See the pysam documentation
(http://pysam.readthedocs.org/en/latest/api.html) for details on what
these fields mean. When multiple filter options are specified, reads must
match *all* filters.
--is-paired Only reads where is_paired is True
--not-is-paired Only reads where is_paired is False
--is-proper-pair Only reads where is_proper_pair is True
--not-is-proper-pair Only reads where is_proper_pair is False
--is-qcfail Only reads where is_qcfail is True
--not-is-qcfail Only reads where is_qcfail is False
--is-read1 Only reads where is_read1 is True
--not-is-read1 Only reads where is_read1 is False
--is-read2 Only reads where is_read2 is True
--not-is-read2 Only reads where is_read2 is False
--is-reverse Only reads where is_reverse is True
--not-is-reverse Only reads where is_reverse is False
--is-secondary Only reads where is_secondary is True
--not-is-secondary Only reads where is_secondary is False
--is-unmapped Only reads where is_unmapped is True
--not-is-unmapped Only reads where is_unmapped is False
--mate-is-reverse Only reads where mate_is_reverse is True
--not-mate-is-reverse
Only reads where mate_is_reverse is False
--mate-is-unmapped Only reads where mate_is_unmapped is True
--not-mate-is-unmapped
Only reads where mate_is_unmapped is False
--is-duplicate Only reads where is_duplicate is True
--not-is-duplicate Only reads where is_duplicate is False
--cigarstring STRING Only reads with the specified cigarstring
--cigarstring-contains STRING
Only reads where cigarstring contains the given string
--query-alignment-sequence STRING
Only reads with the specified query_alignment_sequence
--query-alignment-sequence-contains STRING
Only reads where query_alignment_sequence contains the
given string
--query-name STRING Only reads with the specified query_name
--query-name-contains STRING
Only reads where query_name contains the given string
--inferred-length N Only reads with the specified inferred_length
--min-inferred-length N
Only reads where inferred_length >=N
--max-inferred-length N
Only reads where inferred_length <=N
--mapping-quality N Only reads with the specified mapping_quality
--min-mapping-quality N
Only reads where mapping_quality >=N
--max-mapping-quality N
Only reads where mapping_quality <=N
--query-alignment-length N
Only reads with the specified query_alignment_length
--min-query-alignment-length N
Only reads where query_alignment_length >=N
--max-query-alignment-length N
Only reads where query_alignment_length <=N
--query-alignment-start N
Only reads with the specified query_alignment_start
--min-query-alignment-start N
Only reads where query_alignment_start >=N
--max-query-alignment-start N
Only reads where query_alignment_start <=N
--query-length N Only reads with the specified query_length
--min-query-length N Only reads where query_length >=N
--max-query-length N Only reads where query_length <=N
--reference-length N Only reads with the specified reference_length
--min-reference-length N
Only reads where reference_length >=N
--max-reference-length N
Only reads where reference_length <=N
--reference-start N Only reads with the specified reference_start
--min-reference-start N
Only reads where reference_start >=N
--max-reference-start N
Only reads where reference_start <=N
--template-length N Only reads with the specified template_length
--min-template-length N
Only reads where template_length >=N
--max-template-length N
Only reads where template_length <=N
loci specification:
--locus LOCUS [LOCUS ...]
Genomic locus, like chr1:2342332 or chr1:2342-23423.
Any number of loci may be specified.
variant loading:
--variants VARIANTS [VARIANTS ...]
Path to VCF file. Any number of VCF files may be
specified. CSV files in the format outputted by the
varlens-variants tool are also supported.
--genome GENOME Genome for the variants (e.g. b37). Required when the
genome cannot be guessed from the metadata in the VCF.
--include-failing-variants
Include variants with a non-PASS filter field.
--variant-source-name VARIANT_SOURCE_NAME [VARIANT_SOURCE_NAME ...]
Names for variant sources. Must specify one name per
variant source. If not specified, the filenames are
used.
--max-variants-per-source N
Load at most N variants from each source.
--single-variant X X X
Literal variant specified as three arguments: LOCUS
REF ALT. Can be specified any number of times by
repeating the --single-variant option.
variant filtering:
If multiple filters are specified, the variants must pass *all* filters.
For filtering by loci, any variants that overlap the specified loci are
included. Structural variants match known breakpoint bases (including
remote mates), not the full SV span.
--ref REF [REF ...] Include only variants where ref is one of the given
values.
--alt ALT [ALT ...] Include only variants where alt is one of the given
values.
--variant-locus VARIANT_LOCUS [VARIANT_LOCUS ...]
Genomic locus, like chr1:2342332 or chr1:2342-23423.
Any number of loci may be specified.
varlens-allele-support
$ varlens-allele-support -h
usage:
Given one or more BAMs and some genomic sites to consider, write a csv file
giving counts of reads supporting each allele at each site for each BAM.
The genomic sites to consider may be specified by locus (--locus option), or via
one or more VCF files.
The positions outputted by this command are in *interbase coordinates*, i.e.
starting at 0, inclusive on first index, exclusive on second (as opposed to
the one-based inclusive coordinates used in VCF files).
Example:
varlens-allele-support \
--reads tests/data/CELSR1/bams/bam_1.bam \
--locus 22:46931061 22:46931063
options:
-h, --help show this help message and exit
output arguments:
--out OUT
-v, --verbose
loci specification:
--locus LOCUS [LOCUS ...]
Genomic locus, like chr1:2342332 or chr1:2342-23423.
Any number of loci may be specified.
variant loading:
--variants VARIANTS [VARIANTS ...]
Path to VCF file. Any number of VCF files may be
specified. CSV files in the format outputted by the
varlens-variants tool are also supported.
--genome GENOME Genome for the variants (e.g. b37). Required when the
genome cannot be guessed from the metadata in the VCF.
--include-failing-variants
Include variants with a non-PASS filter field.
--variant-source-name VARIANT_SOURCE_NAME [VARIANT_SOURCE_NAME ...]
Names for variant sources. Must specify one name per
variant source. If not specified, the filenames are
used.
--max-variants-per-source N
Load at most N variants from each source.
--single-variant X X X
Literal variant specified as three arguments: LOCUS
REF ALT. Can be specified any number of times by
repeating the --single-variant option.
variant filtering:
If multiple filters are specified, the variants must pass *all* filters.
For filtering by loci, any variants that overlap the specified loci are
included. Structural variants match known breakpoint bases (including
remote mates), not the full SV span.
--ref REF [REF ...] Include only variants where ref is one of the given
values.
--alt ALT [ALT ...] Include only variants where alt is one of the given
values.
--variant-locus VARIANT_LOCUS [VARIANT_LOCUS ...]
Genomic locus, like chr1:2342332 or chr1:2342-23423.
Any number of loci may be specified.
read loading:
--reads READS [READS ...]
Paths to bam files. Any number of paths may be
specified.
--read-source-name READ_SOURCE_NAME [READ_SOURCE_NAME ...]
Names for each read source. The number of names
specified must match the number of bam files. If not
specified, filenames are used for names.
read filtering:
A number of read filters are available. See the pysam documentation
(http://pysam.readthedocs.org/en/latest/api.html) for details on what
these fields mean. When multiple filter options are specified, reads must
match *all* filters.
--is-paired Only reads where is_paired is True
--not-is-paired Only reads where is_paired is False
--is-proper-pair Only reads where is_proper_pair is True
--not-is-proper-pair Only reads where is_proper_pair is False
--is-qcfail Only reads where is_qcfail is True
--not-is-qcfail Only reads where is_qcfail is False
--is-read1 Only reads where is_read1 is True
--not-is-read1 Only reads where is_read1 is False
--is-read2 Only reads where is_read2 is True
--not-is-read2 Only reads where is_read2 is False
--is-reverse Only reads where is_reverse is True
--not-is-reverse Only reads where is_reverse is False
--is-secondary Only reads where is_secondary is True
--not-is-secondary Only reads where is_secondary is False
--is-unmapped Only reads where is_unmapped is True
--not-is-unmapped Only reads where is_unmapped is False
--mate-is-reverse Only reads where mate_is_reverse is True
--not-mate-is-reverse
Only reads where mate_is_reverse is False
--mate-is-unmapped Only reads where mate_is_unmapped is True
--not-mate-is-unmapped
Only reads where mate_is_unmapped is False
--is-duplicate Only reads where is_duplicate is True
--not-is-duplicate Only reads where is_duplicate is False
--cigarstring STRING Only reads with the specified cigarstring
--cigarstring-contains STRING
Only reads where cigarstring contains the given string
--query-alignment-sequence STRING
Only reads with the specified query_alignment_sequence
--query-alignment-sequence-contains STRING
Only reads where query_alignment_sequence contains the
given string
--query-name STRING Only reads with the specified query_name
--query-name-contains STRING
Only reads where query_name contains the given string
--inferred-length N Only reads with the specified inferred_length
--min-inferred-length N
Only reads where inferred_length >=N
--max-inferred-length N
Only reads where inferred_length <=N
--mapping-quality N Only reads with the specified mapping_quality
--min-mapping-quality N
Only reads where mapping_quality >=N
--max-mapping-quality N
Only reads where mapping_quality <=N
--query-alignment-length N
Only reads with the specified query_alignment_length
--min-query-alignment-length N
Only reads where query_alignment_length >=N
--max-query-alignment-length N
Only reads where query_alignment_length <=N
--query-alignment-start N
Only reads with the specified query_alignment_start
--min-query-alignment-start N
Only reads where query_alignment_start >=N
--max-query-alignment-start N
Only reads where query_alignment_start <=N
--query-length N Only reads with the specified query_length
--min-query-length N Only reads where query_length >=N
--max-query-length N Only reads where query_length <=N
--reference-length N Only reads with the specified reference_length
--min-reference-length N
Only reads where reference_length >=N
--max-reference-length N
Only reads where reference_length <=N
--reference-start N Only reads with the specified reference_start
--min-reference-start N
Only reads where reference_start >=N
--max-reference-start N
Only reads where reference_start <=N
--template-length N Only reads with the specified template_length
--min-template-length N
Only reads where template_length >=N
--max-template-length N
Only reads where template_length <=N
varlens-fusions
$ varlens-fusions -h
usage: varlens-fusions [-h] [--out OUT] [--hla HLA [HLA ...]]
[--peptide-lengths PEPTIDE_LENGTHS [PEPTIDE_LENGTHS ...]]
[--min-fragments MIN_FRAGMENTS]
inputs [inputs ...]
Reconstruct supplied fusion RNA and optionally predict junction peptides.
positional arguments:
inputs Isovar supplied-fusion JSON or JSON.gz files
options:
-h, --help show this help message and exit
--out OUT JSON/JSON.gz report; defaults to stdout
--hla HLA [HLA ...] MHC alleles; enables NetMHCpan via mhctools
--peptide-lengths PEPTIDE_LENGTHS [PEPTIDE_LENGTHS ...]
--min-fragments MIN_FRAGMENTS
Minimum direct junction fragments required by Isovar
(default: 2)
Python API
- varlens package
- Subpackages
- Submodules
- varlens.fusions module
- varlens.loci_util module
- varlens.locus module
- varlens.mhc_binding module
- varlens.read_source module
- varlens.reads_util module
- varlens.sequence_context module
- varlens.support module
- varlens.util module
- varlens.variant_includes module
- varlens.variants_util module
- varlens.version module
- Module contents