
Merge Per-Haplotype Annotations Into One Annotation Directory
Source:R/annotation-tools.R
merge_annotations.RdPhased (trio-binned or pangenome) assemblies come with one annotation per
haplotype, for example the HPRC CAT files HG00438.1.chm13.gff3.gz and
HG00438.2.chm13.gff3.gz. merge_annotations() converts each file (or
reuses an existing annotation directory), tags every table with the
haplotype label, makes identifiers unique by appending _<haplotype>, and
writes one combined annotation directory. Transcript, gene and exon IDs
therefore become <id>_<haplotype>, the convention expected for the row
names of a haplotype-resolved IsoformicExperiment (rename the sequences
of the per-haplotype transcript FASTA files the same way before building
the Salmon index).
The tables are copied by DuckDB from the Parquet files of each haplotype to the merged files, so they are not read into R: merging two annotations of a whole human release with their transcript sequences takes seconds and less than 2 GB of memory. The sequences are copied by one DuckDB thread, which keeps their memory to a few hundred megabytes.
The source_gene_id / source_transcript_id columns (GRCh38 identifiers
kept by Liftoff/CAT) are left untouched, which is what
haplotype_summary() uses to compare haplotypes of the same gene.
Usage
merge_annotations(
annot_paths,
output_path = NULL,
annot_name = "merged_haplotypes",
id_suffix = TRUE,
overwrite = FALSE
)Arguments
- annot_paths
Named character vector: names are haplotype labels, values are GFF3/GTF files or annotation directories.
- output_path
Directory under which the merged annotation directory is created.
NULLusesget_isoformic_cache().- annot_name
Name of the merged annotation directory.
- id_suffix
Logical. Append
_<haplotype>to gene, transcript and exon identifiers (defaultTRUE). Set toFALSEwhen the identifiers are already unique across haplotypes.- overwrite
Logical. Replace an existing merged directory.
Examples
gff <- system.file("extdata", "example.gff3.gz", package = "isoformic")
merged <- merge_annotations(
c(hap1 = gff, hap2 = gff),
output_path = tempdir(),
annot_name = "example_diploid",
overwrite = TRUE
)
#> ℹ Using cached annotation directory /tmp/RtmpM3Y6Dd/example_gff3.
#> ℹ Using cached annotation directory /tmp/RtmpM3Y6Dd/example_gff3.
tx <- read_parquet(file.path(merged, "annot_data_transcripts.parquet"))
table(tx$haplotype)
#>
#> hap1 hap2
#> 141 141
head(tx$transcript_id)
#> [1] "ENST00000909997.2_hap1" "ENST00000909998.2_hap1" "ENST00000909999.2_hap1"
#> [4] "ENST00000910000.2_hap1" "ENST00001131755.1_hap1" "ENST00000282397.9_hap1"