#!usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use Statistics::R;
#usage: perl /storage/Runs/CIC/ANALYSIS/JL_scripts/PerleR_ToC.pl -g [ref_gemone] -p [/path_to_Table] -t [DatabaseTablename] -c [path/ToC]
my ( $path, $genome, $table, $toc, $libType );
GetOptions(
'path=s' => \$path,
'genome=s' => \$genome,
'tablename=s' => \$table,
'counttable=s' => \$toc,
#'sconditions=s' => \@conds,
'libtype=s' => \$libType, #solo para un tipo de librerias
);
chdir $path or die "ERROR: Unable to enter $path: $!\n";
print "current dir =$path\n";
# Create a communication bridge with R and start R
my $R = Statistics::R->new();
$R->set('genome', $genome);
my $out_genome = $R->get('genome');
print "genome = $out_genome\n";
$R->set('tablename', "$table");
my $out_table = $R->get('tablename');
print "database table = $out_table\n";
$R->set('file', "$toc");
my $out_toc = $R->get('file');
print "ToC = $out_toc\n";
#$R->set('conds', "@conds");
#my @out_conds = $R->get('conds');
#print "Conditions = @out_conds\n";
#$R->set('libType', "$libType");
#my $out_libType = $R->get('libType');
#print "Libraries type = $out_libType\n";
# Here-doc with multiple R commands:
my $cmds = <<EOF;
library(DESeq)
#personalizar el nombre de la tabla
countsTable <- read.delim( "/solexa/storage/Runs/CIC/ANALYSIS/JA-01-mRNA/Sequences/FASTQ_original/mm9_JA01_ToC.tsv", header=TRUE, row.names = 1, stringsAsFactors=TRUE )
head (countsTable )
ToCDesign = data.frame(
row.names = colnames( countsTable ),
condition = c( "untreated", "treated" ),
libType = c( "single-end", "single-end" ) )
ToCDesign
singleSamples = ToCDesign$libType == "single-end"
countTable = countsTable [ , singleSamples ]
condition = ToCDesign$condition[ singleSamples ]
head(countTable)
condition
condition = factor( c( "untreated", "treated" ) )
cds = newCountDataSet( countTable, condition )
cds = estimateSizeFactors( cds )
sizeFactors( cds )
head( counts( cds, normalized=TRUE ) )
cds = estimateDispersions( method ="blind", cds )
str( fitInfo(cds) )
plotDispEsts( cds )
head( fData(cds) )
#2)DATA QUALITY ASSESMENT
#Heatmap of the count table
cdsFullBlind = estimateDispersions( cds, method = "blind" )
vsdFull = varianceStabilizingTransformation( cdsFullBlind )
library("RColorBrewer")
library("gplots")
select = order(rowMeans(counts(cds)), decreasing=TRUE)[1:30]
hmcol = colorRampPalette(brewer.pal(9, "GnBu"))(100)
heatmap.2(exprs(vsdFull)[select,], col = hmcol, trace="none", margin=c(10, 6))
heatmap.2(counts(cds)[select,], col = hmcol, trace="none", margin=c(10,6))
dists = dist ( t( exprs(vsdFull) ) )
mat = as.matrix( dists )
rownames(mat) = colnames(mat) = with(pData(cdsFullBlind), paste(condition, libType, sep=" : "))
heatmap.2(mat, trace="none", col = rev(hmcol), margin=c(13, 13))
dev.off()
print('ok')
EOF
my $out2 = $R->run($cmds);
#$R->stop();