-
Notifications
You must be signed in to change notification settings - Fork 52
/
agat_sp_add_attribute_shortest_intron_size.pl
executable file
·226 lines (177 loc) · 7.14 KB
/
agat_sp_add_attribute_shortest_intron_size.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env perl
use strict;
use warnings;
use POSIX qw(strftime);
use File::Basename;
use Carp;
use Getopt::Long;
use IO::File;
use Pod::Usage;
use AGAT::AGAT;
my $header = get_agat_header();
my $config;
my $opt_file;
my $opt_output=undef;
my $verbose=undef;
my $opt_help = 0;
my @copyARGV=@ARGV;
if ( !GetOptions( 'f|gff|ref|reffile=s' => \$opt_file,
'o|out|output=s' => \$opt_output,
'v|verbose!' => \$verbose,
'c|config=s' => \$config,
'h|help!' => \$opt_help ) )
{
pod2usage( { -message => 'Failed to parse command line',
-verbose => 1,
-exitval => 1 } );
}
# Print Help and exit
if ($opt_help) {
pod2usage( { -verbose => 99,
-exitval => 0,
-message => "$header\n" } );
}
if ( ! defined($opt_file) ) {
pod2usage( {
-message => "$header\nMust specify at least 1 parameters:\nReference data gff3 file (--gff)\n",
-verbose => 0,
-exitval => 1 } );
}
# --- Manage config ---
$config = get_agat_config({config_file_in => $config});
# #######################
# # START Manage Option #
# #######################
my $ostreamReport_filename;
if (defined($opt_output) ) {
my ($filename,$path,$ext) = fileparse($opt_output,qr/\.[^.]*/);
$ostreamReport_filename=$path.$filename."_report.txt";
}
my $gffout = prepare_gffout($config, $opt_output);
my $ostreamReport = prepare_fileout($ostreamReport_filename);
my $string1 = strftime "%m/%d/%Y at %Hh%Mm%Ss", localtime;
$string1 .= "\n\nusage: $0 @copyARGV\n\n";
print $ostreamReport $string1;
if($opt_output){print $string1;}
#######################
# MAIN #
# >>>>>>>>>>>>>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
######################
### Parse GFF input #
print "Reading ".$opt_file,"\n";
my ($hash_omniscient, $hash_mRNAGeneLink) = slurp_gff3_file_JD({ input => $opt_file,
config => $config });
print("Parsing Finished\n\n");
### END Parse GFF input #
#########################
my $nb_cases_l1=0;
my $nb_cases_l2=0;
my $tag = "shortest_intron";
######################
### Parse GFF input #
foreach my $tag_l1 (keys %{$hash_omniscient->{'level1'}}){
foreach my $id_l1 (keys %{$hash_omniscient->{'level1'}{$tag_l1}}){
my $feature_l1 = $hash_omniscient->{'level1'}{$tag_l1}{$id_l1};
my $shortest_intron=undef;
foreach my $tag_l2 (keys %{$hash_omniscient->{'level2'}}){
if (exists_keys($hash_omniscient,('level2',$tag_l2,$id_l1) ) ){
my $shortest_intron_l2=undef;
foreach my $feature_l2 (@{$hash_omniscient->{'level2'}{$tag_l2}{$id_l1}}){
my $level2_ID = lc($feature_l2->_tag_value('ID'));
if ( exists_keys($hash_omniscient,('level3','exon',$level2_ID)) ){
my $counterL3=-1;
my $indexLast = $#{$hash_omniscient->{'level3'}{'exon'}{$level2_ID}};
my @sortedList = sort {$a->start <=> $b->start} @{$hash_omniscient->{'level3'}{'exon'}{$level2_ID}};
foreach my $feature_l3 ( @sortedList ){
$counterL3++;
#Manage Introns## from the second intron to the last (from index 1 to last index of the table sortedList) ## We go inside this loop only if we have more than 1 feature.
if($counterL3 > 0 and $counterL3 <= $indexLast){
my $intronSize = $sortedList[$counterL3]->start - $sortedList[$counterL3-1]->end;
if(! $shortest_intron_l2){
$shortest_intron_l2 = $intronSize;
}
elsif( $intronSize < $shortest_intron_l2){
$shortest_intron_l2 = $intronSize;
}
}
}
if($shortest_intron_l2){ # To avoid single exon gene that do not have introns
$feature_l2->add_tag_value($tag, $shortest_intron_l2);
$nb_cases_l2++;
if(! $shortest_intron){
$shortest_intron = $shortest_intron_l2;
}
elsif( $shortest_intron_l2 < $shortest_intron){
$shortest_intron = $shortest_intron_l2;
}
}
}
}
}
}
if($shortest_intron){
$feature_l1->add_tag_value($tag, $shortest_intron);
$nb_cases_l1++;
}
}
}
my $toprint = "$nb_cases_l1 $tag flags/attributes added to level1 features and $nb_cases_l2 $tag flags/attributes added to level2 features. The value of the attribute is size of the shortest exon found.\n";
print $ostreamReport $toprint;
if($opt_output){print $toprint;}
print_omniscient( {omniscient => $hash_omniscient, output => $gffout} );
#########################
######### END ###########
#########################
#######################################################################################################################
####################
# methods #
################
##############
############
##########
########
######
####
##
__END__
=head1 NAME
agat_sp_add_attribute_shortest_intron_size.pl
=head1 DESCRIPTION
The script add the attribute <shortest_intron> to each gene and rna, which will hold the size of the shortest exon in bp.
=head1 SYNOPSIS
agat_sp_add_attribute_shortest_intron_size.pl --gff infile --out outfile
agat_sp_add_attribute_shortest_intron_size.pl --help
=head1 OPTIONS
=over 8
=item B<--gff>, B<-f>, B<--ref> or B<-reffile>
STRING: Input GTF/GFF file.
=item B<--out>, B<--output> or B<-o>
STRING: Output gff3 file where the result will be printed.
=item B<-v>
BOLEAN: Verbose for debugging purpose.
=item B<-c> or B<--config>
String - Input agat config file. By default AGAT takes as input agat_config.yaml file from the working directory if any,
otherwise it takes the orignal agat_config.yaml shipped with AGAT. To get the agat_config.yaml locally type: "agat config --expose".
The --config option gives you the possibility to use your own AGAT config file (located elsewhere or named differently).
=item B<--help> or B<-h>
Display this helpful text.
=back
=head1 FEEDBACK
=head2 Did you find a bug?
Do not hesitate to report bugs to help us keep track of the bugs and their
resolution. Please use the GitHub issue tracking system available at this
address:
https://github.com/NBISweden/AGAT/issues
Ensure that the bug was not already reported by searching under Issues.
If you're unable to find an (open) issue addressing the problem, open a new one.
Try as much as possible to include in the issue when relevant:
- a clear description,
- as much relevant information as possible,
- the command used,
- a data sample,
- an explanation of the expected behaviour that is not occurring.
=head2 Do you want to contribute?
You are very welcome, visit this address for the Contributing guidelines:
https://github.com/NBISweden/AGAT/blob/master/CONTRIBUTING.md
=cut
AUTHOR - Jacques Dainat