[Bio] / FortyEight / rp_request_peer_sims.pl Repository:
ViewVC logotype

Diff of /FortyEight/rp_request_peer_sims.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Fri Oct 3 15:45:02 2008 UTC revision 1.2, Fri Nov 7 22:42:29 2008 UTC
# Line 13  Line 13 
13  use GenomeMeta;  use GenomeMeta;
14  use FileHandle;  use FileHandle;
15  use Sim;  use Sim;
16    use GeneralJob;
17    use FileLocking qw(lock_file unlock_file);
18    use SGE;
19    
20  my $meta;  my $meta;
21    
# Line 20  Line 23 
23    
24  my @job_ids = @ARGV;  my @job_ids = @ARGV;
25    
26  my @blast_args = qw(-p blastp -m 8 -e 1.0e-5);  $FIG_Config::general_jobdir ne '' or die "\$FIG_Config::general_jobdir must be set\n";
27    
28    my $sge = new SGE;
29    
30    #
31    #
32    # First walk the list of jobs we're setting up sims for and touch the
33    # orgdir/sims/org2.queued file to mark them as queued for computation.
34    #
35    
36    my @jobs;
37    for my $j (@job_ids)
38    {
39        my $d = "$FIG_Config::rast_jobs/$j";
40        my $g = &FIG::file_head("$d/GENOME_ID", 1);
41        $g or die "cannot read jobdir $g";
42        chomp $g;
43        my $simdir = "$d/rp/$g";
44    
45        if (! -d "$simdir/sims")
46        {
47            mkdir("$simdir/sims");
48        }
49        if (! -f "$simdir/sims/lock")
50        {
51            open(LF, ">", "$simdir/sims/lock");
52            close(LF);
53        }
54    
55        push(@jobs, [$j, $d, $g, $simdir]);
56    }
57    
58    my %need;
59    
60    for my $j1idx (0..@jobs-1)
61    {
62        my($j1_id, $j1_jobdir, $j1_genome, $j1_orgdir) = @{$jobs[$j1idx]};
63    
64        #
65        # Lock the sims dir while we are doing this check.
66        #
67    
68        open(LF, "+<", "$j1_orgdir/sims/lock") or die
69            "Cannot open lockfile $j1_orgdir/sims/lock: $!";
70        lock_file(\*LF);
71    
72        for my $j2idx (0..@jobs-1)
73        {
74            next if $j1idx == $j2idx;
75            my($j2_id, $j2_jobdir, $j2_genome, $j2_orgdir) = @{$jobs[$j2idx]};
76    
77            my $simfile_base = "$j1_orgdir/sims/$j2_genome";
78    
79            print "checking $simfile_base\n";
80            if (-f "$simfile_base.queued")
81            {
82                print "$j1_genome $j2_genome already queued\n";
83            }
84            elsif (-f "$simfile_base.in_progress")
85            {
86                print "$j1_genome $j2_genome already in progress\n";
87            }
88            elsif (-f "$simfile_base")
89            {
90                print "$j1_genome $j2_genome already computed\n";
91            }
92            else
93            {
94                my($j1, $j2) = sort { $a <=> $b } ($j1idx, $j2idx);
95    
96                $need{$j1,$j2}++;
97            }
98        }
99    
100        close(LF);
101    }
102    
103    for my $pair (sort keys %need)
104    {
105        my ($j1idx, $j2idx) = split(/$;/, $pair);
106    
107        #my($id, $jobdir, $genome, $orgdir) = @{$jobs[$jidx]};
108        #print "Need to compute $id $jobdir $genome $orgdir\n";
109        print "need to compute $j1idx $j2idx\n";
110    
111        my $jobid = GeneralJob->create_new_job($FIG_Config::general_jobdir);
112    
113        my $job = GeneralJob->new($FIG_Config::general_jobdir, $jobid);
114    
115        mark_queued($j1idx, $j2idx);
116    
117        my $j1 = $jobs[$j1idx]->[0];
118        my $j2 = $jobs[$j2idx]->[0];
119    
120        my $work = $job->dir;
121        mkdir "$work/sge_output";
122    
123        my @args = (-N => "p${j1}_${j2}",
124                    -e => "$work/sge_output",
125                    -o => "$work/sge_output",
126                    -v => "PATH",
127                    -b => "yes",
128                    );
129        my $args = join(" ", @args);
130    
131        my $cmd = "$FIG_Config::bin/rp_compute_peer_sim_pair $work $j1 $j2";
132        my $jobid = $sge->submit_job($job->meta, $args, $cmd);
133    
134        print "Submitted $jobid\n";
135    }
136    
137    
138    sub mark_queued
139    {
140        my($from, $to) = @_;
141    
142        my $g1 = $jobs[$from]->[2];
143        my $g2 = $jobs[$from]->[2];
144    
145        my $d1 = $jobs[$from]->[1] . "/rp/$g1";
146        my $d2 = $jobs[$to]->[1] . "/rp/$g2";
147    
148        print "mark $g1  $g2 / $d1 $d2\n";
149    
150        -d "$d1/sims" or mkdir "$d1/sims" or die "cannot mkdir $d1/sims: $!";
151        if (!open(LF, "+<", "$d1/sims/lock"))
152        {
153            open(LF, "+>", "$d1/sims/lock") or die
154                "Cannot open lockfile $d1/sims/lock: $!";
155        }
156        lock_file(\*LF);
157    
158        open(S, ">", "$d1/sims/$g2.queued") or die "cannot mark $d1/sims/$g2.queued: $!";
159        close(LF);
160    }
161    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3