Skip to contents

An R6 class to represent transcriptome annotation with protein mapping. Specifically, it provides the following features:

  • Transcriptome annotation:

    • Association of transcript IDs with gene IDs, RNA types, and species

    • Association of gene IDs with gene symbols, protein IDs (UniProt), etc.

Details

For more information on how to specify the arguments, please refer to the vignette defining file formats.

Methods


Method new()

Initialize a new Annotation object.

This method initializes a new Annotation object.

Usage

Annotation$new(
  annotation = NULL,
  format_gff = TRUE,
  idmapping = NULL,
  annotation_dir = NULL,
  log_level = "WARN",
  suffix_pattern = "\\.\\d+$",
  gff_type_filter = c(".*RNA", ".*transcript"),
  gff_source = c("ncbi", "ensembl")
)

Arguments

annotation

Path to the annotation file in GFF format / or as described in the vignette. It can be a vector of files.

format_gff

If TRUE, the annotation file is in GFF format.

idmapping

Path to the idmapping file, which allows the mapping of uniprot id to gene id. If not give, the idmapping file will be downloaded from uniprot using taxon ID from annotation file.

annotation_dir

Path to a directory containing annotation CSV files (previously generated by write_to_directory). If provided, this takes precedence over annotation and idmapping.

log_level

Logging level, e.g., "INFO", "WARN", "DEBUG".

suffix_pattern

The regex pattern used see clean_txid_versions method.

gff_type_filter

Vector of regex patterns to filter the type column (3rd column of GFF)

gff_source

GFF format source: "ncbi" (default) or "ensembl". NCBI style looks for ID, Parent, gene, Dbxref, gbkey attributes. Ensembl style looks for ID (with transcript: prefix), gene_id, transcript_id, Parent (with gene: prefix), and Name attributes.

Returns

A new Annotation object.


Method generate_translate_dict()

generate a translate dictionary (named vector) from and id to another based on the annotation

Usage

Annotation$generate_translate_dict(from, to)

Arguments

from

the id type corresponding to the keys

to

the id type corresponding to the values

Details

Below is precised what is available and id type for value depending on id type for keys

  • Entrez Gene ID gid (Or equivalent on Ensembl,UCSC...)

    • Gene symbol symbol

    • Protein name protein_names

    • Protein ID uniprot

    • Taxon ID tax_id

    • Taxon name tax_name

    • Typed gene ID tgid

  • RefSeq transcript ID txid (Or equivalent on Ensembl,UCSC...)

    • Entrez Gene ID gid

    • rna type type

    • Taxon ID tax_id

    • Taxon name tax_name

    • Typed gene ID tgid

  • Typed gene ID tgid i.e. gene id with type concatenated (sep is _) (one gene can have several type, some coding, some not coding)

    • Gene symbol symbol

    • Protein name protein_names (warning even if not coding type)

    • Protein ID uniprot (warning even if not coding type)

    • rna type type

    • Taxon ID tax_id

    • Taxon name tax_name

  • Uniprot protein ID uniprot

    • Entrez Gene ID gid

    • Protein name protein_names

    • Gene symbol symbol

  • Gene symbol symbol

    • Entrez Gene ID gid

    • Protein ID uniprot

Returns

a named vector that can translate from an id type to another Get the list of id type available for translate dicttionary as keys


Method get_from_ids()

Usage

Annotation$get_from_ids()

Returns

vecotr with potentioal key "from" Get the list of id type available for translate dicttionary as values


Method get_to_ids()

Usage

Annotation$get_to_ids(from)

Arguments

from

the key of the translate dictionary

Returns

vecotr with potentioal key "to"


Method export_to_df()

Export annotation data to a data.frame for a given 'from' ID type.

For a specified 'from' ID type, this method creates a data.frame where each row corresponds to a unique 'from' ID, and columns represent all associated 'to' ID types. Missing associations will be represented as NA.

Usage

Annotation$export_to_df(from)

Arguments

from

The primary ID type (e.g., "gid", "txid") to use for rows.

Returns

A data.frame with the 'from' ID type as the first column, followed by columns for each derivable 'to' ID type. Returns an empty data.frame if 'from' is invalid or no data can be constructed.


Method write_to_directory()

Write all annotation data frames to a specified directory.

This method iterates through all available 'from' ID types, generates a data.frame for each using self$export_to_df(), and writes each data.frame to a CSV file named after the 'from' ID type (e.g., "gid.csv") in the specified directory.

Usage

Annotation$write_to_directory(directory_path)

Arguments

directory_path

The path to the directory where CSV files will be written. The directory will be created if it does not exist.

Returns

Invisibly returns TRUE if successful, or FALSE/throws error on failure. Logs information about files written or warnings for types with no data.


Method clean_txid_versions()

Clean version suffixes from transcript IDs within the internal annotation structures.

This method iterates through the private$annotations object. If a from_key (names of a mapping) is "txid", it cleans these names. If a to_key (values of a mapping) is "txid", it cleans these values. It uses the remove_id_version_suffix utility function.

Usage

Annotation$clean_txid_versions(suffix_pattern = "\\.\\d+$")

Arguments

suffix_pattern

(character) The regex pattern for the version suffix. Default is "\\.\\d+$". If NULL, FALSE, or an empty string, no cleaning is performed.


Method clone()

The objects of this class are cloneable with this method.

Usage

Annotation$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.