-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRNAfinderFileForMenu.pir
219 lines (192 loc) · 8.84 KB
/
RNAfinderFileForMenu.pir
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
#
# This class represents the RNAfinderFileforMenu used by RNAfinder;
# That file stores foreach RNA model the followed information :
#
# Name = rnpB | Name of model used in order to run RNAfinder
# |
# # rnpB (RNase P RNA), generale: | A comment that appears only in the file RNAfinderFileForMenu
# Commands | Start of commands list
# Item | List used for run erpin one time
# erpin_arg = "1,10 -add 2 4 -add 3 5 -add 8 9 -logzero -5 -cutoff 2.5 12 17" | erpin arguments
# model_name = rnpB-mito.epn | name of model file used by erpin
# comment = "" | Comment that must appear in RNAfinder Usage
# EndItem |
# EndCommans | End of Commands list
#
# For tRNA user should add the position of anticodon for each item.
# To do this add this line :
# pos_ac = "13"
# Between "Item" and "EndItem" if the anticodon is the 13 element of the model.
#
- PerlClass PirObject::RNAfinderFileForMenu
- InheritsFrom PirObject
- FieldsTable
# Field name Sing/Array/Hash Type Comments
#---------------------- --------------- --------------- -----------------------
filename single string optional
List array <RNAfinderMenuList> Menu list
- EndFieldsTable
- Methods
our $RCS_VERSION='$Id: RNAfinderFileForMenu.pir,v 1.8 2011/03/18 19:21:38 nbeck Exp $';
our ($VERSION) = ($RCS_VERSION =~ m#,v ([\w\.]+)#);
# Sample format of text file
#
# Used for identification of tRNA
# Name = tRNA
# comment = tRNA_model
# order = 1
#
# Item
# erpin_arg = "-1,19 -add 1 17 18 -add 11 12 14 -add 2 3 5 7 -logzero -5"
# cutoff = 2.9 8 30
# model_file = tRNA.epn
# pos_ac = 13
# comment = tRNA
# EndItem
#
sub ImportFromTextFile {
my $self = shift;
my $filename = shift;
my $class = ref($self) || $self;
$self = $class->new() if $self eq $class;
$self->set_filename($filename);
my $fh = new IO::File "<$filename"
or die "Cannot read from file '$filename': $!\n";
my @file = <$fh>;
$fh->close();
my $RNAfinderMenuList = {};
my $count_line = 0;
while (@file) {
my $line = shift(@file);
$count_line++;
next if $line =~ m/^\s*$|^\s*#/;
# Expects "genename"
die "Error: unparsable line '$count_line' in '$filename' (expected \"name=\"), got:\n$line"
if ($line !~ m/^\s*name?\s*=\s*(\w+)\s*$/i);
my $name = $1; # potentially a list, like "abc,def"
$name =~ s/\s+//;
die "Error: genename '$name' line '$count_line' seen more than once in file '$filename'.\n"
if exists $RNAfinderMenuList->{lc($name)};
# Expects "comment"
while (@file && $file[0] =~ m/^\s*$|^\s*#/){
shift(@file);
$count_line++;
}
die "Error: unparsable line '$count_line' in '$filename' (expected \"comment=\"), got:\n$line"
if ($file[0] !~ m/^\s*comment?\s*=\s*(.+)\s*$/i);
my $ModelComment = $1;
shift(@file);
# Expect "order"
while (@file && $file[0] =~ m/^\s*$|^\s*#/){
shift(@file);
$count_line++;
}
die "Error: unparsable line '$count_line' in '$filename' (expected \"order=\"), got:\n$line"
if ($file[0] !~ m/^\s*order?\s*=\s*(\w+)\s*$/i);
my $Order = $1;
shift(@file);
$count_line++;
# Expect "ToFus"
while (@file && $file[0] =~ m/^\s*$|^\s*#/){
shift(@file);
$count_line++;
}
die "Error: unparsable line '$count_line' in '$filename' (expected \"ToFus=\"), got:\n$line"
if ($file[0] !~ m/^\s*ToFus?\s*=\s*(.+)\s*$/i);
my $ToFus = $1;
my $arrayToFus = &CheckToFusList($ToFus);
shift(@file);
$count_line++;
my $List = new PirObject::RNAfinderMenuList(
Set => {},
OriName => $name,
Comment => $ModelComment,
Order => $Order,
ToFus => $arrayToFus,
);
my $ItemSet = $List->get_Set();
my $Item_counter = 0;
while (@file) {
while (@file && $file[0] =~ m/^\s*$|^\s*#/){
shift(@file);
$count_line++;
}
last if !@file;
$file[0] =~ s/\n$//;
last if $file[0] !~ m/^\s*Item\s*$/i;
shift(@file);
$count_line++;
$Item_counter++;
my $autorized_fields = ["erpin_arg","model_file","label","pos_ac","comment","module","cutoff","gap_to_end","comment_for_MFa","to_comment","at_cutoff","evalue_cutoff"];
my $Item = new PirObject::RNAfinderItem();
while (@file && $file[0] !~ m/^\s*EndItem\s*$/i) {
my $line_b = shift(@file);
$count_line++;
chomp($line_b);
next if $line_b eq "";
die "Line '$line_b' must begin with 'field =', for autorized fields see in '$filename', line '$count_line'.\n"
if $line_b !~ m/^\s*\w+\s*=/;
my ($field,$value) = ($1,$2) if $line_b =~ m/^\s*(\w+)\s*=(.+)/;
$value =~ s/^\s*//;
$value =~ s/\s*$//;
die "Field : '$field' line '$count_line' isn't autorized, line '$count_line'.\n"
if !(grep(/^$field/, @$autorized_fields));
$Item->set_cutoff($value) if $field eq "cutoff";
$Item->set_erpinArg($value) if $field eq "erpin_arg";
$Item->set_modelFile($value) if $field eq "model_file";
$Item->set_Label($value) if $field eq "label";
$Item->set_AcId($value) if $field eq "pos_ac";
$Item->set_module($value) if $field eq "module";
$Item->set_comment($value) if $field eq "comment";
$Item->set_gaptoend($value) if $field eq "gap_to_end";
$Item->set_commentForMFa($value) if $field eq "comment_for_MFa";
$Item->set_toComment($value) if $field eq "to_comment";
$Item->set_atCutoff($value) if $field eq "at_cutoff";
$Item->set_evalueCutoff($value) if $field eq "evalue_cutoff";
}
unshift(@file,"(EOF)\n") unless @file; # for error message
my $endcomkeyword = shift(@file);
$count_line++;
die "Error: unparsable line '$count_line' in '$filename' (expected \"EndItem\" keyword), got:\n$endcomkeyword."
unless $endcomkeyword =~ m/^\s*EndItem\s*$/i;
die "Item$Item_counter for block '$name' haven't erpin arguments, line '$count_line'.\n" if !($Item->get_erpinArg());
die "Item$Item_counter for block '$name' haven't model file, line'$count_line'\n." if !($Item->get_modelFile());
die "Item$Item_counter for block '$name' haven't comment, line '$count_line'.\n" if !($Item->get_comment());
$ItemSet->{$Item_counter} = $Item;
}
$RNAfinderMenuList->{lc($name)} = $List;
}
$self->set_List($RNAfinderMenuList);
$self;
}
sub CheckToFusList {
my $toFus_str = shift;
my $cnt_name_and_item = {};
$toFus_str =~ s/\s+//g;
my $arrayToFus = ();
if ($toFus_str eq "0") {
push(@$arrayToFus,$toFus_str);
}
else {
my @split_toFus_str = split(/;/,$toFus_str);
foreach my $fusion (@split_toFus_str) {
my @split_fus = split(/,/,$fusion);
my $name = pop(@split_fus);
die "Wrong format of last element for fusion : '$fusion'.\nExpect a string without space.\n"
if $name !~ m/^\w+$/;
$cnt_name_and_item->{$name}++;
foreach my $Item (@split_fus) {
die "Wrong format of element $Item for fusion : '$fusion'.\nExpect a number\n"
if $Item !~ m/\d+/;
$cnt_name_and_item->{$Item}++;
}
push(@$arrayToFus,$fusion);
}
}
foreach my $cnt (keys %$cnt_name_and_item) {
my $value = $cnt_name_and_item->{$cnt};
next if $value ==1;
die "ToFus string '$toFus_str' have wrong format in RNAfinder.cfg\n";
}
return $arrayToFus;
}