Skip to main content

Create a DDBJ annotation file from GFF3 and FASTA files

Project description

GFF3-to-DDBJ

日本語版はこちら

GitHub tag (latest by date) Conda (channel only) PyPI

[TOC]

Table of Contents

Table of contents generated with markdown-toc

What is this?

GFF3-to-DDBJ creates the annotation file for submission to DDBJ by taking GFF3 and FASTA files as input. It also works with FASTA alone.

Analogous programs are GAG for submissions to NCBI, and EMBLmyGFF3 for submissions to EMBL.

Please take a look at our test directory for examples. Files ending with .ann are the DDBJ annotation files produced by thie program.

Initial setup

Install with bioconda

# Create a conda environment named "ddbj", and install relevant packages from bioconda channel
conda create -n ddbj -c bioconda -c conda-forge gff3toddbj

# Activate the environment "ddbj"
conda activate ddbj

Install with pip

# Create a conda environment named "ddbj" and install pip
conda create -n ddbj pip

# Activate the environment "ddbj"
conda activate ddbj

# Need bgzip executable in samtools
conda install -c bioconda samtools

# Install from pip
pip install gff3toddbj

Install from the source

# Download
wget https://github.com/yamaton/gff3_to_ddbj/archive/refs/heads/main.zip

# Extract, rename, and change directory
unzip main.zip && mv gff3toddbj-main gff3toddbj && cd gff3toddbj

# Create a conda environment named "ddbj"
conda create -n ddbj

# Activate the environment "ddbj"
conda activate ddbj

# Install dependencies to "ddbj"
conda install -c bioconda -c conda-forge biopython bcbio-gff toml setuptools pysam samtools

# Install gff3-to-ddbj and extra tools
python setup.py install

Create DDBJ annotation from GFF3 and FASTA

Run gff3-to-ddbj

Let's run the main program to get some ideas.

gff3-to-ddbj \
  --gff3 myfile.gff3 \                # bare-minimum output if omitted
  --fasta myfile.fa \                 # <<REQUIRED>>
  --metadata mymetadata.toml \        # example metadata used if omitted
  --locus_tag_prefix MYOWNPREFIX_ \   # default is "LOCUSTAGPREFIX_"
  --transl_table 1 \                  # default is 1
  --output myawesome_output.ann       # standard output if omitted

Here is the options:

  • --gff3 <FILE> takes GFF3 file
  • --fasta <FILE> takes FASTA file
  • --metadata <FILE> takes the metadata file in TOML
  • --locus_tag_prefix <STRING> takes the prefix of locus tag obtained from BioSample. You can skip this for now.
  • --transl_table <INT>: Choose appropriate one from The Genetic Codes. The default value is 1 ("standard").
  • --output <FILE> sets the path the annotation output.

Under the Hood

Here is the list of operations gff3-to-ddbj will do:

  • Re-compress FASTA with bgzip if the FASTA input is compressed with gzip

    • A bgzip file is created if absent like myfile_bgzip.fa.gz.
    • For indexing and saving memory
    • The bgzip file should be compatible with gzip
  • Rename features and qualifiers following the renaming scheme.

  • Search for assembly_gaps in FASTA.

  • Add /transl_table to each CDS.

  • Insert source information from the metadata fie.

  • Merge CDSs having the same parent with join notation.

  • Merge mRNA and exon in GFF3 and create mRNA feature with join notation.

  • Modify locations with inequality signs (< and >) if start/stop codon is absent.

  • Let CDS have a single /product value: Set it to "hypothetical protein" if absent. Move the rest of exising values to /note.

    • This is to conform the instruction on /product.

      • Even if there are multiple general names for the same product, do not enter multiple names in 'product'. Do not use needless symbolic letters as delimiter for multiple names. If you would like to describe more than two names, please enter one of the most representative name in /product qualifier, and other(s) in /note qualifier.

      • If the name and function are not known, we recommend to describe as "hypothetical protein".

  • Remove duplicates in qualifier values.

  • Sort lines in annotation

  • Filter features and qualifiers following the matrix.

Customize the behavior

Metadata file

To enter information missing in GFF3 or FASTA, such as submitter names and certain qualifier values, you need to feed a metadata file in TOML, say mymetadata.toml. Take a look at an example matching the example annotation in the DDBJ page.

The file accommodates following and they are all optional. That is, GFF3-to-DDBJ works even with an empty file.

  • Basic features in the COMMON entry

    • ... such as SUBMITTER, REFERENCE, and COMMENT.
  • "meta-description" in the COMMON entry

    • Here is an example with this notation:

      [COMMON.assembly_gap]
      estimated_length = "unknown"
      gap_type = "within scaffold"
      linkage_evidence = "paired-ends"
      
    • DDBJ annotation supports "meta" values with features under COMMON such that the items are inserted to each occurrence in the resulting flat file produced by DDBJ. Here is an example to insert assembly_gap feature under COMMON entry.

  • Feature-qualifier items inserted to each occurrence

    • Here is an example: Difference from the previous case is only at [assembly_gap] as opposed to[COMMON.assembly_gap].

      [assembly_gap]
      estimated_length = "unknown"   # Set it "<COMPUTE>" to count the number of N's
      gap_type = "within scaffold"
      linkage_evidence = "paired-ends"
      
    • While this should work effectively the same as the "meta-description" item above, use this notation if you insert values repeatedly in the annotation file produced by GFF3-to-DDBJ.

    • Currently supporting [source] and [assembly_gap] only.

    • If both [COMMON.assembly_gap] and [COMMON.assembly] exist in the metadata file, gff3-to-ddbj takes the one with COMMON.

For more examples, see WGS in COMMON and WGS provided by DDBJ as annotation examples, and corresponding metadata files metadata_WGS_COMMON.toml and metadata_WGS.toml in this repository.

[Advanced] Rename Features and Qualifiers

GFF3 and DDBJ annotation have rough correspondence like:

  1. GFF3 column 3 "type" → DDBJ annotation column 2 as "Feature"
  2. GFF3 column 9 "attribute" → DDBJ annotation column 4 and 5 as "Qualifier key", and "Qualifier value"

but nomenclatures in GFF3 often do not conform the annotations set by INSDC. Furthermore, DDBJ lists up the feature-qualifier pairs they accepts, a subset of the INSDC definitions.

To meet convensions with the requirement, GFF3-to-DDBJ comes with a default configuration in TOML to rename (or even translate) feature keys and qualifier keys/values. Note that the Sequence Ontology is helpful in translating a type into a INSDC feature and qualifier(s).

Here is how to customize the renaming configuration.

Rename types/feature keys

The default setting renames five_prime_UTR "type" in GFF3 into 5'UTR "feature key" in the annotation. This transformation is expressed in TOML as follows:

[five_prime_UTR]
feature_key = "5'UTR"

Rename attributes/qualifier keys

This is about renaming attributes under arbitrary types. By default, ID=foobar "attribute" in a GFF3 becomes /note="ID:foobar" qualifier in the annotation. (Here I follow the convention putting slash (like /note) to denote qualifier. But DDBJ annotation does NOT include slash hence no slash is used in any of TOML files.)

Here is the TOML defining the transformation. __ANY__ is the special name representing arbitrary types. ID is the original attribute key. note is the name of corresponding qualifier key. ID: is attached as the prefix of the qualifier value.

[__ANY__.ID]
qualifier_key = "note"
qualifier_value_prefix = "ID:"  # optional

Translate GFF3 types to features with qualifiers

Sometimes we want to replace a certain types with features WITH qualifiers. For example, snRNA is an invalid feature in INSDC/DDBJ hence we replace it with ncRNA feature with /ncRNA_class="snRNA" qualifier. Such transformation is written in TOML as following.

[snRNA]
feature_key = "ncRNA"
qualifier_key = "ncRNA_class"
qualifier_value = "snRNA"

Translate (type, attribute) items to features

Example: some annotation programs produce a GFF3 line containing RNA as the type and biotype=misc_RNA as one of the attributes. Then it should be translated to misc_RNA feature in annoation.

[RNA.biotype]
attribute_value = "misc_RNA"
feature_key = "misc_RNA"

Run with custom configuration

To feed a custom translation table, use the CLI option:

  • --config_rename <FILE>

And here is an example call:

gff3-to-ddbj \
  --gff3 myfile.gff3 \
  --fasta myfile.fa \
  --metadata mymetadata.toml \
  --locus_tag_prefix MYOWNPREFIX_ \
  --transl_table 1 \
  --config_rename my_translate_features_qualifiers.toml \  # Set your customized file here
  --output myawesome_output.ann

[Advanced] Filter features and qualifiers

DDBJ specifies recommended Feature/Qualifier usage matrix. To conform this rule, features and qualifiers appearing in the annotation output are filtered by the filtering file in TOML by default. The file is in TOML format with the structure like this:

CDS = [
"EC_number",
"inference",
"locus_tag",
"note",
"product",
]

exon = [
"gene",
"locus_tag",
"note",
]

The left-hand side of the equal sign = represents an allowed feature key, and the right-hand side is a list of allowed qualifier keys. In this example, only CDS and exon features will show up in the annotation, and qualifiers are limited to the listed items. To customize this filtering function, edit the TOML file first and pass the file with the CLI option:

  • --config_filter <FILE>

Troubleshooting

Validate GFF3

It might be a good practice to validate your GFF3 files. GFF3 online validator is useful though the file size is limited to 50MB.

Split FASTA from GFF3 (if needed)

GFF3_to_DDBJ does not work when GFF3 contains FASTA information inside with ##FASTA directive. Attached tool split-fasta reads a GFF3 file and saves GFF3 (without FASTA info) and FASTA.

split-fasta path/to/myfile.gff3 --suffix "_splitted"

This creates two files, myfile_splitted.gff3 and myfile_splitted.fa.

Normalize entry names (if needed)

Letters like =|>" [] are not allowed in the 1st column (= "Entry") of the DDBJ annotation. The attached program normalize-entry-names renames such entries. This program converts an ID like ERS324955|SC|contig000013 into ERS324955:SC:contig000013 for example.

normalize-entry-names myannotation_output.txt

This command create as files myannotation_output_renamed.txt if the invalid letters are found. Otherwise, you'll see no output.

Credit

GFF3-to-DDBJ's design is deeply indebted to EMBLmyGFF3, a versatile coversion for EMBL annotation format.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gff3toddbj-0.2.4.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

gff3toddbj-0.2.4-py3-none-any.whl (46.9 kB view details)

Uploaded Python 3

File details

Details for the file gff3toddbj-0.2.4.tar.gz.

File metadata

  • Download URL: gff3toddbj-0.2.4.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for gff3toddbj-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c3798f2515db9049de0c9fc5ef12caf2c391308955fa4dc096f9a0f26c6e61ac
MD5 6266128a92f6aa9900d1700fc1d692ff
BLAKE2b-256 a616bce8a7ef2b42eb0884d7961bf7e53cda033932cd0cf7e6c4de5d57d87f6e

See more details on using hashes here.

File details

Details for the file gff3toddbj-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: gff3toddbj-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 46.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for gff3toddbj-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c092fc085b7fad242a3b2ce7f0ef5f77e28987874e4a4649404d68c0331b7ced
MD5 5546312df41086b5fb924f6106880d2e
BLAKE2b-256 aec0a2b2ef9d8e57c8c019d602e754c7410d58cdfac66958d704f6d9dcab55e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page