sub write_infile
{
my ($self, $filename) = @_;
if (! $filename) {
$filename = $self->infile();
}
my $noa = scalar(keys %{$self->result_features});
warn("\tNo. of result sets: ". $noa);
my $nof = scalar(@{(values %{$self->result_features})[0]});
warn("\tNo. of result features: ". $nof);
my $header = join("\t", 'chromosome', 'position', keys %{$self->result_features});
$header .= "\tDUMMY" if ($noa == 1);
open(F, ">".$filename)
or throw("Can't open file $filename.");
print F $header, "\n";
for (my $i=0; $i<$nof; $i++) {
my $coord=0;
foreach my $rset (values %{$self->result_features}) {
print F join("\t", ${$rset}[$i][0], ${$rset}[$i][1]) unless ($coord);
$coord=1;
print F "\t".(-1*${$rset}[$i][3]);
}
print F "\t0" if ($noa == 1);
print F "\n";
}
close F;
warn("\tresult features written to ".$filename);
my $workdir = $self->workdir.'/'.$self->analysis->module();
(my $project = $filename) =~ s,.+/(.+)\.dat,$1,;
warn('ANALYSIS PARAMETERS: '.$self->analysis->parameters);
my %parameters = ();
map {
my ($key, $value) = split (/=/);
$parameters{$key} = $value;
} split(/;\s+/, $self->analysis->parameters);
my $config = $workdir.'/'.$project.'_args.txt';
$self->config_file($config);
my $template_file = $parameters{TEMPLATE_FILE};
open(IN, $template_file)
or throw("Can't open config file $template_file");
open(OUT, ">$config")
or throw("Can't open config file $config");
map {
s,^(O.1-.+=).+$,$1 $workdir,; s,^(O.2-.+=).+$,$1 $project,; s,^(I.2-.+=).+$,$1 $project.dat,; s,^(I.3-.+=).+$,$1 2,; s,^(II.1-.+=).+$,$1 0,; s,^(II.2-.+=).+$,$1 NULL,; s,^(III.2-.+=).+$,$1 $parameters{METHOD},; s,^(IV.1-.+=).+$,$1 $parameters{POSTPROB},; s,^(IV.2-.+=).+$,$1 $parameters{MAXGAP},; s,^(IV.4-.+=).+$,$1 0,; s,^(IV.5-.+=).+$,$1 NULL,; s,^(IV.10-.+=).+$,$1 $parameters{HYBLENGTH},; s,^(V.2-.+=).+$,$1 $parameters{MAXGAP},; print OUT;
} <IN>;
close IN;
close OUT;
my $cmpinfo = $workdir.'/'.$project.'.cmpinfo';
warn("cmp info file: $cmpinfo");
open(CMP, ">$cmpinfo")
or throw("Can't open cmpinfo file $cmpinfo");
my $array_no = ($noa == 1)? '2' : $noa;
my $group_no = ($noa == 1)? '2' : 1;
my $groups = ($noa == 1)? '1 2' : '1 'x $noa;
warn("array_no: " . $array_no);
warn("group_no: " . $group_no);
warn("groups: " . $groups);
print CMP <<EOCMP; ############################## # TileMap Comparison Info # ############################## ############################## # Basic Info # ############################## [Array number] = $array_no [Group number] = $group_no [Group ID] $groups
############################## # Patterns of Interest # ############################## [Comparisons] 1>2
############################## # Preprocessing # ############################## [Truncation lower bound] = -1000000000000.0 [Take log2 before calculation?] (1:yes; 0:no) = 0
############################## # Simulation Setup # ############################## [Monte Carlo draws for posterior prob.] = 0
############################## # Common Variance Groups # ############################## [Common variance groups] = 1 $groups
############################## # Permutation Setup # ############################## [Number of permutations] = 0 [Exchangeable groups] = 1 $groups EOCMP
close OUT;
my $ext;
if ($parameters{METHOD}) {
$ext = '_ma';
} else {
$ext = '_hmm';
}
my $results = $workdir.'/'.$project.$ext.'.bed';
$self->resultsfile($results);
my @fields = (0..2,4); $self->output_fields(\@fields);
return $filename; } |