« blib/lib/Software/GenoScan/SeqAnnotator.pm
↑ Summary
blib/lib/Software/GenoScan/HairpinClassifier.pm »
| 1 | package Software::GenoScan::OutputProcessor; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | require Exporter; | ||
| 7 | |||
| 8 | our $VERSION = "v1.0.4"; | ||
| 9 | our @ISA = qw(Exporter); | ||
| 10 | our %EXPORT_TAGS = ("all" => [ qw( | ||
| 11 | writeOutput | ||
| 12 | ) ] ); | ||
| 13 | our @EXPORT_OK = (@{ $EXPORT_TAGS{"all"} }); | ||
| 14 | |||
| 15 | #Description: Writes miRNA candidates to output file | ||
| 16 | #Parameters: (1) probability threshold, (2) low-complexity thresshold, (3) output directory, (4) verbose flag, (5) log array | ||
| 17 | #Return value: None | ||
| 18 | sub writeOutput($ $ $ $ $){ | ||
| 19 | my ($PROBABILITY_THRESHOLD, $LOW_COMPLEXITY, $OUTPUT_DIR, $VERBOSE, $logArray) = @_; | ||
| 20 | if(! -e $OUTPUT_DIR){ | ||
| 21 | system("mkdir $OUTPUT_DIR"); | ||
| 22 | } | ||
| 23 | if(!-e "$OUTPUT_DIR/step_5"){ | ||
| 24 | system("mkdir $OUTPUT_DIR/step_5"); | ||
| 25 | } | ||
| 26 | if($VERBOSE){ | ||
| 27 | print(" Filtering hairpins by low-complexity > $LOW_COMPLEXITY and probability >= $PROBABILITY_THRESHOLD\n"); | ||
| 28 | } | ||
| 29 | push(@{$logArray}, "Step 5: write miRNA candidates to output file\n"); | ||
| 30 | |||
| 31 | #Read regression model report | ||
| 32 | open(REPORT, "$OUTPUT_DIR/step_4/log_reg_model_report") or die "GenoScan error: Unable to read log_reg_model_report\n"; | ||
| 33 | my @report = <REPORT>; | ||
| 34 | close(REPORT); | ||
| 35 | my $numHp = scalar(@report); | ||
| 36 | if($VERBOSE){ | ||
| 37 | print(" Total number of hairpins: $numHp\n"); | ||
| 38 | } | ||
| 39 | push(@{$logArray}, "\tTotal number of hairpins: $numHp\n"); | ||
| 40 | |||
| 41 | #Filter by low-complexity and probability threshold | ||
| 42 | open(PASS, ">$OUTPUT_DIR/step_5/miRNA_candidates.fasta"); | ||
| 43 | my $passCounter = 0; | ||
| 44 | my $lowCompCounter = $numHp; | ||
| 45 | foreach my $hp (@report){ | ||
| 46 | $hp =~ s/\s+$//; | ||
| 47 | my ($header, $seq, $probability) = split(/\t/, $hp); | ||
| 48 | my $lowComp = () = $seq =~ m/[augc]/g; | ||
| 49 | $lowComp = $lowComp / length($seq); | ||
| 50 | if($lowComp > $LOW_COMPLEXITY){ | ||
| 51 | $lowCompCounter--; | ||
| 52 | next; | ||
| 53 | } | ||
| 54 | if($probability >= $PROBABILITY_THRESHOLD){ | ||
| 55 | $passCounter++; | ||
| 56 | print(PASS ">$header\n$seq\n"); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | close(PASS); | ||
| 60 | if($VERBOSE){ | ||
| 61 | print(" Number of hairpins passing low-complexity: $lowCompCounter\n"); | ||
| 62 | print(" Number of hairpins passing threshold: $passCounter\n"); | ||
| 63 | } | ||
| 64 | push(@{$logArray}, "\tNumber of hairpins passing low-complexity: $lowCompCounter\n"); | ||
| 65 | push(@{$logArray}, "\tNumber of hairpins passing threshold: $passCounter\n"); | ||
| 66 | |||
| 67 | #Write logfile | ||
| 68 | open(LOG, ">$OUTPUT_DIR/step_5/genoscan_log") or die "Unable to write logfile\n"; | ||
| 69 | print(LOG @{$logArray}); | ||
| 70 | close(LOG); | ||
| 71 | if($VERBOSE){ | ||
| 72 | print(" miRNA candidates written to $OUTPUT_DIR/step_5/miRNA_candidates.fasta\n"); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | return 1; | ||
| 77 |