App-geoCancerDiagnosticDatasetsRetriever
view release on metacpan or search on metacpan
bin/geoCancerDiagnosticDatasetsRetriever view on Meta::CPAN
main($formatted_input_file, $output_file);
###################################################
# #
# SUBROUTINES BELOW #
# ----------------- #
# #
###################################################
############################ SUBROUTINE 1 #######################################################
#various checks done before program's run execution.
sub initial_checks {
#check 1 - check that the script is installed on the system.
#Prompt user to install it, if not found in the $PATH.
my $which_path = qx{which geoCancerDiagnosticDatasetsRetriever};
$rscript_subdir = "/geoCancerDiagnosticDatasetsRetriever_files/Rscript";
my $rscript_path;
unless ($which_path) {
print color ("red"), "geoCancerDiagnosticDatasetsRetriever is not installed on this system...\n", color("reset");
print color ("red"), "See \"README\" for installation instructions.\n", color("reset");
exit;
}
else {
my $mkdir_arg = "~" . $rscript_subdir . "/";
#create main Rscript directory - ignore if already present
system("mkdir -p $mkdir_arg");
my $home_dir = File::HomeDir -> my_home;
$rscript_path = $home_dir . $rscript_subdir;
}
#check 2 - check if CPAN module (LWP::Protocol::https) is installed on current system
#and install it if not found.
my $cpan_module = "LWP::Protocol::https";
eval "use $cpan_module";
if ($@) {
print color ("red"), "CPAN module: \"$cpan_module\" not found...\n", color("reset");
print color ("green"), "Preparing one time installation of $cpan_module....\nInstalling cpanm....\n", color("reset");
#install cpanm to make installing other modules easier
system ("cpan App::cpanminus");
print color ("green"), "done\n", color("reset");
print color ("green"), "Installing $cpan_module....\n", color("reset");
#now install LWP::Protocol::https module
system ("cpanm $cpan_module");
print color ("green"), "done\n", color("reset");
}
#check 3 - check for the presence of curl/lynx binaries in the $PATH.
#if not found, install on an Ubuntu/Ubuntu-based systems.
#if system is not Ubuntu, prompt user to install it manually.
my $check_curl = qx{which curl};
my $check_lynx = qx{which lynx};
#check if current system is Ubuntu/or Ubuntu-based
my $ubuntu = qx{uname -a};
if (!$check_curl) {
if ($ubuntu=~ /.+ubuntu.+/ig) {
print color ("red"), "curl binary was not found: follow onscreen instructions/input your password for its installation...\n\n", color("reset");
system("sudo apt -y install curl"); #install curl
print "done\n";
}
else {
print color ("red"), "curl binary was not found: install it on your system.\n", color("reset");
exit;
}
}
if (!$check_lynx) {
if ($ubuntu=~ /.+ubuntu.+/ig) {
print color ("red"), "lynx binary was not found: follow onscreen instructions/input your password for its installation...\n\n", color("reset");
system("sudo apt -y install lynx"); #install curl
print "done\n";
}
else {
print color ("red"), "lynx binary was not found: install it on your system.\n", color("reset");
exit;
}
}
#check 4 - download healthyControlsPresentInputParams.r if not present
my $RscriptFile1 = 'healthyControlsPresentInputParams.r';
my $RscriptFile2 = "$rscript_path/healthyControlsPresentInputParams.r";
unless (-e $RscriptFile2) {
#The script downloads the R script if it does not exist in the current folder
print color ("red"), "The \"$RscriptFile1\" file is missing and will be downloaded...\n\n", color("reset");
system ("cd $rscript_path/ && { curl -O -C - https://raw.githubusercontent.com/davidechicco/healthyControlsPresenceChecker_repo/main/healthyControlsPresentInputParams.r ; }");
}
}
############################ SUBROUTINE 2 #######################################################
#get the current date and time.
sub date_time {
my ($sec, $min, $hour, $mday, $mon, $yr, $wday, $yday, $isdst) = localtime();
my $ctime = localtime();
my $time_hour;
my $time_minutes;
#hour #minutes
if ($ctime =~ m/^\w+\s+\w+\s+\d+\s+(\d+)\:(\d+)\:\d+\s+\d+/) {
$time_hour = $1;
bin/geoCancerDiagnosticDatasetsRetriever view on Meta::CPAN
} else {
print color ("green"), "No user-provided temporary file path through the -f argument is present...\nSaving files to: \"~/geoCancerDiagnosticDatasetsRetriever_files/\" folder...\n", color("reset");
$results_subdir = "/geoCancerDiagnosticDatasetsRetriever_files/results/";
}
#after checking if the CLI's "-f" option is present or not, create results directory's path.
$results_subdir = $home_dir . $results_subdir;
system("mkdir -p $results_subdir");
#check if user-defined GPL platforms are specified.
if (defined $options{p}) {
$platform_gpl = uc($options{p});
#error checks done in case a user specifies "-p" flag but includes missing or wrong inputs
#and if that is the case, the default platform will be used.
if ($platform_gpl !~ m/^GPL|^\d+/) {
$platform_gpl = "GPL570";
print color ("green"), "No user-provided input platform through the -p argument is present...\nDefault platform: GPL570 will be used...\n", color("reset");
}
} else {
#if a user does not specify any platform, default platform is set to "GPL570"
$platform_gpl = "GPL570";
print color ("green"), "No user-provided input platform through the -p argument is present...\nDefault platform: GPL570 will be used...\n", color("reset");
}
#after all checks above are completed - run mini() to initiate a run or check/restart aborted runs.
mini();
}
#elsif (!$options{d} or !$options{p}) {
elsif (!$options{d}) {
print color ("green"), "$help_message1\n$help_message2\n", color("reset");
print color ("red"), $error_message, color("reset");
exit;
}
sub mini {
#print color ("green"), "done\n", color("reset");
my $restart_input_file;
my $cancer = "$query_term_1";
my @files = glob("$prog_path/data/$cancer\_cancer_GEO_*.txt");
my @sorted_files = sort {$b cmp $a} @files;
$run_dir = "$results_subdir" . "$cancer_type\_GEO-files";
foreach my $file (@sorted_files) {
$restart_input_file = basename($file);
last;
}
#If an old run file was found, prompt the user with choices to make.
if (-e "$run_dir") {
print color ("red"), "$cancer_type\_GEO-files directory exists...This run was not completed\n", color("reset");
my $text = "";
my $ok = timed_response( sub {
print color ("red"), "Do you want to resume an interrupted execution [r], or start a new one [n]? (r/n)\nDefault selection will be [n] after 10 seconds...\n", color("reset"); $text = <STDIN>;
}, 10);
chomp($text);
if ($text eq "r") {
print color ("green"), "Resuming analysis using input file: $restart_input_file\n", color("reset");
#$platform_gpl = uc($options{p});
$platform_gpl = uc($platform_gpl);
my $regex1 = join( '', ( split(/GPL/, $platform_gpl) ) );
$regex_platform = join( '|', ( split(/ /, $regex1) ) );
$input_file = $restart_input_file;
$output_file = "$cancer_type.out";
}
#this is when the user selects "n", or types nothing/ or 10 seconds elapse -> defaults to "n"
else {
print color ("green"), "Starting new analysis...\n", color("reset");
system ("rm -r $run_dir"); #remove old results output directory
new_run($query_term_1);
}
sub timed_response {
my ($f, $sec) = @_;
return eval {
local $SIG{ALRM} = sub { die };
alarm($sec);
$f->();
alarm(0);
1;
};
}
}
#else no "interrupted" run directory was found. Start a new run.
else {
new_run($query_term_1);
}
sub new_run {
my $cancer = $_[0];
print color ("green"), "Downloading input file for \"$cancer\" cancer from GeoDatasets...", color("reset");
$input_file = download_geo_input($options{d});
print color ("green"), "done\n", color("reset");
system ("mkdir $run_dir"); #create results output directory
my $regex1 = join( '', ( split(/GPL/, $platform_gpl) ) );
( run in 0.476 second using v1.01-cache-2.11-cpan-0b5f733616e )