-
Notifications
You must be signed in to change notification settings - Fork 0
/
step1.pl
executable file
·87 lines (73 loc) · 1.91 KB
/
step1.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
#!/usr/bin/perl -w
#$ -S /import/bc2/soft/app/perl/5.10.1/Linux/bin/perl
#$ -P project_zavolan
#$ -q fs_very_long_hm
#$ -l mem_total=10000M
#$ -o step1.out
#$ -e step1.err
#$ -j n
#$ -N step1
#$ -cwd
# This file was written for clustering of data from Fantom 5.
# This script produces cumulatives in the tmpDir directory.
# TODO: it should also make a file with sample id => description, depth, and so on.
# necessery to exec the RIGHT perl in the system call
# $ENV{PATH} = '/import/bc2/soft/app/perl/5.10.1/Linux/bin:' . $ENV{PATH};
use strict;
use lib '.';
use promoteromeLib;
use YAML::Any;
$| = 1;
######################## config
my $conf_file = shift @ARGV or die "specify a config file!\n";
my $theOnlyFile = shift @ARGV; # second parameter if not empty is just one file to run on: for parallelizing
my $config = YAML::Any::LoadFile($conf_file);
my $dir = $config->{dir};
my $tmpDir = $config->{tmpDir};
my $cumDir = $config->{cumDir};
my $mappedDir = $config->{mappedDir};
my $normDir = $config->{normDir};
##################### CODE
# make sure the dires are created
mkdir $tmpDir.$cumDir;
mkdir $tmpDir.$mappedDir;
mkdir $tmpDir.$normDir;
if(defined $theOnlyFile)
{
processFile($dir, $theOnlyFile);
}
else
{
opendir(my $D, $dir) or die;
while(my $f = readdir $D)
{
if(-f $dir.$f || -l $dir.$f)
{
processFile($dir, $f);
}
}
close $D;
}
sub processFile
{
my ($dir, $f) = @_;
my ($sampleDesc, $sampleID) = split(/\./, $f);
my $outF = $tmpDir.$cumDir.$sampleID;
if(! -e $outF)
{
print STDERR $f, "\n";
my %h;
my $sampleInfo = processBed(\%h, $dir.$f);
my $cumTxt = cumulative_rev_unnorm(h2counts(\%h));
open(A, '>', $outF ) or die "cannot write to $outF\n";
print A $cumTxt;
close A;
open(B, '>', $tmpDir.$mappedDir.$sampleID) or die; #.".mappedCount"
print B $sampleInfo->{mappedCount}, "\n";
close B;
}
else
{
print STDERR "Sample $sampleID is already processed. Quitting.\n";
}
}