~ubuntu-branches/ubuntu/vivid/horae/vivid

« back to all changes in this revision

Viewing changes to 0CPAN/STAR-Parser-0.59/bin/parseMulti.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2006-12-26 11:54:29 UTC
  • Revision ID: james.westby@ubuntu.com-20061226115429-kjuhf6h9w6bohlwj
Tags: upstream-063
ImportĀ upstreamĀ versionĀ 063

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/local/bin/perl
 
2
 
 
3
=head1 DESCRIPTION
 
4
 
 
5
  This script will attempt to parse all cif files in 
 
6
  a given directory and save the parsed binaries.
 
7
 
 
8
=head1 USAGE
 
9
 
 
10
  parseMulti.pl [-i <input dir> -r -s <size> -o <output dir> -f <filter dict> -l <log file> -c]
 
11
 
 
12
  Options:
 
13
 
 
14
  -i input directory
 
15
  -r recursively search all subdirectories
 
16
  -o output directory
 
17
  -f filter through dictionary
 
18
  -l log file
 
19
  -c compress the binaries
 
20
  -s size limit: skip files that are greater than <size> MB uncompressed 
 
21
 
 
22
  Comments:
 
23
 
 
24
  -i defaults to working directory if omitted
 
25
  -o defaults to working directory if omitted
 
26
  -l defaults to cifParse.log if omitted
 
27
 
 
28
=cut
 
29
 
 
30
use STAR::Parser;
 
31
use STAR::Filter;
 
32
use strict;
 
33
use Getopt::Std;
 
34
use vars qw( $opt_i $opt_r $opt_o $opt_f $opt_l $opt_c $opt_s ); 
 
35
 
 
36
getopt('iofls');
 
37
 
 
38
$opt_i or $opt_i = ".";
 
39
$opt_o or $opt_o = ".";
 
40
$opt_l or $opt_l = "cifParse.log";
 
41
 
 
42
my $compress = "/bin/compress -f";
 
43
my $uncompress = "/bin/uncompress -f";
 
44
 
 
45
my @tmp;             # temporary file list (find command output)
 
46
my @files;           # file list
 
47
my $file;            # one file
 
48
my $uncompressed;    # uncompressed file
 
49
my $status;          # status of system call
 
50
my $id;              # pdbid
 
51
my $parse_opt;       # parse options
 
52
my $data;            # parsed data object
 
53
my $filtered;        # filtered data object
 
54
my $dict;            # dictionary
 
55
my $date;            # date and time
 
56
my $size;            # size limit for files (uncompressed, in MB)
 
57
my $pwd;             # working directory
 
58
 
 
59
if ( -e "temp.cif.Z" or -e "temp.cif" ) {
 
60
    die "Please remove file(s) temp.cif* from working directory";
 
61
}
 
62
 
 
63
$pwd = `pwd`;
 
64
 
 
65
# open log file 
 
66
#
 
67
open (LOG, ">$opt_l");
 
68
print LOG "Working directory: $pwd";
 
69
print LOG "Directory of cif files: $opt_i\n";
 
70
print LOG "Subdirectories included? ", $opt_r?"yes":"no","\n";
 
71
print LOG "Size limit for uncompressed files? ", $opt_s?"$opt_s MB":"none", "\n";
 
72
print LOG "Dictionary used for filtering: ", $opt_f?"$opt_f":"none","\n";
 
73
print LOG "\n";
 
74
 
 
75
# open dictionary
 
76
#
 
77
if ( $opt_f ) {
 
78
    $opt_f =~ /\.cob/ or die "Dictionary must be a binary (.cob file)";
 
79
    $dict = STAR::Dictionary->new( $opt_f );
 
80
}
 
81
 
 
82
# assemble file list
 
83
#
 
84
if ( $opt_r ) {
 
85
    @tmp = `find $opt_i -name "*.cif" -print`;
 
86
    @tmp = ( @tmp, `find $opt_i -name "*.cif.Z" -print` );
 
87
}
 
88
else {
 
89
    @tmp = `ls -1 $opt_i/*.cif $opt_i/*.cif.Z`;
 
90
}
 
91
foreach ( @tmp ) {
 
92
    /^(.*\.cif[\.Z]*)/;
 
93
    push @files, $1;
 
94
}
 
95
 
 
96
$date = `date`;
 
97
print LOG "Started parsing: $date";
 
98
 
 
99
# process all files
 
100
#
 
101
foreach $file ( sort @files ) {
 
102
 
 
103
    $file =~ /(....)\.cif/;
 
104
    $id = $1;
 
105
    
 
106
    if ( $file =~ /^(.*)\.Z/ ) {
 
107
        $uncompressed = $1;
 
108
        eval{ system( "cp -f $file temp.cif.Z; $uncompress temp.cif.Z" ); };
 
109
        if ( ! $@ ) {
 
110
            &parse( "temp.cif", $file );
 
111
        }
 
112
        else {
 
113
            print LOG "Could not uncompress $file\n";
 
114
        }
 
115
    }
 
116
    else {
 
117
        &parse( $file, $file );
 
118
    }
 
119
}
 
120
 
 
121
eval{ system( "/bin/rm -f temp.cif" ); };
 
122
 
 
123
$date = `date`;
 
124
print LOG "Finished parsing: $date";
 
125
 
 
126
close LOG;        
 
127
exit(0);
 
128
 
 
129
sub parse {
 
130
 
 
131
    if ( $opt_s ) {
 
132
        $size = -s "$_[0]";
 
133
        if ( $size > ( $opt_s * 1048576 ) ) {
 
134
            print LOG "File $_[1] ($size bytes uncompressed) exceeds $opt_s MB size limit\n";
 
135
            return;
 
136
        }
 
137
    }
 
138
 
 
139
    eval { ( $data ) = STAR::Parser->parse(-file=>$_[0]); };
 
140
 
 
141
    if ( $@ ) {
 
142
        print LOG "Could not parse $_[1]\n";
 
143
        return;
 
144
    }
 
145
    else {
 
146
        print LOG "Parsed $_[1]\n";
 
147
        if ( $opt_f ) {
 
148
            eval { $filtered = STAR::Filter->filter_through_dict(-data=>$data, -dict=>$dict); };
 
149
            if ( $@ ) {
 
150
                print LOG "Could not filter $_[0]\n";
 
151
                return;
 
152
            }
 
153
            else {
 
154
                $filtered->store( "$opt_o/$id.cob" );
 
155
            }
 
156
        }
 
157
        else {
 
158
            $data->store( "$opt_o/$id.cob" );
 
159
        }
 
160
    }
 
161
 
 
162
    if ( $opt_c ) {
 
163
        eval{ system( "$compress $opt_o/$id.cob" ); };
 
164
        if ( $@ ) {
 
165
            print LOG "Could not compress $opt_o/$id.cob\n";
 
166
        }
 
167
    }
 
168
    return;
 
169
}
 
170
               
 
171