Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage chevron in GFF start and stop #241

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ jobs:
--genome_name chlam_annotated_with_prodigal --anno GBFF/GCF_003788785.1_ct114V1_genomic_prodigal_annotation.gff.gz \
--gff --table --cpu $NUM_CPUS

# projection of a plasmid with chevron that have been added manually to test chevron handeling in GFF
ppanggolin projection --pangenome myannopang/pangenome.h5 --anno GBFF/plasmid_NZ_CP007132_with_manually_added_chevrons.gff.gz --cpu $NUM_CPUS -o projection_plasmid_with_chevron

- name: testing write_genome_cmds
shell: bash -l {0}
run: |
Expand Down
36 changes: 32 additions & 4 deletions ppanggolin/annotate/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,29 @@ def get_id_attribute(attributes_dict: dict) -> str:
raise Exception(f"Each CDS type of the gff files must own a unique ID attribute. "
f"Not the case for file: {gff_file_path}")
return element_id


def check_chevrons_in_start_and_stop(start: str, stop: str) -> Tuple[int, int, bool]:
"""
Checks for the presence of chevrons ('<' or '>') in the start and stop strings, removes them if present,
and converts the remaining parts to integers.

:param start: The start string which may contain chevrons.
:param stop: The stop string which may contain chevrons.

:return: A tuple containing the integer values of start and stop, and a boolean indicating if chevrons were present in either string.
"""
chevrons_present = '>' in start or '<' in start or '>' in stop or '<' in stop

if chevrons_present:
start = int(start.replace('<', '').replace('>', ''))
stop = int(stop.replace('<', '').replace('>', ''))
else:
start = int(start)
stop = int(stop)

return start, stop, chevrons_present


contig = None # initialize contig
has_fasta = False
Expand Down Expand Up @@ -646,8 +669,13 @@ def get_id_attribute(attributes_dict: dict) -> str:
else:
fields_gff = [el.strip() for el in line.split('\t')]
attributes = get_gff_attributes(fields_gff)

pseudogene = False

start, stop, has_chevron = check_chevrons_in_start_and_stop(start=fields_gff[gff_start], stop=fields_gff[gff_end])
if has_chevron:
pseudogene = True

if fields_gff[gff_type] == 'region':
# keep region attributes to add them as metadata of genome and contigs
# excluding some info as they are alredy contained in contig object.
Expand Down Expand Up @@ -714,8 +742,8 @@ def get_id_attribute(attributes_dict: dict) -> str:
"position":contig.number_of_genes,
"product":product,
"local_identifier":gene_id,
"start": int(fields_gff[gff_start]),
"stop": int(fields_gff[gff_end]),
"start": start,
"stop": stop,
"ID": id_attribute}

check_and_add_extra_gene_part(existing_gene, new_gene_info)
Expand All @@ -728,7 +756,7 @@ def get_id_attribute(attributes_dict: dict) -> str:
id_attr_to_gene_id[id_attribute] = gene

# here contig is filled in order, so position is the number of genes already stored in the contig.
gene.fill_annotations(start=int(fields_gff[gff_start]), stop=int(fields_gff[gff_end]),
gene.fill_annotations(start=start, stop=stop,
strand=fields_gff[gff_strand], gene_type=fields_gff[gff_type], name=name,
position=contig.number_of_genes, product=product,
local_identifier=gene_id,
Expand All @@ -742,7 +770,7 @@ def get_id_attribute(attributes_dict: dict) -> str:
rna_type = fields_gff[gff_type]
rna = RNA(org.name + f"_{rna_type}_" + str(rna_counter).zfill(4))

rna.fill_annotations(start=int(fields_gff[gff_start]), stop=int(fields_gff[gff_end]),
rna.fill_annotations(start=start, stop=stop,
strand=fields_gff[gff_strand], gene_type=fields_gff[gff_type], name=name,
product=product, local_identifier=gene_id)
rna.fill_parents(org, contig)
Expand Down
Binary file not shown.