root/lib/ds_utility.pm

Revision 271, 3.8 kB (checked in by cholt, 2 months ago)

make runlog softmask instensitive for old data. Fix fgenesh xdef errors

Line 
1 #------------------------------------------------------------------------
2 #----                       datastore_utility                        ----
3 #------------------------------------------------------------------------
4 package ds_utility;
5
6 use strict;
7 use vars qw(@ISA @EXPORT $VERSION);
8 use Exporter;
9 use Datastore::MD5;
10 use File::Path;
11 use Cwd;
12 use URI::Escape;
13
14 @ISA = qw(
15        );
16
17 my $CWD = Cwd::getcwd();
18
19 #------------------------------------------------------------------------
20 #--------------------------- METHODS   ----------------------------------
21 #------------------------------------------------------------------------
22 sub new {
23    my $class = shift;
24    my @args = @_;
25    my $self = {};
26
27    bless ($self, $class);
28
29    $self->_initialize(@args);
30
31    return $self;
32 }
33 #------------------------------------------------------------------------
34 sub _initialize {
35    my $self = shift @_;
36    my %CTL_OPTIONS = %{shift @_};
37
38    $CWD = $CTL_OPTIONS{CWD};
39
40    my $out_base = $CTL_OPTIONS{out_base};
41    my $out_name = $CTL_OPTIONS{out_name};
42
43    $self->{root} = "$out_base/$out_name\_datastore";
44    $self->{log} = "$out_base/$out_name\_master_datastore_index.log";
45    
46    print STDERR "A data structure will be created for you at:\n".
47    $self->{root}."\n\n".
48    "To access files for individual sequences use the datastore index:\n".
49    $self->{log}."\n\n";
50
51    if($CTL_OPTIONS{datastore}){   
52       $self->{ds_object} = new Datastore::MD5('root' => $self->{root},
53                                               'depth' => 2
54                                              );
55    }
56    else{
57       $self->{ds_object} = undef;
58    }
59
60    #initialize the log
61    open(my $IN, ">", $self->{log});
62    close($IN);
63 }
64 #------------------------------------------------------------------------
65 sub get_index {
66    my $self = shift;
67    
68    return $self->{log};
69 }
70 #------------------------------------------------------------------------
71 sub get_root {
72    my $self = shift;
73    
74    return $self->{root};
75 }
76 #------------------------------------------------------------------------
77 sub mkdir {
78    my $self = shift;
79    my $id = shift;
80
81    my $safe_id = uri_escape($id,
82                             '\*\?\|\\\/\'\"\{\}\<\>\;\,\^\(\)\$\~\:'
83                            );
84
85    my $dir = $self->{root}."/".$safe_id;
86
87    if($self->{ds_object}){
88       $dir = $self->{ds_object}->id_to_dir($safe_id);
89       $self->{ds_object}->mkdir($safe_id) || die "ERROR: could not make datastore directory\n";
90    }
91    else{
92       File::Path::mkpath($dir);
93    }
94
95    return $dir;
96 }
97 #------------------------------------------------------------------------
98 sub id_to_dir {
99    my $self = shift;
100    my $id = shift;
101
102    my $safe_id = uri_escape($id,
103                             '\*\?\|\\\/\'\"\{\}\<\>\;\,\^\(\)\$\~\:'
104                            );
105
106    my $dir = $self->{root}."/".$safe_id;
107
108    if($self->{ds_object}){
109       $dir = $self->{ds_object}->id_to_dir($safe_id);
110    }
111
112    return $dir;
113 }
114 #------------------------------------------------------------------------
115 sub seq_dirs {
116    my $self = shift;
117    my $id = shift;
118
119    my $out_dir = $self->mkdir($id);
120    my $safe_id = uri_escape($id,
121                             '\*\?\|\\\/\'\"\{\}\<\>\;\,\^\(\)\$\~\:'
122                            );
123    my $the_void = "$out_dir/theVoid.$safe_id";
124    File::Path::mkpath($the_void);
125
126    return $out_dir, $the_void;
127 }
128 #------------------------------------------------------------------------
129 sub add_entry {
130    my $self = shift;
131    my @F = @_;
132
133    #remove deep directory data so log is relative
134    my $cwd = ($CWD) ? $CWD : Cwd::getcwd();
135    my $entry = join("\t", @F);
136
137    if($entry =~ /\tFINISHED|\tSTARTED|\tDIED|\tSKIPPED|\tRETRY/){
138        $entry =~ s/$cwd\/.*\.maker\.output\/*//;
139    }
140
141    open(my $IN, ">>", $self->{log});
142    print $IN $entry . "\n";
143    close($IN);
144 }
145 #------------------------------------------------------------------------
146 #------------------------------------------------------------------------
147 #------------------------------------------------------------------------
148 #------------------------------------------------------------------------
149 1;
Note: See TracBrowser for help on using the browser.