Skip to content

Commit

Permalink
fix #457 remove attribute in gene_id and transcript_id to keep only t…
Browse files Browse the repository at this point in the history
…he first … (#496)

* remove multi values in special attributes gene_id and transcript_id to keep only the first one. The others are saved in agat_other_gene_id or agat_other_ transcript_id

* when using merge_overlap_loci avoid to merge value for ID Parent and no gene_id too. Avoid to add ID created on the fly when creating merged_.

* add a deflate_attribute parameter. Make also a global variable for CONFIG to be available from everywhere (filled by get_agat_config)

* Update and add tests
  • Loading branch information
Juke34 authored Dec 6, 2024
1 parent d8a3f15 commit 9ecbcc6
Show file tree
Hide file tree
Showing 21 changed files with 302 additions and 170 deletions.
4 changes: 4 additions & 0 deletions bin/agat
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ force_gff_input_version, gtf_output_version, gff_output_version and output_forma
getopt => 'gtf_output_version=s',
help => 'Set the GTF output vesion. Choice 1, 2, 2.1, 2.2, 2.5, 3 or relax. [Default relax]',
},
{
getopt => 'deflate_attribute!',
help => 'deflate multi-values attributes: attribute_tag=att_value1,att_value2,att_value3 will will become attribute_tag=att_value1;attribute_tag2=att_value2;attribute_tag3=att_value3;',
},
{
getopt => 'create_l3_for_l2_orphan!',
help => 'To create l3 feature for l2 feature without any. [Default activated]',
Expand Down
15 changes: 13 additions & 2 deletions lib/AGAT/AGAT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use AGAT::PlotR;
use Bio::Tools::GFF;

our $VERSION = "v1.4.1";
our @ISA = qw(Exporter);
our @EXPORT = qw(get_agat_header print_agat_version get_agat_config handle_levels);
our $CONFIG; # This variable will be used to store the config and will be available from everywhere.
our @ISA = qw( Exporter );
our @EXPORT = qw( get_agat_header print_agat_version get_agat_config handle_levels );
sub import {
AGAT::AGAT->export_to_level(1, @_); # to be able to load the EXPORT functions when direct call; (normal case)
AGAT::OmniscientI->export_to_level(1, @_);
Expand Down Expand Up @@ -159,6 +160,10 @@ sub get_agat_config{
# Load the config
my $config = load_config({ config_file => $config_file_checked});
check_config({ config => $config});

# Store the config in a Global variable accessible from everywhere.
$CONFIG = $config;

return $config;
}

Expand Down Expand Up @@ -243,6 +248,7 @@ sub handle_config {
my $output_format = $general->{configs}[-1]{output_format};
my $gff_output_version = $general->{configs}[-1]{gff_output_version};
my $gtf_output_version = $general->{configs}[-1]{gtf_output_version};
my $deflate_attribute = $general->{configs}[-1]{deflate_attribute};
my $create_l3_for_l2_orphan = $general->{configs}[-1]{create_l3_for_l2_orphan};
my $clean_attributes_from_template = $general->{configs}[-1]{clean_attributes_from_template};
my $locus_tag = $general->{configs}[-1]{locus_tag};
Expand Down Expand Up @@ -325,6 +331,11 @@ sub handle_config {
$modified_on_the_fly = 1;
}
# bolean
if( defined($deflate_attribute) ){
$config->{ deflate_attribute } = _make_bolean($deflate_attribute);
$modified_on_the_fly = 1;
}
# bolean
if( defined($create_l3_for_l2_orphan) ){
$config->{ create_l3_for_l2_orphan } = _make_bolean($create_l3_for_l2_orphan);
$modified_on_the_fly = 1;
Expand Down
24 changes: 24 additions & 0 deletions lib/AGAT/BioperlGFF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ package AGAT::BioperlGFF;
use vars qw($HAS_HTML_ENTITIES);
use strict;

use AGAT::OmniscientTool;
use AGAT::AGAT;
use Bio::Seq::SeqFactory;
use Bio::LocatableSeq;
use Bio::SeqFeature::Generic;
Expand Down Expand Up @@ -699,6 +701,28 @@ sub write_feature {
$self->_print($line);
}
$self->{'_first'} = 0;

# deflate multi-values attribute if asked by config
if ($AGAT::AGAT::CONFIG->{'deflate_attribute'}){
foreach my $feature ( @features ) {
my @list_tags= $feature->get_all_tags();
foreach my $tag (@list_tags){
my @tag_values = $feature->get_tag_values($tag);
if ($#tag_values >= 1){
my $tag_counter=-1;
foreach my $tag_value (@tag_values){
$tag_counter++;
if ($tag_counter == 0){
create_or_replace_tag($feature, $tag , $tag_value);
} else {
create_or_replace_tag($feature, $tag."_".$tag_counter , $tag_value);
}
}
}
}
}
}

foreach my $feature ( @features ) {
$self->_print($self->gxf_string($feature)."\n");
}
Expand Down
6 changes: 5 additions & 1 deletion lib/AGAT/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ sub check_config{
$error = 1;
}
if( ! exists_keys($config,("log") ) ){
print "progress_bar parameter missing in the configuration file.\n";
print "log parameter missing in the configuration file.\n";
$error = 1;
}
if( ! exists_keys($config, ("debug") ) ){
Expand Down Expand Up @@ -241,6 +241,10 @@ sub check_config{
print "gtf_output_version parameter missing in the configuration file.\n";
$error = 1;
}
if( ! exists_keys($config, ("deflate_attribute") ) ) {
print "deflate_attribute parameter missing in the configuration file.\n";
$error = 1;
}
if( ! exists_keys($config, ("create_l3_for_l2_orphan") ) ) {
print "create_level3_for_level2_orphan parameter missing in the configuration file.\n";
$error = 1;
Expand Down
Loading

0 comments on commit 9ecbcc6

Please sign in to comment.