Guest User

Untitled

a guest
Nov 23rd, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.79 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2.  
  3. =head1 NAME
  4.  
  5. run_genewisedb.pl
  6.  
  7. =head1 SYNOPSIS
  8.  
  9. run_genewisedb.pl input_fasta input_hmms output outputdir spliceflat parameterfile
  10. where input_fasta is the input fasta file of scaffolds,
  11. input_hmms is the input file of HMMs,
  12. output is the genewise output file,
  13. outputdir is the output directory for writing output files,
  14. spliceflat says whether to use the -splice flat option (yes/no),
  15. parameterfile is the name of the intron parameter file (none if there is none).
  16.  
  17. =head1 DESCRIPTION
  18.  
  19. This script takes an input fasta file of scaffolds (<input_fasta>) and an
  20. input file of HMMs (<input_hmms>) and runs genewise on the scaffolds, using
  21. one HMM at a time. The output is then written in the output file <output>.
  22. Before running this perl script you need to run:
  23. setenv WISECONFIGDIR /nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/wisecfg/
  24.  
  25. =head1 VERSION
  26.  
  27. Perl script last edited 31-Oct-2012.
  28.  
  29. =head1 CONTACT
  30.  
  31. alc@sanger.ac.uk (Avril Coghlan)
  32.  
  33. =cut
  34.  
  35. #
  36. # Perl script run_genewisedb.pl
  37. # Written by Avril Coghlan (alc@sanger.ac.uk)
  38. # 31-Oct-12.
  39. # Last edited 31-Oct-2012.
  40. # SCRIPT SYNOPSIS: run_genewisedb.pl: runs GeneWise using TreeFam HMMs, on an input fasta file of scaffolds.
  41. #
  42. #------------------------------------------------------------------#
  43.  
  44. # CHECK IF THERE ARE THE CORRECT NUMBER OF COMMAND-LINE ARGUMENTS:
  45.  
  46. use strict;
  47. use warnings;
  48.  
  49. my $num_args = $#ARGV + 1;
  50. if ($num_args != 6)
  51. {
  52. print "Usage of run_genewisedb.pl\n\n";
  53. print "perl run_genewisedb.pl <input_fasta> <input_hmms> <output> <outputdir> <spliceflat> <parameterfile>\n";
  54. print "where <input_fasta> is the input fasta file,\n";
  55. print " <input_hmms> is the input file of HMMs,\n";
  56. print " <output> is the genewise output file,\n";
  57. print " <outputdir> is the output directory for writing output files,\n";
  58. print " <spliceflat> says whether to use the -splice flat option (yes/no),\n";
  59. print " <parameterfile> is the name of the intron parameter file (none if there is none)\n";
  60. print "For example, >perl run_genewisedb.pl /lustre/scratch108/parasites/es9/50HGgenebuild/brpah/genome_small.fa\n";
  61. print "/lustre/scratch108/parasites/es9/GeneWise/TreeFam8.hmm genewise_output\n";
  62. print "/nfs/users/nfs_a/alc/Documents/GeneWise50Helminths yes mygenestat.stat\n";
  63. print "NOTE: Before running this perl script, you need to run:\n";
  64. print "setenv WISECONFIGDIR /nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/wisecfg/\n";
  65. exit;
  66. }
  67.  
  68. # FIND THE PATH TO THE INPUT FASTA FILE:
  69.  
  70. my $input_fasta = $ARGV[0];
  71.  
  72. # FIND THE INPUT FILE OF HMMs:
  73.  
  74. my $input_hmms = $ARGV[1];
  75.  
  76. # FIND THE GENEWISE OUTPUT FILE:
  77.  
  78. my $output = $ARGV[2];
  79.  
  80. # FIND THE DIRECTORY TO USE FOR OUTPUT FILES:
  81.  
  82. my $outputdir = $ARGV[3];
  83.  
  84. # FIND OUT WHETHER WE WANT TO USE THE -splice flat OPTION IN GENEWISE:
  85.  
  86. my $spliceflat = $ARGV[4];
  87.  
  88. # FIND THE NAME OF THE INTRON PARAMETER FILE:
  89.  
  90. my $parameterfile = $ARGV[5];
  91.  
  92. #------------------------------------------------------------------#
  93.  
  94. # TEST SUBROUTINES:
  95.  
  96. my $PRINT_TEST_DATA = 0; # SAYS WHETHER TO PRINT DATA USED DURING TESTING.
  97. &test_print_error;
  98. &test_write_fasta_file($outputdir);
  99.  
  100. #------------------------------------------------------------------#
  101.  
  102. # RUN THE MAIN PART OF THE CODE:
  103.  
  104. &run_main_program($outputdir,$input_fasta,$input_hmms,$output,$spliceflat,$parameterfile);
  105.  
  106. print STDERR "FINISHED.\n";
  107.  
  108. #------------------------------------------------------------------#
  109.  
  110. # RUN THE MAIN PART OF THE CODE:
  111.  
  112. sub run_main_program
  113. {
  114. my $outputdir = $_[0]; # DIRECTORY TO PUT OUTPUT FILES IN.
  115. my $input_fasta = $_[1]; # THE INPUT FASTA FILE
  116. my $input_hmms = $_[2]; # THE INPUT FILE OF HMMs
  117. my $output = $_[3]; # THE OUTPUT FILE NAME
  118. my $spliceflat = $_[4]; # SAYS WHETHER WE WANT TO USE THE -splice flat OPTION IN GENEWISE
  119. my $parameterfile = $_[5]; # THE NAME OF THE INTRON PARAMETER FILE
  120. my $errorcode; # RETURNED AS 0 IF THERE IS NO ERROR.
  121. my $errormsg; # RETURNED AS 'none' IF THERE IS NO ERROR.
  122.  
  123. # CHECK THAT THE WISECONFIGDIR IS SET CORRECTLY:
  124. ($errorcode,$errormsg) = &check_wiseconfigdir;
  125. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  126.  
  127. # RUN GENEWISE WITH ONE SCAFFOLD/CONTIG AT A TIME, ON ONE HMM AT A TIME:
  128. ($errorcode,$errormsg) = &run_genewise_on_scaffolds($outputdir,$input_fasta,$input_hmms,$output,$spliceflat,$parameterfile);
  129. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  130. }
  131.  
  132. #------------------------------------------------------------------#
  133.  
  134. # RUN GENEWISE WITH ONE SCAFFOLD/CONTIG AT A TIME, ON ONE HMM AT A TIME:
  135.  
  136. sub run_genewise_on_scaffolds
  137. {
  138. my $outputdir = $_[0]; # THE DIRECTORY FOR WRITING OUTPUT FILES
  139. my $input_fasta = $_[1]; # THE INPUT FASTA FILE OF SCAFFOLDS
  140. my $input_hmms = $_[2]; # THE INPUT FILE OF HMMs
  141. my $output = $_[3]; # THE OUTPUT FILE
  142. my $spliceflat = $_[4]; # SAYS WHETHER TO USE THE SPLICE FLAT OPTION
  143. my $parameterfile = $_[5]; # THE INTRON PARAMETER FILE NAME
  144. my $errorcode = 0; # RETURNED AS 0 IF THERE IS NO ERROR
  145. my $errormsg = "none";# RETURNED AS 'none' IF THERE IS NO ERROR
  146. my $line; #
  147. my @temp; #
  148. my $name; # NAME OF A SCAFFOLD
  149. my $seq = ""; # SEQUENCE OF A SCAFFOLD
  150. my $seq_fasta; # FASTA FILE FOR SEQUENCE OF A SCAFFOLD
  151.  
  152. # OPEN THE OUTPUT FILE:
  153. $output = $outputdir."/".$output;
  154. open(OUTPUT,">$output") || die "ERROR: run_genewise: cannot open $output\n";
  155. close(OUTPUT);
  156.  
  157. # READ IN THE INPUT FASTA FILE AND TAKE ONE SCAFFOLD AT A TIME:
  158. open(INPUTFASTA,"$input_fasta") || die "ERROR: run_genewise_on_scaffolds: cannot open $input_fasta\n";
  159. while(<INPUTFASTA>)
  160. {
  161. $line = $_;
  162. chomp $line;
  163. if (substr($line,0,1) eq '>')
  164. {
  165. # WRITE THE SEQUENCE TO A TEMPORARY FASTA FILE:
  166. if ($seq ne '')
  167. {
  168. ($seq_fasta,$errorcode,$errormsg) = &write_fasta_file($seq,$name,$outputdir);
  169. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  170. # RUN GENEWISE ON $seq_fasta, ONE HMM AT A TIME:
  171. ($errorcode,$errormsg) = &run_genewise($outputdir,$seq_fasta,$input_hmms,$output,$spliceflat,$parameterfile,$name);
  172. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  173. # DELETE TEMPORARY FILE:
  174. system "rm -f $seq_fasta";
  175. }
  176. @temp = split(/\s+/,$line);
  177. $name = $temp[0];
  178. $name = substr($name,1,length($name)-1);
  179. }
  180. else
  181. {
  182. $seq = $seq.$line;
  183. }
  184.  
  185. }
  186. close(INPUTFASTA);
  187. # WRITE THE SEQUENCE TO A TEMPORARY FASTA FILE:
  188. if ($seq ne '')
  189. {
  190. ($seq_fasta,$errorcode,$errormsg) = &write_fasta_file($seq,$name,$outputdir);
  191. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  192. # RUN GENEWISE ON $seq_fasta:
  193. ($errorcode,$errormsg) = &run_genewise($outputdir,$seq_fasta,$input_hmms,$output,$spliceflat,$parameterfile,$name);
  194. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  195. # DELETE TEMPORARY FILE:
  196. system "rm -f $seq_fasta";
  197. }
  198.  
  199. return($errorcode,$errormsg);
  200.  
  201. }
  202.  
  203. #------------------------------------------------------------------#
  204.  
  205. # TEST &write_fasta_file
  206.  
  207. sub test_write_fasta_file
  208. {
  209. my $outputdir = $_[0]; # DIRECTORY TO WRITE OUTPUT FILES TO
  210. my $errorcode; # RETURNED AS 0 BY A FUNCTION IF THERE IS NO ERROR
  211. my $errormsg; # RETURNED AS 'none' BY A FUNCTION IF THERE IS NO ERROR
  212. my $fasta; # FASTA FILE
  213. my $expected_fasta; # EXPECTED CONTENTS OF FASTA FILE
  214. my $random_number; # RANDOM NUMBER TO USE IN TEMPORARY FILE NAMES
  215. my $differences; # DIFFERENCES BETWEEN $fasta AND $expected_fasta
  216. my $length_differences; # LENGTH OF $differences
  217. my $line; #
  218.  
  219. ($fasta,$errorcode,$errormsg) = &write_fasta_file("AGCTAGCT","myseq",$outputdir);
  220. if ($errorcode != 0) { print STDERR "ERROR: test_write_fasta_file: failed test1\n"; exit;}
  221. $random_number = rand();
  222. $expected_fasta = $outputdir."/tmp".$random_number;
  223. open(EXPECTED,">$expected_fasta") || die "ERROR: write_fasta_file: cannot open $expected_fasta\n";
  224. print EXPECTED ">myseq\n";
  225. print EXPECTED "AGCTAGCT\n";
  226. close(EXPECTED);
  227. $differences = "";
  228. open(TEMP,"diff $fasta $expected_fasta |");
  229. while(<TEMP>)
  230. {
  231. $line = $_;
  232. $differences = $differences.$line;
  233. }
  234. close(TEMP);
  235. $length_differences = length($differences);
  236. if ($length_differences != 0) { print STDERR "ERROR: test_write_fasta_file: failed test1 (files $fasta $expected_fasta)\n"; exit;}
  237. system "rm -f $fasta";
  238. system "rm -f $expected_fasta";
  239. }
  240.  
  241. #------------------------------------------------------------------#
  242.  
  243. # WRITE THE SEQUENCE TO A TEMPORARY FASTA FILE:
  244.  
  245. sub write_fasta_file
  246. {
  247. my $seq = $_[0]; # SEQUENCE
  248. my $name = $_[1]; # NAME OF THE SEQUENCE
  249. my $outputdir = $_[2]; # DIRECTORY FOR WRITING OUTPUT FILES TO
  250. my $fasta; # FASTA FILE
  251. my $random_number; # RANDOM NUMBER TO USE IN TEMPORARY FILE NAMES
  252. my $errorcode = 0; # RETURNED AS 0 IF THERE IS NO ERROR
  253. my $errormsg = "none";# RETURNED AS 'none' IF THERE IS NO ERROR
  254.  
  255. $random_number = rand();
  256. $fasta = $outputdir."/tmp".$random_number;
  257. open(FASTA,">$fasta") || die "ERROR: write_fasta_file: cannot open $fasta\n";
  258. print FASTA ">$name\n";
  259. print FASTA "$seq\n";
  260. close(FASTA);
  261.  
  262. return($fasta,$errorcode,$errormsg);
  263.  
  264. }
  265.  
  266. #------------------------------------------------------------------#
  267.  
  268. # CHECK THAT THE WISECONFIGDIR IS SET CORRECTLY:
  269.  
  270. sub check_wiseconfigdir
  271. {
  272. my $wiseconfigdir = "none";# THE WISECONFIGDIR
  273. my $errorcode = 0; # RETURNED AS 0 IF THERE IS NO ERROR
  274. my $errormsg = "none";# RETURNED AS 'none' IF THERE IS NO ERROR
  275.  
  276. open(TMP,"echo \$WISECONFIGDIR |");
  277. while(<TMP>)
  278. {
  279. $wiseconfigdir = $_;
  280. chomp($wiseconfigdir);
  281. }
  282. close(TMP);
  283. if ($wiseconfigdir ne '/nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/wisecfg/')
  284. {
  285. $errormsg = "ERROR: check_wiseconfigdir: wiseconfigdir $wiseconfigdir\nBefore running this perl script, you must run:\nsetenv WISECONFIGDIR /nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/wisecfg/\n";
  286. $errorcode = 6; # ERRORCODE=6
  287. return($errorcode,$errormsg);
  288. }
  289.  
  290. return($errorcode,$errormsg);
  291. }
  292.  
  293. #------------------------------------------------------------------#
  294.  
  295. # RUN GENEWISE ON ONE HMM AT A TIME:
  296.  
  297. sub run_genewise
  298. {
  299. my $outputdir = $_[0]; # DIRECTORY FOR WRITING OUTPUT FILES TO
  300. my $input_fasta = $_[1]; # THE INPUT FASTA FILE
  301. my $input_hmms = $_[2]; # THE INPUT FILE OF HMMs
  302. my $output = $_[3]; # THE OUTPUT FILE NAME
  303. my $spliceflat = $_[4]; # SAYS WHETHER WE WANT TO USE THE -splice flat OPTION IN GENEWISE
  304. my $parameterfile = $_[5]; # THE NAME OF THE INTRON PARAMETER FILE
  305. my $scaffoldname = $_[6]; # THE NAME OF THE SCAFFOLD
  306. my $errorcode = 0; # RETURNED AS 0 IF THERE IS NO ERROR.
  307. my $errormsg = "none";# RETURNED AS 'none' IF THERE IS NO ERROR.
  308. my $line; #
  309. my $hmm = ""; # A HMM
  310. my $hmmname = "none";# HMM NAME
  311. my @temp; #
  312.  
  313. # READ IN ONE HMM AT A TIME FROM THE INPUT FILE OF HMMs:
  314. open(HMMS,"$input_hmms") || die "ERROR: run_genewise: cannot open $input_hmms\n";
  315. while(<HMMS>)
  316. {
  317. $line = $_;
  318. $hmm = $hmm.$line;
  319. if (substr($line,0,2) eq '//')
  320. {
  321. # CHECK WE HAVE A NAME FOR THE HMM:
  322. if ($hmmname eq 'none')
  323. {
  324. $errormsg = "ERROR: run_genewise: do not have name for hmm $hmm\n";
  325. $errorcode = 3; # ERRORCODE=3
  326. return($errorcode,$errormsg);
  327. }
  328. # RUN GENEWISE FOR THIS HMM:
  329. ($errorcode,$errormsg) = &run_genewise_on_hmm($hmm,$outputdir,$input_fasta,$output,$hmmname,$spliceflat,$parameterfile,$scaffoldname);
  330. if ($errorcode != 0) { ($errorcode,$errormsg) = &print_error($errormsg,$errorcode,0); }
  331. $hmm = "";
  332. $hmmname = "none";
  333. }
  334. if (substr($line,0,4) eq 'NAME')
  335. {
  336. @temp = split(/\s+/,$line);
  337. $hmmname = $temp[1];
  338. chomp($hmmname);
  339. }
  340. }
  341. close(HMMS);
  342. if ($hmm ne '')
  343. {
  344. $errormsg = "ERROR: run_genewise: at end of file hmm should be empty\n";
  345. $errorcode = 1; # ERRORCODE=1
  346. return($errorcode,$errormsg);
  347. }
  348.  
  349. return($errorcode,$errormsg);
  350. }
  351.  
  352. #------------------------------------------------------------------#
  353.  
  354. # READ IN ONE HMM AT A TIME FROM THE INPUT FILE OF HMMs:
  355.  
  356. sub run_genewise_on_hmm
  357. {
  358. my $hmm = $_[0]; # THE HMM
  359. my $outputdir = $_[1]; # DIRECTORY TO WRITE OUTPUT FILES TO
  360. my $input_fasta = $_[2]; # INPUT FASTA FILE
  361. my $output = $_[3]; # FILE FOR GENEWISE OUTPUT
  362. my $hmmname = $_[4]; # NAME OF THE HMM
  363. my $spliceflat = $_[5]; # SAYS WHETHER WE WANT TO USE THE -splice flat OPTION IN GENEWISE
  364. my $parameterfile = $_[6]; # THE NAME OF THE INTRON PARAMETER FILE
  365. my $scaffoldname = $_[7]; # NAME OF THE SCAFFOLD
  366. my $errorcode = 0; # RETURNED AS 0 IF THERE IS NO ERROR.
  367. my $errormsg = "none";# RETURNED AS 'none' IF THERE IS NO ERROR.
  368. my $random_number; # RANDOM NUMBER FOR TEMPORARY FILE NAME
  369. my $hmmfile; # FILE CONTAINING THE HMM
  370. my $genewise; # TEMPORARY FILE FOR THE GENEWISE OUTPUT FOR THIS HMM
  371. my $cmd; # THE GENEWISE COMMAND TO RUN
  372. my $genewise_exe = "/nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/src/bin/genewise"; # wise 2.4.1, can use -genestats
  373.  
  374. # CHECK THE HMM LOOKS OK:
  375. if (substr($hmm,0,8) ne 'HMMER2.0' && substr($hmm,length($hmm)-2,2) ne '//')
  376. {
  377. $errormsg = "ERROR: run_genewise_on_hmm: hmm $hmm\n";
  378. $errorcode = 2; # ERRORCODE=2
  379. return($errorcode,$errormsg);
  380. }
  381.  
  382. # CHECK THE SPLICEFLAT OPTION IS 'yes' OR 'no':
  383. if ($spliceflat ne 'yes' && $spliceflat ne 'no')
  384. {
  385. $errormsg = "ERROR: run_genewise_on_hmm: spliceflat is $spliceflat (should be yes or no)\n";
  386. $errorcode = 4; # ERRORCODE=4
  387. return($errorcode,$errormsg);
  388. }
  389.  
  390. # WRITE THE HMM TO A FILE:
  391. $random_number = rand();
  392. $hmmfile = $outputdir."/tmp".$random_number;
  393. open(HMMFILE,">$hmmfile") || die "ERROR: run_genewise_on_hmm: cannot open $hmmfile\n";
  394. print HMMFILE "$hmm";
  395. close(HMMFILE);
  396.  
  397. # WRITE THE FAMILY NAME IN THE OUTPUT FILE:
  398. system "echo $hmmname >> $output";
  399.  
  400. # RUN GENEWISE:
  401. $random_number = rand();
  402. $genewise = $outputdir."/tmp".$random_number;
  403. print STDERR "Scaffold $scaffoldname: running genewise for HMM $hmmname ...\n";
  404. if ($parameterfile ne 'none' && $spliceflat eq 'no')
  405. {
  406. $cmd = "$genewise_exe $hmmfile $input_fasta -gff -hmmer -genestats $parameterfile -nosplice_gtag > $genewise";
  407. }
  408. elsif ($parameterfile eq 'none' && $spliceflat eq 'yes')
  409. {
  410. $cmd = "$genewise_exe $hmmfile $input_fasta -gff -hmmer -splice_gtag > $genewise";
  411. }
  412. elsif ($parameterfile eq 'none' && $spliceflat eq 'no')
  413. {
  414. $cmd = "$genewise_exe $hmmfile $input_fasta -gff -hmmer -nosplice_gtag > $genewise"; # USES THE gene.stats FILE THAT COMES WITH GENEWISE, /nfs/users/nfs_a/alc/Documents/GeneWise/wise2.4.1/wisecfg/gene.stat
  415. }
  416. elsif ($parameterfile ne 'none' && $spliceflat eq 'yes')
  417. {
  418. $errormsg = "ERROR: run_genewise_on_hmm: cannot have spliceflat $spliceflat and parameterfile $parameterfile\n";
  419. $errorcode = 5; # ERRORCODE=5
  420. return($errorcode,$errormsg);
  421. }
  422. system "$cmd";
  423.  
  424. # CONCATENATE THIS GENEWISE OUTPUT ONTO THE MAIN OUTPUT FILE OF GENEWISE OUTPUT:
  425. sleep(1);
  426. system "cat $genewise";
  427. system "cat $genewise >> $output";
  428.  
  429. # DELETE TEMPORARY FILES:
  430. system "rm -f $hmmfile";
  431. system "rm -f $genewise";
  432.  
  433. return($errorcode,$errormsg);
  434. }
  435.  
  436. #------------------------------------------------------------------#
  437.  
  438. # TEST &print_error
  439.  
  440. sub test_print_error
  441. {
  442. my $errormsg; # RETURNED AS 'none' FROM A FUNCTION IF THERE WAS NO ERROR
  443. my $errorcode; # RETURNED AS 0 FROM A FUNCTION IF THERE WAS NO ERROR
  444.  
  445. ($errormsg,$errorcode) = &print_error(45,45,1);
  446. if ($errorcode != 12) { print STDERR "ERROR: test_print_error: failed test1\n"; exit;}
  447.  
  448. ($errormsg,$errorcode) = &print_error('My error message','My error message',1);
  449. if ($errorcode != 11) { print STDERR "ERROR: test_print_error: failed test2\n"; exit;}
  450.  
  451. ($errormsg,$errorcode) = &print_error('none',45,1);
  452. if ($errorcode != 13) { print STDERR "ERROR: test_print_error: failed test3\n"; exit;}
  453.  
  454. ($errormsg,$errorcode) = &print_error('My error message', 0, 1);
  455. if ($errorcode != 13) { print STDERR "ERROR: test_print_error: failed test4\n"; exit;}
  456. }
  457.  
  458. #------------------------------------------------------------------#
  459.  
  460. # PRINT OUT AN ERROR MESSAGE AND EXIT.
  461.  
  462. sub print_error
  463. {
  464. my $errormsg = $_[0]; # THIS SHOULD BE NOT 'none' IF AN ERROR OCCURRED.
  465. my $errorcode = $_[1]; # THIS SHOULD NOT BE 0 IF AN ERROR OCCURRED.
  466. my $called_from_test = $_[2]; # SAYS WHETHER THIS WAS CALLED FROM test_print_error OR NOT
  467.  
  468. if ($errorcode =~ /[A-Z]/ || $errorcode =~ /[a-z]/)
  469. {
  470. if ($called_from_test == 1)
  471. {
  472. $errorcode = 11; $errormsg = "ERROR: print_error: the errorcode is $errorcode, should be a number.\n"; # ERRORCODE=11
  473. return($errormsg,$errorcode);
  474. }
  475. else
  476. {
  477. print STDERR "ERROR: print_error: the errorcode is $errorcode, should be a number.\n";
  478. exit;
  479. }
  480. }
  481.  
  482. if (!($errormsg =~ /[A-Z]/ || $errormsg =~ /[a-z]/))
  483. {
  484. if ($called_from_test == 1)
  485. {
  486. $errorcode = 12; $errormsg = "ERROR: print_error: the errormessage $errormsg does not seem to contain text.\n"; # ERRORCODE=12
  487. return($errormsg,$errorcode);
  488. }
  489. else
  490. {
  491. print STDERR "ERROR: print_error: the errormessage $errormsg does not seem to contain text.\n";
  492. exit;
  493. }
  494. }
  495.  
  496. if ($errormsg eq 'none' || $errorcode == 0)
  497. {
  498. if ($called_from_test == 1)
  499. {
  500. $errorcode = 13; $errormsg = "ERROR: print_error: errormsg $errormsg, errorcode $errorcode.\n"; # ERRORCODE=13
  501. return($errormsg,$errorcode);
  502. }
  503. else
  504. {
  505. print STDERR "ERROR: print_error: errormsg $errormsg, errorcode $errorcode.\n";
  506. exit;
  507. }
  508. }
  509. else
  510. {
  511. print STDERR "$errormsg";
  512. exit;
  513. }
  514.  
  515. return($errormsg,$errorcode);
  516. }
  517.  
  518. #------------------------------------------------------------------#
Add Comment
Please, Sign In to add comment