-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdeal_augustus.pl
executable file
·142 lines (126 loc) · 4.61 KB
/
deal_augustus.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
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use fileSunhh;
use LogInforSunhh;
my %opts;
GetOptions(\%opts,
"help!",
"augDir:s", # /data/Sunhh/src/Annot/maker/maker/exe/augustus
"copy_species:s",
);
sub usage {
print <<HH;
################################################################################
# perl $0
# -help
#
# Basic settings:
# -augDir [/data/Sunhh/src/Annot/maker/maker/exe/augustus/]
# If not given,
# first check from \$AUGUSTUS_CONFIG_PATH
# then check if directory '/data/Sunhh/src/Annot/maker/maker/exe/augustus' exist.
# Will report warn if not found any.
#
# -copy_species [SpeciesName1,SpeciesName2] Copy SpeciesName1 to SpeciesName2.
################################################################################
HH
exit 1;
}
$opts{'help'} and &usage();
(keys %opts) == 0 and &usage();
# Basic settings.
my %infor;
$infor{'augDir'} = &_getAugDir();
# Invoke functiosn.
©Species() if ( defined $opts{'copy_species'} );
# Sub functions.
sub copySpecies {
my @spec = split(/,/, $opts{'copy_species'});
s!\s!!g foreach (@spec);
@spec == 2 or &stopErr("[Err] Please use two species only.\n");
©Spec1to2($spec[0], $spec[1]);
return undef();
}
# Supporting functions.
=head1 _getAugDir()
First check $opts{'augDir'}, then check $ENV{'AUGUSTUS_CONFIG_PATH'},
then check /data/Sunhh/src/Annot/maker/maker/exe/augustus/,
fail if none work.
=cut
sub _getAugDir {
defined $opts{'augDir'} and &fileSunhh::_chkExist($opts{'augDir'}) and return $opts{'augDir'};
if ( defined $ENV{'AUGUSTUS_CONFIG_PATH'} and $ENV{'AUGUSTUS_CONFIG_PATH'} ne '' and -d "$ENV{'AUGUSTUS_CONFIG_PATH'}/../") {
return "$ENV{'AUGUSTUS_CONFIG_PATH'}/../";
} elsif ( -d '/data/Sunhh/src/Annot/maker/maker/exe/augustus/' ) {
return '/data/Sunhh/src/Annot/maker/maker/exe/augustus/';
} else {
&stopErr("[Err] Please provide augustus directory -augDir\n");
}
}# sub _getAugDir()
=head1 copySpec1to2($specFrom, $specTo, 'augCfgPath'=>"$augDir/config/")
Return : 1 if failed.
=cut
sub copySpec1to2 {
my $sp1 = shift;
my $sp2 = shift;
my %parm = @_;
unless ( defined $parm{'augCfgPath'} ) {
$parm{'augCfgPath'} = "$infor{'augDir'}/config/";
}
-d "$parm{'augCfgPath'}/species/$sp2/" and &stopErr("[Err] $parm{'augCfgPath'}/species/$sp2/ already exists.\n");
fileSunhh::_dircopy( "$parm{'augCfgPath'}/species/$sp1/", "$parm{'augCfgPath'}/species/$sp2/" );
my $fpath1 = &_speciesCfgFiles($sp1);
my $fpath2 = &_speciesCfgFiles($sp2);
for my $tk (keys %{$fpath1->{'base'}}) {
my $f1 = $parm{'augCfgPath'} . '/species/' . $sp1 . '/' . $fpath1->{'base'}{$tk};
my $f2 = $parm{'augCfgPath'} . '/species/' . $sp2 . '/' . $fpath2->{'base'}{$tk};
my $f2old = $parm{'augCfgPath'} . '/species/' . $sp2 . '/' . $fpath1->{'base'}{$tk};
-f $f2old or do { &tsmsg("[Wrn] $f2old not exist.\n"); next; };
open F,'<',"$f2old" or die;
open O,'>',"$f2" or die;
while (<F>) {
s!(\s)$sp1!$1$sp2!o;
print O $_;
}
close O; close F;
unlink($f2old);
}
for my $tk (keys %{$fpath1->{'more'}}) {
my $f1 = $parm{'augCfgPath'} . '/species/' . $sp1 . '/' . $fpath1->{'more'}{$tk};
my $f2 = $parm{'augCfgPath'} . '/species/' . $sp2 . '/' . $fpath2->{'more'}{$tk};
my $f2old = $parm{'augCfgPath'} . '/species/' . $sp2 . '/' . $fpath1->{'more'}{$tk};
-f $f2old or do { &tsmsg("[Wrn] $f2old not exist.\n"); next; };
open F,'<',"$f2old" or die;
open O,'>',"$f2" or die;
while (<F>) {
s!(\s)$sp1!$1$sp2!o;
print O $_;
}
close O; close F;
unlink($f2old);
}
return undef();
}# sub copySpec1to2()
=head1 _speciesCfgFiles($speciesName)
Return : \%file_paths
{'base'}{'...'} basic files from generic species.
{'more'}{'...'} more files including .pbl files.
=cut
sub _speciesCfgFiles {
my $spName = shift;
my %paths;
$paths{'base'}{'cfgfilename'} = $spName . '_parameters.cfg';
$paths{'base'}{'weightfilename'} = $spName . '_weightmatrix.txt';
$paths{'base'}{'metafilename'} = $spName . '_metapars.cfg';
$paths{'base'}{'metautrfilename'} = $spName . '_metapars.utr.cfg';
$paths{'base'}{'ovlpfilename'} = $spName . '_ovlp_len.pbl';
$paths{'base'}{'transshadowfilename'} = $spName . '_trans_shadow_bacterium.pbl';
$paths{'more'}{'exonpblfilename'} = $spName . '_exon_probs.pbl';
$paths{'more'}{'utrpblfilename'} = $spName . '_utr_probs.pbl';
$paths{'more'}{'intronpblfilename'} = $spName . '_intron_probs.pbl';
$paths{'more'}{'igenicpblfilename'} = $spName . '_igenic_probs.pbl';
# Anything else?
return \%paths;
}# sub _speciesCfgPath()