-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_visualizations.pl
executable file
·157 lines (131 loc) · 4.15 KB
/
create_visualizations.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
#!/usr/bin/perl
my $name = "create_visualizations.pl";
my $version = "0.7.6";
my $updated = "2022-09-03";
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
use File::Basename;
use Cwd qw(abs_path);
use File::Path qw(make_path);
my $usage = << "EXIT";
NAME ${name}
VERSION ${version}
UPDATED ${updated}
SYNOPSIS Creates ChimeraX visual comparisons between .pdb structures
and matches found with QueGO
USAGE ${name} \\
-m RESULTS/compiled_results.tsv \\
-u /media/FatCat_1/julian/QueGO/UniProt \\
-p /media/FatCat_1/Microsporidia/Intestinalis/3DFI/FOLDING/ALPHAFOLD_3D_PARSED
OPTIONS
-m (--match) Foldseek/GESAMT match file parsed by organize_results.pl
-p (--prov) Directory containing provided .pdb files
-u (--uni) Directory containing UniProt scrap .pdb files
-o (--outdir) Output directory for ChimeraX sessions [Default: ./3D_Visualizations]
EXIT
die "\n\n$usage\n\n" unless @ARGV;
my $match_file;
my @provided_struct;
my $uniprot_struct;
my $outdir = './3D_Visualizations';
GetOptions(
'm|match=s' => \$match_file,
'p|prov=s@{1,}' => \@provided_struct,
'u|uni=s' => \$uniprot_struct,
'o|out=s' => \$outdir,
);
my ($filename,$dir) = fileparse($0);
my $script = "$dir/chimerax_session_creator.py";
unless (-d $outdir){
make_path($outdir,{mode => 0755}) or die "\n[ERROR]\tUnable to create $outdir: $!\n";
}
my %provided_struct;
foreach my $provided (@provided_struct){
my ($dirname) = $provided =~ /\/(\w+)\/?$/;
$provided_struct{$dirname} = $provided;
}
##
my %results;
open IN, "<", $match_file or die "Unable to read from $match_file: $!\n";
my $prot_name;
while (my $line = <IN>){
chomp($line);
if ($line =~ /^## (.*)\t/){
$prot_name = $1;
$prot_name =~ tr/ .,'"()/_/;
make_path("$outdir/$prot_name",{mode => 0755});
}
elsif(($prot_name) && ($line =~ /^\w/)){
my ($locus,$prev_annot,$seq_score,$seq_access,$fs_score,$fs_access,$fs_db,$fs_model,$gs_score,$gs_access,$gs_db,$gs_model) = split("\t",$line);
if ($fs_score ne "-"){
my $db_loc = $provided_struct{$fs_db};
my $provided_pdb = $locus;
unless ($fs_model eq "-"){
$provided_pdb .= "-".$fs_model;
}
push(@{$results{$prot_name}},[$db_loc,$provided_pdb,$fs_access]);
}
elsif ($gs_score ne "-"){
my $db_loc = $provided_struct{$gs_db};
my $provided_pdb = $locus;
unless ($gs_model eq "-"){
$provided_pdb .= "-".$gs_model;
}
push(@{$results{$prot_name}},[$db_loc,$provided_pdb,$gs_access]);
}
}
}
close IN;
foreach my $protein (keys(%results)){
print ("Working on visualizations for $protein...\n");
foreach my $match ((@{$results{$protein}})){
my ($db_loc,$provided_pdb,$match_pdb) = @{$match};
my $temp_provided_pdb = "$outdir/$protein/$provided_pdb.temp.pdb";
# print($temp_provided_file."\n");
my $provided_pdbs = `ls $db_loc/$provided_pdb*.pdb*`;
my @provided_pdbs = split("\n",$provided_pdbs);
if ($provided_pdbs[0] =~ /\.gz$/){
system ("zcat $db_loc/$provided_pdb* > $temp_provided_pdb");
}
else{
system ("cat $db_loc/$provided_pdb* > $temp_provided_pdb");
}
my $temp_match_pdb = "$outdir/$protein/$match_pdb.temp.pdb";
my $match_pdbs = `ls $uniprot_struct/$match_pdb*.pdb*`;
my @match_pdbs = split("\n",$match_pdbs);
if ($match_pdbs[0] =~ /\.gz$/){
system ("zcat $uniprot_struct/$match_pdb*.pdb* > $temp_match_pdb");
}
else{
system ("cat $uniprot_struct/$match_pdb*.pdb* > $temp_match_pdb");
}
my $cxs_name = "$outdir/$protein/${provided_pdb}_${match_pdb}.cxs";
if (-e $cxs_name) { print " Alignment between $provided_pdb and $match_pdb found. Skipping alignment...\n"; }
else {
# ChimeraX API calling
print " Aligning $provided_pdb to $match_pdb with ChimeraX\n";
system (
"chimerax 1>/dev/null --nogui $script \\
-p $temp_provided_pdb \\
-m $temp_match_pdb \\
-o $outdir/$protein\n
") == 0 or checksig();
}
}
system ("rm $outdir/$protein/*.temp.pdb");
}
### Subroutine(s)
sub checksig {
my $exit_code = $?;
my $modulo = $exit_code % 255;
print "\nExit code = $exit_code; modulo = $modulo \n";
if ($modulo == 2) {
print "\nSIGINT detected: Ctrl+C => exiting...\n";
exit(2);
}
elsif ($modulo == 131) {
print "\nSIGTERM detected: Ctrl+\\ => exiting...\n";
exit(131);
}
}