App-GeoCancerPrognosticDatasetsRetriever
view release on metacpan or search on metacpan
bin/geoCancerPrognosticDatasetsRetriever view on Meta::CPAN
######################################################################\n\n\n" , color("reset");
}
############################ SUBROUTINE 4 #######################################################
#This subroutine checks all command line input switches and arguments and warns user if something
#is missing.
sub input_parameters_check {
my $error_message = "Error: The following arguments are missing: CANCER_TYPE PLATFORM_CODES\n";
my $help_message1 = "Usage: geoCancerPrognosticDatasetsRetriever -d \"CANCER_TYPE\" -p \"PLATFORMS_CODES\"";
my $help_message2 = "Mandatory arguments:
CANCER_TYPE type of the cancer as query search term
PLATFORM_CODES list of GPL platform codes
Optional arguments:
-h show help message and exit";
#parse command line switches and their arguments into a hash.
getopts("hd:p:", \%options);
#Check for help switch and, if present, output help text.
if ($options{h}) {
print color ("green"), "$help_message1", color("reset");
print color ("green"), "\n$help_message2\n", color("reset");
exit;
}
elsif ($options{d} and $options{p}) {
print color ("green"), "Checking input parameters...", color("reset");
mini();
}
elsif (!$options{d} or !$options{p}) {
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 $temp_filename = "$options{d}";
my ($query_term_1, $query_term_2) = split ( / /, $temp_filename );
#add dash in cancer type query search term.
$cancer_type = uc ( join ( '-', $query_term_1, $query_term_2 ) );
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 = "$prog_path/results/$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});
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
$platform_gpl= uc($options{p});
my $regex1 = join( '', ( split(/GPL/, $platform_gpl) ) );
bin/geoCancerPrognosticDatasetsRetriever view on Meta::CPAN
#Check for a GeoDatasets timeout error and abort run, if found.
if (!$data) {
print color ("red"), "\nThe download from GeoDatasets was not successful...\nA GeoDatasets timeout error was detected: current run aborted...\nPlease restart the run...\n", color("reset");
exit; #abort current run
}
#add date & time to current input file download
my $geo_datasets_file = "$cancer\_cancer_GEO_$current_date_time.txt";
open(FH, ">$prog_path/data/$geo_datasets_file") or die "Cannot open file for writing the GDS input:$!\n";
binmode(FH, ":utf8");
print FH "$data";
close(FH);
return $geo_datasets_file;
}
############################ SUBROUTINE 6 #######################################################
#This subroutine performs minor formatting of a GEO input file to merge the title and abstract
#lines together to prevent the regex lines from missing potential keyword hits in the 'title'
#line.
sub format_input {
my $raw_input = $_[0];
my $out_file = $_[1];
my $concatenate;
print color ("green"), "Formatting Input: $input_file...", color("reset");
open (IN, "$prog_path/data/$raw_input") or die "Cannot open file for reformatting: $raw_input. $!.\n";
open (OUT, '>', "$prog_path/data/$out_file") or die "Cannot open file for writing reformatted data: $out_file $!\n";
while ($line = <IN>) {
#title line check only
if ($line =~ m/(^\d+\.\s+.*)/) {
$concatenate = $line;
chomp($concatenate);
}
#abstract line
elsif ($line !~ m/(^\d+\.\s+.*)/) {
$concatenate .= "$line";
print OUT "$concatenate";
$concatenate = ""; #reinitialize variable for next entry.
}
}
print color ("green"), "done\n", color("reset");
close (IN);
close (OUT);
}
############################ SUBROUTINE 7 #######################################################
#Check for the presence of curl in the $PATH. If not found, install on an Ubuntu system or if
#not Ubuntu, prompt user to install it manually.
sub check_curl {
#check for the presence of curl binary
my $check = qx{which curl};
#if no curl binary was found, install it on Ubuntu/Ubuntu-based systems
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 "curl is not found on this system: install it on your system.\n";
}
}
}
############################ SUBROUTINE 8 #######################################################
#This subroutine runs the main processing steps, while running other subroutines to continue the
#processing pipeline.
sub main {
my $main_formatted_input_file = $_[0];
my $main_output_file = $_[1];
print color ("green"), "Analyzing Input: $main_formatted_input_file file...\n", color("reset");
#open input file
open (FH, "$prog_path/data/$main_formatted_input_file") or die "Cannot open file: $main_formatted_input_file $!\n";
#open output file
open (FH2, '>', "$prog_path/results/$main_output_file") or die "Cannot open file for writing data: $!\n";
while ($line = <FH>) {
if ($line =~ m/.*(prognosis|prognostic|prognostically|prognosticator|survival|survive|survives|survived|surviving).*/ig) {
#if ($line =~ m/.*(progno.+\s?|surviv.+\s?).*/ig) {
$flag = 1;
$prog_flag = 1;
next;
}
#this conditional activates when the above keywords are not found and only "more..." is found.
#Note this conditional implicitly doesn't get executed if both the desired keyword and "more..." are found.
elsif ($line =~ m/.+(more\.\.\.)/ig) {
$flag = 1;
$wget_flag = 1;
next;
}
elsif ($line =~ m/(^Organism:\s+Homo\s+sapiens.*)/ig) {
( run in 0.533 second using v1.01-cache-2.11-cpan-6aa56a78535 )