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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
#!/bin/env perl
=pod
=head1 NAME
make-conf - using data from parse-table, create Circos input files to visualize the table
=head1 SYNOPSIS
cat parsed-table.txt | make-conf -dir data/
# or
make-conf -file table.txt -dir data/
=head1 DESCRIPTION
This script uses the output of parse-table to create Circos configuration files used to create circular table views as described here
http://mkweb.bcgsc.ca/circos/tableviewer/
=head1 OUTPUT
Output files are placed in the directory defined by -dir parameter.
When drawing the image, make sure that the paths to data files defined in circos.conf point to where you've created the files.
=head1 CONFIGURATION
All configuration parameters are controlled by the configuration file - see etc/make-conf.conf.
=head1 HISTORY
=over
=item * 21 Jan 2009 v0.1
Versioned and updated.
=back
=head1 BUGS
=head1 AUTHOR
Martin Krzywinski
=head1 CONTACT
Martin Krzywinski
Genome Sciences Centre
Vancouver BC Canada
www.bcgsc.ca
martink@bcgsc.ca
=cut
################################################################
#
# Copyright 2002-2008 Martin Krzywinski
#
# This file is part of the Genome Sciences Centre Perl code base.
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
################################################################
################################################################
# Martin Krzywinski (martink@bcgsc.ca)
# 2008
################################################################
use strict;
use Config::General;
use Data::Dumper;
use File::Basename;
use File::Path;
use FindBin;
use Getopt::Long;
use IO::File;
#use Math::VecStat qw(sum min max average);
#use Math::Round qw(round);
use Pod::Usage;
#use Set::IntSpan;
#use Statistics::Descriptive;
#use Storable;
#use Time::HiRes qw(gettimeofday tv_interval);
use lib "$FindBin::RealBin";
use lib "$FindBin::RealBin/../lib";
use lib "$FindBin::RealBin/lib";
use vars qw(%OPT %CONF);
################################################################
#
# *** YOUR MODULE IMPORTS HERE
#
################################################################
GetOptions(\%OPT,
"dir=s",
"configfile=s","help","man","debug+");
pod2usage() if $OPT{help};
pod2usage(-verbose=>2) if $OPT{man};
loadconfiguration($OPT{configfile});
populateconfiguration(); # copy command line options to config hash
validateconfiguration();
if($CONF{debug} > 1) {
$Data::Dumper::Pad = "debug parameters";
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Terse = 1;
print Dumper(\%CONF);
}
################################################################
# setup the input handle to be the file, if specified, otherwise
# read from STDIN
my $inputhandle;
if(my $file = $CONF{file}) {
die "No such file $file" unless -e $file;
open(F,$file);
$inputhandle = \*FILE;
} else {
printdebug("using STDIN");
$inputhandle = \*STDIN;
}
my @rules = ({rx=>"colorpercentile",
file=>"colors_percentile.conf",
skip=>1},
{rx=>"chromosomes_scale",
file=>"scaling.conf",
skip=>0},
{rx=>"colordef",
file=>"colors.conf",
skip=>1},
{rx=>"karyo",
file=>"karyotype.txt",
skip=>1},
{rx=>"segmentlabel",
file=>"segmentlabel.txt",
skip=>1},
{rx=>"link cell",
file=>"cells.txt",
skip=>1},
{rx=>[qw(highlight \brow\b)],
file=>"row.txt",
skip=>2},
{rx=>[qw(colribboncap)],
file=>"cap.col.txt",
skip=>1},
{rx=>[qw(rowribboncap)],
file=>"cap.row.txt",
skip=>1},
{rx=>[qw(highlight \bcol\b)],
file=>"col.txt",
skip=>2},
{rx=>[qw(highlight \ball\b)],
file=>"all.txt",
skip=>2});
for my $rule (@rules) {
unlink(sprintf("%s/%s",$CONF{dir},$rule->{file}));
}
LINE:
while(<$inputhandle>) {
chomp;
my $line = $_;
RULE:
for my $rule (@rules) {
my $pass;
if(ref($rule->{rx})) {
$pass = grep($line =~ /$_/, @{$rule->{rx}}) == @{$rule->{rx}};
} else {
$pass = $line =~ $rule->{rx};
}
if($pass) {
my $file = sprintf("%s/%s",$CONF{dir},$rule->{file});
mkpath(dirname($file));
open(F,">>$file") || die "cannot open file $file";
my @tok = split(" ",$line);
print F join(" ", @tok[$rule->{skip} .. @tok-1]),"\n";;
close(F);
printdebug("writing to $file",@tok);
} else {
next RULE;
}
}
}
sub validateconfiguration {
}
################################################################
#
# *** DO NOT EDIT BELOW THIS LINE ***
#
################################################################
sub populateconfiguration {
foreach my $key (keys %OPT) {
$CONF{$key} = $OPT{$key};
}
# any configuration fields of the form __XXX__ are parsed and replaced with eval(XXX). The configuration
# can therefore depend on itself.
#
# flag = 10
# note = __2*$CONF{flag}__ # would become 2*10 = 20
for my $key (keys %CONF) {
my $value = $CONF{$key};
while($value =~ /__([^_].+?)__/g) {
my $source = "__" . $1 . "__";
my $target = eval $1;
$value =~ s/\Q$source\E/$target/g;
#printinfo($source,$target,$value);
}
$CONF{$key} = $value;
}
}
sub loadconfiguration {
my $file = shift;
my ($scriptname) = fileparse($0);
if(-e $file && -r _) {
# great the file exists
} elsif ($ENV{LOGNAME} && -e "/home/$ENV{LOGNAME}/.$scriptname.conf" && -f _ && -r _) {
$file = "/home/$ENV{LOGNAME}/.$scriptname.conf";
} elsif (-e "$FindBin::RealBin/$scriptname.conf" && -f _ && -r _) {
$file = "$FindBin::RealBin/$scriptname.conf";
} elsif (-e "$FindBin::RealBin/etc/$scriptname.conf" && -f _ && -r _) {
$file = "$FindBin::RealBin/etc/$scriptname.conf";
} elsif (-e "$FindBin::RealBin/../etc/$scriptname.conf" && -f _ && -r _) {
$file = "$FindBin::RealBin/../etc/$scriptname.conf";
} else {
return undef;
}
$OPT{configfile} = $file;
my $conf;
eval {
$conf = new Config::General(-ConfigFile=>$file,
-AllowMultiOptions=>"yes",
-LowerCaseNames=>1,
-AutoTrue=>1);
};
if($@) {
printinfo($@);
exit;
}
%CONF = $conf->getall;
}
sub printdebug {
printinfo("debug",@_) if $CONF{debug};
}
sub printinfo {
printf("%s\n",join(" ",@_));
}
sub printdumper {
printinfo(Dumper(@_));
}
|