-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICM_Load.pl
165 lines (152 loc) · 4.34 KB
/
ICM_Load.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
#!/usr/bin/env perl
#use Cwd qw(abs_path);
# Define I/O && initialize #
$info = "\nICM_Load.pl opens and rename all files within a given folder into ICM. It will need the full directory path. \n\t(IE: ./ICM_Load.pl /home/server/ICM_FOLDER/ [new_name])";
$input = "\nUsage\: ICM_Load.pl [Folder/Of/.ob/Files] [new-name]\n (take away the [] when using this)
\t[Folder/Of/.ob/Files]\t\tFolder to the .ob files\n\t[new-name]\t\tNew names due to ICM rename request
";
# Set default values that can be overwritten #
$directory = $ENV{'PWD'};
$icm_home = "~/icm-3.7-2b/";
$rname = "New-Name";
# Get flags #
if((@ARGV))
{
if($#ARGV!=1)
{
$help = 1;
if($#ARGV<1)
{
print "\nInvalid Usage, please give the name of the project to rename to."
}
else
{
print "\nInvalid Usage, Please follow all usage rules.\n";
}
}
else
{
for ($i=0; $i<=$#ARGV; $i++)
{
$flag = $ARGV[$i];
chomp $flag;
if($flag eq "-h")
{
$help = 1;
last;
}
else
{
if ($i == 0)
{
$directory = $ARGV[$i];
}
elsif ($i == 1)
{
$rname = $ARGV[$i];
}
else
{
$help = 1;
last;
}
}
}
}
}
else
{
print "$input\n";
exit();
}
# If user type the -h flag or put to many arguements, activate this help menu
if($help==1)
{
print "$info";
print "$input\n";
exit();
}
# Validing user's directory #
if (-e $ENV{'PWD'}."/".$directory)
{
$directory = $ENV{'PWD'}."/".$directory;
chomp $directory;
if((substr $directory, -1) ne "/")
{
$directory = $directory."/";
}
}
else
{
print "\nThe directory:$directory does not exist!!!\n\n";
exit;
}
# Reading the files in the directory and putting the files name into array DIR #
opendir(DIR,$directory);
my @obFiles;
$obFilesCount = 0;
while ( my $file = readdir(DIR) )
{
# Ignoring all the non files in the directory, IE: "." & ".."
next unless ( -f "$directory/$file" );
# Finding files with .ob extension
next unless ( $file =~ /\.ob$/ );
$obFiles[$obFilesCount] = $file;
$obFilesCount++;
}
closedir(DIR);
# This section is used to set up the working directory for loadICM.icm to be made #
chdir $directory;
# Create ICM script #
open(ICM,'>',"loadICM.icm") || die "Please give me output filename $!"; #adjust the ICMscript
#print ICM "#!$icm_home"."icm64 -g /home/server/icm-3.7-2b/_startup \n";
# This print portion is used to Hack ICM into loading its Library -Aingty Eung #
print ICM "l_commands = no \n";
print ICM "l_info=no \n";
print ICM "if((Version()~\"*WIN*\" & Version() !~ \"*WINCONSOLE*\" ) | Version()~\"*MacOSX-IL*\") set directory s_projectsDir \n";
print ICM "read table s_icmhome + \"WEBLINK.tab\" system \n";
print ICM "set property WEBLINK show delete edit off \n";
print ICM "set property WEBAUTOLINK show delete edit off \n";
print ICM "set property DATABASE show delete edit off \n";
print ICM "print \"Startup> Loading libraries..\" \n";
print ICM "read libraries \n";
print ICM "read libraries mute \n";
print ICM "l_info=yes \n";
print ICM "call _aliases \n";
print ICM "call _macro \n";
print ICM "loadResources \n";
print ICM "call _bioinfo test \n";
print ICM "call _rebel test \n";
print ICM "call _ligedit test \n";
print ICM "call _docking test \n";
print ICM "l_info=yes \n";
print ICM "if (l_info) printf \"\\n\" \n";
print ICM "if (Index(Version(),\"NoGraphics\")==0 & !Exist(gui)) then \n";
print ICM " print \" Hint> Run program with -g switch to start graphical user interface\" \n";
print ICM "endif \n";
print ICM "movie_init \n";
print ICM "print \"...ICM startup file executed...\" \n";
print ICM "l_info=yes \n";
print ICM "l_commands=yes \n";
# End of Hacked Print section #
$newNameCount = 0;
for($i=0; $i<=$#obFiles; $i++)
{
chomp $obFiles[$i];
if($obFiles[$i] eq "." || $obFiles[$i] eq "..")
{
next;
}
else
{
$newNameCount++;
print ICM "openFile '$directory$obFiles[$i]'\n";
print ICM "rename a_ Name(Name(\"$rname$newNameCount\" simple),object)\n";
}
}
close(ICM)||die $!;
# Ending creating ICM script #
# Running the command to load in files
system("$icm_home"."icm64 -g loadICM.icm && rm loadICM.icm");
# End running the command
###################################################################################################################################################################################