Skip to content

Commit

Permalink
fix #129. Level2 replaced by level1. Sounds better and no problem enc…
Browse files Browse the repository at this point in the history
…ountered. Fix #128. Add warning when l2 not on same seq_id than its parent. Fix check_level1_positions to avoid to update location when L2 not on same seq_id than its parent. (#130)
  • Loading branch information
Juke34 committed May 10, 2021
1 parent 4997ee6 commit 601743d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 21 additions & 3 deletions lib/AGAT/OmniscientI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ sub manage_one_feature{
#GFF case
if($feature->has_tag('Parent')){
$parent = lc($feature->_tag_value('Parent'));
$locusTAGvalue=$parent;
$locusTAGvalue = $parent;
_save_common_tag_value_top_feature($feature, $locusTAG_uniq, 'level2');
}

Expand Down Expand Up @@ -708,6 +708,7 @@ sub manage_one_feature{
####################
# SAVE THE FEATURE #
dual_print ($log, "::::::::::Push-L2-omniscient-3 level2 || $primary_tag || $parent == ".$feature->gff_string."\n", $verbose) if ($debug);
_check_locus_uniqueness($feature, $omniscient, $parent);
push (@{$omniscient->{"level2"}{$primary_tag}{lc($parent)}}, $feature);
}
return $last_locusTAGvalue, $last_l1_f, $feature, $last_l3_f, $feature, $lastL1_new;
Expand Down Expand Up @@ -990,6 +991,23 @@ sub _fix_parent_attribute_when_id_l1_l2_identical{
}
}

# infrom user if 2 features of a same record are on different seq_id
sub _check_locus_uniqueness{
my ($feature, $omniscient, $parent)=@_;

foreach my $tag_l1 ( sort {$a cmp $b} keys %{$omniscient->{'level1'}}){ # primary_tag_key_level2 = mrna or mirna or ncrna or trna etc...
if ( exists_keys ( $omniscient, ('level1', $tag_l1, lc($parent) ) ) ){

if( $feature->seq_id() ne $omniscient->{'level1'}{$tag_l1}{lc($parent)}->seq_id() ) {
warn "WARNING l2 and l1 features not on same seq_id @ ".$feature->_tag_value("ID").
" level2 feature is on ".$feature->seq_id." sequence while ".
$omniscient->{'level1'}{$tag_l1}{lc($parent)}->_tag_value("ID").
" level1 feature is on ".$omniscient->{'level1'}{$tag_l1}{lc($parent)}->seq_id."\n";
}
}
}
}

# /!\ $feature must have a parent if not level1
# Keep track to recover from sequential locus tag share whith feature saved in Omniscient
sub _save_common_tag_value_top_feature{
Expand All @@ -1003,7 +1021,7 @@ sub _save_common_tag_value_top_feature{
if($feature->has_tag($tag)){
$locusName=lc($feature->_tag_value($tag)); #get the value

if ( !( exists_keys ( $locusTAG_uniq, ('topfeature', $locusName, 'level1') ) ) and ($level eq 'level2') ) {
if ( !( exists_keys ( $locusTAG_uniq, ('topfeature', $locusName, 'level1') ) ) and ($level eq 'level1') ) {
$locusTAG_uniq->{'topfeature'}{$locusName}{'level1'}{'ID'} = lc($feature->_tag_value('ID'));
last;
}
Expand Down Expand Up @@ -1298,7 +1316,7 @@ sub _create_ID{
$key=$primary_tag;
}

my $uID= $id ? $id : $key."-1";
my $uID = $id ? $id : $key."-1";

while( exists_keys($uniqID, (lc ($uID) ) )){ #loop until we found an uniq tag
$miscCount->{$key}++;
Expand Down
6 changes: 4 additions & 2 deletions lib/AGAT/OmniscientTool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,9 @@ sub check_level1_positions {
$check_existence_feature_l2=1;

my $extrem_start_A=1000000000000;
my $extrem_end_A=0;
my $extrem_end_A=0;
foreach my $feature ( @{$hash_omniscient->{'level2'}{$tag_level2}{$id_l1}}) {
if( $feature->seq_id eq $feature_l1->seq_id ){
my $start=$feature->start();
my $end=$feature->end();
if ($start < $extrem_start_A){
Expand All @@ -2220,7 +2221,8 @@ sub check_level1_positions {
if($end > $extrem_end_A){
$extrem_end_A=$end;
}
}
}
}

if ($extrem_start_A < $extrem_start){
$extrem_start=$extrem_start_A;
Expand Down

0 comments on commit 601743d

Please sign in to comment.