App-geoCancerPrognosticDatasetsRetriever

 view release on metacpan or  search on metacpan

bin/geoCancerPrognosticDatasetsRetriever  view on Meta::CPAN


#perform initial checks.
initial_checks();

#check for input switches/arguments.
input_parameters_check();

#format the input file.
format_input($input_file, $formatted_input_file);

#run main processing events of geo_CPDR and output results.
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 geoCancerPrognosticDatasetsRetriever};
	
	unless ($which_path) {
		
		print color ("red"), "geoCancerPrognosticDatasetsRetriever is not installed on this system...\n", color("reset");
		print color ("red"), "See \"README\" for installation instructions.\n", color("reset");
		exit;
	} 

	#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 binary 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 = qx{which curl};
	
	if (!$check) {
			
		#check if current system is Ubuntu/or Ubuntu-based
		my $ubuntu = qx{uname -a};
			
		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"); 
		}	
	}	
}
############################ 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;
		$time_minutes = $2;
	}
	
    my $month    = $mon + 1;
    my $year     = $yr + 1900;
    $current_date_time = "$year-0$month-$mday\_h$time_hour$time_minutes";
}
############################ SUBROUTINE 3 #######################################################
#This subroutine prints the program details at start-up.
sub start_up {
	
	print color ("yellow"),"  
#######################################################################
#                                                                     #
#           GEO Cancer Prognostic Datasets Retriever v1.02            #
#           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            #
#                                                                     #
#              Author: Abbas Alameer, Kuwait University               #
#                         abbas.alameer\@ku.edu.kw                     #
#                                                                     #
#                                                                     #
#                       Developed in March/November 2021              #
#                     and released under GPLv2 license                #
#                                                                     #
#######################################################################\n\n\n" , color("reset");
}
############################ SUBROUTINE 4 #######################################################
#This subroutine checks all command line input switches and arguments (including optional ones).

bin/geoCancerPrognosticDatasetsRetriever  view on Meta::CPAN

		
		} else {
			
			print color ("green"), "No user-provided temporary file path through the -f argument is present...\nSaving files to: \"~/geoCancerPrognosticDatasetsRetriever_files/\" folder...\n", color("reset");
			 
			$results_subdir = "/geoCancerPrognosticDatasetsRetriever_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 1.676 second using v1.01-cache-2.11-cpan-6aa56a78535 )