Human mobile element insertions¶
Applies to GraffiTE v1.1
Verified against v1.1.0.0 at commit bf51777. The
2024 paper describes v1.0, which
differs in places; see v1.0 vs v1.1.
In Stage 2, --human writes pangenome.human.vcf, a subset of
pangenome.vcf restricted to the mobile element subfamilies still active in humans, instead
of pangenome.trusted.vcf module/main.nf:597-608. Then it runs the
HERV-K (HML-2) classifier over the callset, and after genotyping it consolidates the HERV-K loci
in the genotyped calls.
The filter reads pangenome.vcf directly; none of the --trusted_* parameters affect it. Class-level filtering would not be enough: SINE/Alu alone admits AluJ and AluS elements
that have not been mobile for tens of millions of years, so every class carries a subfamily
whitelist.
What --human changes¶
pangenome.vcf goes through five gates in one bcftools view -i
expression. The carve-out on the right admits HML-2 proviral records that RepeatMasker split
into more than one hit.
The whole filter is one expression, assembled in Groovy and written verbatim into
3_TSD_search/human_filter_summary.txt together with record counts and the kept and dropped
(matching_classes, repeat_ids) combinations module/main.nf:610-625.
Read that file first when a record you expected is missing.
Subfamily whitelists¶
A record of a class passes only when one of its repeat_ids matches that class's whitelist regex. The
whitelists are comma-separated lists of bcftools regexes; each list is expanded into an OR of
repeat_ids~"<regex>" clauses module/main.nf:538-544.
matching_classes |
Parameter | Default | Keeps | Source |
|---|---|---|---|---|
SINE/Alu |
--human_alu_ids |
^AluY |
AluY and its subfamilies (AluYa5, AluYb8, ...); drops AluS and AluJ | nextflow.config:70 |
LINE/L1 |
--human_l1_ids |
^L1HS |
L1HS only; add ^L1PA2 to relax |
nextflow.config:71 |
Retroposon/SVA |
--human_sva_ids |
^SVA_[DEF] |
SVA_D, SVA_E, SVA_F | nextflow.config:72 |
Simple_repeat |
--human_sva_ids |
^SVA_[DEF] |
the SVA_*(VNTR_only) records that Stage 2 reclassified as Simple_repeat; see SVA VNTR polymorphisms |
module/main.nf:543 |
LTR/ERVK |
--human_hervk_ids |
^HERVK-int,^HERVK$,^LTR5_Hs,^LTR5A,^LTR5B |
the HML-2 internal region under either library name, and the LTR5 family; ^HERVK$ is anchored at both ends so that HERVK9-int, HERVK11-int and HERVK14-int, which are other lineages, stay out |
nextflow.config:73-81 |
An empty string keeps the whole class module/main.nf:539.
Two bcftools behaviors the filter depends on
repeat_ids and matching_classes are Number=. fields. bcftools evaluates ~ on them
element by element, with ^ anchoring each element, which is why repeat_ids~"^LTR5_Hs"
matches the record SVA_A,LTR5_Hs. bcftools regexes have no alternation, so each
whitelist is a list rather than one a|b pattern. Negation with !~ is not reliable on these
fields either, which is why every clause below is phrased positively
module/main.nf:532-549. Details in
VCF fields.
Length and tandem-repeat gates¶
module/main.nf:545
| Parameter | Default | Effect |
|---|---|---|
--human_min_svlen |
250 bp |
drops records shorter than a truncated Alu |
--human_max_ultra_span |
0.6 (fraction of the variant covered by ULTRA tandem repeats) |
drops VNTR-dominated records, except the Simple_repeat ones that are VNTR by construction |
Source: nextflow.config:82-83.
The 250 bp threshold is sized for insertions and is wrong for the SVA_*(VNTR_only) records,
whose unit is about 49 bp. On the 20-genome HPRC set it keeps 102 of 1,141, and
--human_sva_ids removes most of the rest, so do not read the VNTR content of
pangenome.human.vcf as a catalog. See
SVA VNTR polymorphisms.
One element, or the HERVK + SVA carve-out¶
module/main.nf:550-571. A record passes the structure gate in one of
two ways.
One hit. n_hits == 1, and the record is LTR/ERVK, Simple_repeat, or carries
polyA = TRUE. Alu, L1 and SVA insertions arrive by target-primed reverse transcription and
carry a polyA tail; HML-2 elements and VNTR expansions do not, so the filter requires the tail
only where the mechanism leaves one.
The carve-out. RepeatMasker often reports a small SVA_* hit at the end of an HML-2
provirus. That is homology, not a second element: SVA's SINE-R domain derives from the HERV-K
LTR (see HERV-K biology). Such records have two hits and would
fail the one-hit rule, so the carve-out admits them when all of these hold:
| Parameter | Default | Source |
|---|---|---|
--hervk_sva_pair |
true; false removes the carve-out |
nextflow.config:85 |
--hervk_pair_max_svlen |
10500 bp, a 9,472 bp provirus plus tolerance |
nextflow.config:86 |
--hervk_pair_max_hits |
3; 2 restores the pre-1.1 rule |
nextflow.config:87 |
The hit count is a cap rather than an equality because RepeatMasker also splits the internal
region of a degraded or rearranged provirus. In a cohort of 20 diploid human genomes, two of the three records at
chr7:4,699,714 came back with three hits (LTR5_Hs,SVA_A,HERVK-int and
HERVK-int,SVA_A,HERVK-int), where the third hit is that split. At n_hits == 2 the filter
kept one record of the locus and dropped the two carrying its common allele, so the locus
came out as a two-unit against three-unit difference where the assemblies show three states. The
other three clauses restrict the cap to HML-2 proviral records: relaxing n_hits on its own in
the one-hit rule admits records that are an LTR5 fragment beside something else, alpha
satellite and HERVK9 among them
module/main.nf:555-569.
Carve-out matches the name HERVK-int only
The clause matches repeat_ids~"^HERVK-int" literally, not the --human_hervk_ids list. A
library that names the internal region HERVK, as Dfam does, satisfies the whitelist but not
the carve-out, so its split proviral records fall back on the one-hit rule.
Finally, unless --human_ignore_filter is set, the record must carry FILTER = PASS from the
SV caller module/main.nf:573.
HERV-K classifier¶
Alu, L1 and SVA records are done once they pass the filter. HML-2 records are not: a solo LTR
and a full provirus at the same site are two different alleles of one locus, and a structural
variant call only ever describes the difference between two of a locus's states. hervk_annotate
works out which two, for each LTR/ERVK candidate in pangenome.vcf, and writes the result into
pangenome.human.vcf main.nf:171-182, module/main.nf:300-414. The
biology is on the HERV-K background page; this is the procedure.
- Candidates. Every record with
LTR/ERVKamong its classes and|SVLEN|at most--hervk_max_svlen(25000bp). This runs over the whole ofpangenome.vcf, not only the human subset, so that a locus split by the filter is still seen wholemodule/main.nf:348-349. - Architecture.
hervk_arch.pyre-reads the raw RepeatMasker tables (repeat_idsholds one name per link group, which erases the LTR-INT-LTR order), tiles the hits along the SV allele, reassigns SINE-R hits to the LTR class, and reports a signature:ARCH_2LTR(two complete terminal LTRs),ARCH_PERM(one LTR split across the two ends at permutation pointk),ARCH_INT_PERM(the same split inside the internal region, pointj),ARCH_SOLO(one LTR, no internal region) orARCH_NONE. Written tohervk_arch.tsvmodule/main.nf:351,bin/hervk_arch.py:254-356. - Reference state.
hervk_ref_state.pycuts a window of the reference around each candidate (--hervk_ref_flank,1500bp each side), masks it with RepeatMasker against the TE library ontask.cpusthreads, and reads off what the reference holds:null,solo,provirus,partial, orunknown. An element that runs into the window edge is re-masked with a 12,000 bp flank, then 24,000 and 48,000 bp if it still does. For a proviral reference it counts the units and measures their period. With--hervk_ref_annotation(a RepeatMasker.outor a BED of the reference) the classifier skips the masking step. Written tohervk_refstate.tsvmodule/main.nf:353-362,bin/hervk_ref_state.py:46-72. - Classification.
hervk_classify.pycombines the two tables andSVLENintoHERVK_ALLELE_REF,HERVK_ALLELE,HERVK_EVIDENCEandHERVK_CLASS. Copy-number arithmetic runs first: when|SVLEN|is a whole number of the reference element's period and one side has two or more units, the states areprov_xN. Otherwise the pair comes from the architecture, or from the reference state where the architecture is degenerate. Size alone never determines a class;HERVK_PMAPis a confidence under a size model, reported for information. It runs twice: over the full candidate set, writinghervk_candidates.vcf,hervk_calls.tsvandhervk_polymorphism_summary.md; and over the human subset, annotating its records and its presence-absence TSVmodule/main.nf:371-382,bin/hervk_classify.py:290-391. - Loci.
hervk_reconcile.py flaggroups records whose footprints lie within--hervk_locus_window(1200bp, one LTR plus tolerance) into loci and writesHERVK_LOCUS,HERVK_LOCUS_N, the flagsHERVK_MEI,HERVK_SOLO_PROV,HERVK_CNV,HERVK_MERGE_FLAG,HERVK_POLARITY_CONFLICT, and the summaryHERVK_LOCUS_TYPE. The flag step marks records and never merges them, becausepangenome.human.vcfmust keep its record structure. The locus table ishervk_loci.tsvmodule/main.nf:384-388,bin/hervk_reconcile.py:95-170. - Consolidated discovery VCF. The same loci collapsed to one multi-allelic record each, with
the allele set and the counts from the assemblies, as a separate file
pangenome.human.consolidated.vcfand a reportmodule/main.nf:401-407.
pangenome.vcf itself is read and never rewritten here: it induces the graph and must stay
byte-identical module/main.nf:295-296. pangenome.human.vcf and its
TSV, first written by concat_repeatmask, are overwritten by this process's annotated versions
module/main.nf:301.
The field-by-field definitions are in VCF fields.
After genotyping: hervk_reconcile¶
Genotyping does not preserve the HERV-K annotation, because merge_VCFs copies INFO from the
un-annotated pangenome.vcf. hervk_reconcile restores it and consolidates the loci in the
genotyped calls main.nf:286-293, module/main.nf:422-493:
GraffiTE.merged.genotypes.vcf.gzis subset to the IDs inpangenome.human.vcf.- Every
HERVK_*INFO field is copied across from the discovery VCF withbcftools annotate. hervk_reconcile.py consolidatewrites one record per locus, withHERVK_AC/HERVK_ANfrom the graph genotypes besideHERVK_AC_DISC/HERVK_AN_DISCfrom the assemblies, and withholds the graph genotypes at copy-number loci (HERVK_GT_MASKED). At those loci the ALT path repeats sequence the reference already carries, so reads from the pre-existing copy traverse it and non-carriers acquire ALT support; the discovery genotypes come from haplotype-resolved alignments and do not have this problemnextflow.config:103-111.
Outputs: 4_Genotyping/GraffiTE.merged.genotypes.human.vcf.gz (indexed),
hervk_unconsolidated_records.vcf (the member records, archived) and
hervk_reconciliation_report.md. The full GraffiTE.merged.genotypes.vcf.gz is never rewritten.
vg call genotypes only
The reconciler reads genotypes from vg call, which the giraffe, graphaligner and
precomputed methods all use bin/hervk_reconcile.py:431-434,772-776.
We validated it on giraffe genotypes from a cohort of 20 diploid human genomes; the synthetic test suite checks
graphaligner and precomputed against giraffe. The pipeline refuses PanGenie genotypes: a
--human run that genotypes with --graph_method pangenie stops at launch unless you pass
--hervk_reconcile false main.nf:65-71. When the VCF comes in
through --hervk_reconcile_vcf, hervk_reconcile reads the back end from the header and
accepts any vg call VCF.
Re-running the HERV-K stages without genotyping¶
Graph genotyping is the expensive stage, and the HERV-K work does not depend on which run made
the calls. To repeat steps 1 to 6 and the consolidation against a genotyped VCF from an earlier
run main.nf:296-314:
nextflow run cgroza/GraffiTE -r v1.1.0.0 -latest \
--RM_dir earlier/out/2_Repeat_Filtering \
--reference ref.fa --TE_library TEs.fa --human \
--genotype false \
--hervk_reconcile_vcf earlier/out/4_Genotyping/GraffiTE.merged.genotypes.vcf.gz
--RM_dir is the entry point to use here, not --graffite_vcf: the classifier needs the raw
RepeatMasker tables, and --graffite_vcf skips the stage that provides them. The workflow
refuses --graffite_vcf --human unless --hervk_reconcile false is also given
main.nf:58-63.
Tuning¶
| Parameter | Default | Effect | Source |
|---|---|---|---|
--hervk_config |
null |
JSON file of overrides for hervk_classify.py; keys present replace the script's DEFAULTS, nested dictionaries are merged key by key |
nextflow.config:66, bin/hervk_classify.py:58-97 |
--hervk_strict |
false |
drop candidates classed other or below pmap_min (0.90); off because dropping records hid a failure in the previous classifier |
nextflow.config:120 |
--hervk_max_svlen |
25000 bp |
candidacy cap; a complete provirus is 9,472 bp and a 25 Mb artifact once dominated the masking cost | nextflow.config:89 |
--hervk_ref_flank |
1500 bp |
reference masked either side of each candidate footprint | nextflow.config:113 |
--hervk_locus_window |
1200 bp |
maximum footprint gap within one locus | nextflow.config:114 |
--hervk_ref_annotation |
null |
precomputed reference repeat track; skips the in-pipeline masking | nextflow.config:118 |
--hervk_mask_graph_gt_at_cnv |
true |
withhold graph genotypes at copy-number loci; --hervk_mask_tandem is the deprecated name |
nextflow.config:103-112 |
--hervk_reconcile |
true |
run the consolidation after genotyping | nextflow.config:99 |
--hervk_annotate_threads, _memory, _time |
1, 10G, 12h |
resources for the masking step | nextflow.config:132-134 |
The keys --hervk_config can override, with their defaults, are the DEFAULTS dictionary at
the top of bin/hervk_classify.py: sigmas, priors, t_min, t_max, s_range,
int_full_frac, pmap_min, min_hml2_bp, hml2_frac_min, cnv_period_tol,
cnv_period_frac, max_svlen, min_solo_bp and min_prov_int_bp. Unknown keys are accepted
and ignored.
utils/HERVK.config.json predates this classifier
The template in utils/ carries keys from the previous, size-based classifier (s_C,
priors named C/T/B/A/X, sva_mimic_*). None of them is read by the current
script. Write your JSON against the DEFAULTS names above.
Outputs specific to --human¶
All in 3_TSD_search/ unless stated; see Output files for the
directory tree and VCF fields for the fields.
| File | Written by | Contents |
|---|---|---|
pangenome.human.vcf |
concat_repeatmask, then overwritten by hervk_annotate |
the filtered subset, with HERV-K allele states and locus flags; not an input to graph construction |
pangenome.presence-absence_human.tsv |
same | its presence-absence table |
human_filter_summary.txt |
concat_repeatmask |
the filter expression, counts, kept and dropped combinations |
hervk_candidates.vcf |
hervk_annotate |
every HERV-K candidate in pangenome.vcf, annotated, whether or not the filter kept it |
hervk_calls.tsv, hervk_loci.tsv |
hervk_annotate |
the per-record calls and the locus table |
hervk_arch.tsv, hervk_refstate.tsv |
hervk_annotate |
the architecture and reference-state tables the calls rest on |
hervk_polymorphism_summary.md |
hervk_annotate |
counts per class and evidence |
pangenome.human.consolidated.vcf, hervk_discovery_consolidation_report.md |
hervk_annotate |
one record per locus, discovery genotypes |
4_Genotyping/GraffiTE.merged.genotypes.human.vcf.gz |
hervk_reconcile |
the genotyped human subset, loci consolidated |
4_Genotyping/hervk_unconsolidated_records.vcf, hervk_reconciliation_report.md |
hervk_reconcile |
the archived member records and the report |
pangenome.trusted.vcf and its TSV are not written under --human
module/main.nf:597-601.