-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathIPR2latex.pl
executable file
·90 lines (79 loc) · 2.18 KB
/
IPR2latex.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
#!/usr/bin/perl
# Script: toLatex.pl
# Description:
# Author: Steven Ahrendt
# email: [email protected]
# Date: 09.13.2014
##################################
use warnings;
use strict;
use Data::Dumper;
use Getopt::Long;
use lib '/rhome/sahrendt/Scripts';
#####-----Global Variables-----#####
my $input;
my %results; # contains all protein domains, keys as prot IDs w/ multiple domains
my ($help,$verb);
GetOptions ('i|input=s' => \$input,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "Usage: toLatex.pl -i input\n\n";
die $usage if $help;
die "No input.\n$usage" if (!$input);
#####-----Main-----#####
my $filename = (split(/\./,$input))[0];
open(my $fh, "<", $input);
while(my $line = <$fh>)
{
next if ($line !~ /Pfam/);
chomp $line;
my ($protID,$MD5,$len,$analysis,$sigID,$desc,$start,$stop,$score,$status,$date) = split(/\t/,$line);
$results{$protID}{'Len'} = $len;
push(@{$results{$protID}{'Dom'}}, join(":",$sigID,$start,$stop));
}
close($fh);
if($verb)
{
# print Dumper \%results;
foreach my $key (sort keys %results)
{
foreach my $dom(@{$results{$key}{'Dom'}})
{
print "$key\t$dom\n";
}
}
}
else
{
## Write to .tex file
open(my $out,">","$filename\.tex");
writePreamble($out,$filename);
foreach my $key (sort keys %results)
{
print $out "\\begin{pmbdomains}[name=$key,x unit=0.2mm,residues per line=1000]{$results{$key}{'Len'}}\n";
foreach my $domain (@{$results{$key}{'Dom'}})
{
my ($dID,$dStart,$dStop) = split(/:/,$domain);
print $out " \\addfeature[description=$dID]{domain}{$dStart}{$dStop}\n";
}
print $out "\\end{pmbdomains}\n";
}
print $out "\\end{document}\n";
}
warn "Done.\n";
exit(0);
#####-----Subroutines-----#####
sub writePreamble {
my $fh = shift @_;
my $data_name = shift @_;
print $fh "%%%%%%%%%%%%%%%%%%%%\n";
print $fh "%% pgfmolbio $data_name %%\n";
print $fh "%%%%%%%%%%%%%%%%%%%%\n";
print $fh "%% http://www.ctan.org/pkg/pgfmolbio\n";
print $fh "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
print $fh "\n";
print $fh "\\documentclass{article}\n";
print $fh "\\usepackage[domains]{pgfmolbio}\n";
print $fh "\n";
print $fh "\\begin{document}\n";
}