Algorithm-TrunkClassifier
view release on metacpan or search on metacpan
Algorithm/TrunkClassifier/ppport.h view on Meta::CPAN
sub find_api
{
my $code = shift;
$code =~ s{
/ (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*)
| "[^"\\]*(?:\\.[^"\\]*)*"
| '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx;
grep { exists $API{$_} } $code =~ /(\w+)/mg;
}
while (<DATA>) {
if ($hint) {
my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings;
if (m{^\s*\*\s(.*?)\s*$}) {
for (@{$hint->[1]}) {
$h->{$_} ||= ''; # suppress warning with older perls
$h->{$_} .= "$1\n";
}
}
else { undef $hint }
}
Algorithm/TrunkClassifier/ppport.h view on Meta::CPAN
exit 2;
}
sub strip
{
my $self = do { local(@ARGV,$/)=($0); <> };
my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms;
$copy =~ s/^(?=\S+)/ /gms;
$self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms;
$self =~ s/^SKIP.*(?=^__DATA__)/SKIP
if (\@ARGV && \$ARGV[0] eq '--unstrip') {
eval { require Devel::PPPort };
\$@ and die "Cannot require Devel::PPPort, please install.\\n";
if (\$Devel::PPPort::VERSION < $VERSION) {
die "$0 was originally generated with Devel::PPPort $VERSION.\\n"
. "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n"
. "Please install a newer version, or --unstrip will not work.\\n";
}
Devel::PPPort::WriteFile(\$0);
exit 0;
Algorithm/TrunkClassifier/ppport.h view on Meta::CPAN
Sorry, but this is a stripped version of \$0.
To be able to use its original script and doc functionality,
please try to regenerate this file using:
\$^X \$0 --unstrip
END
/ms;
my($pl, $c) = $self =~ /(.*^__DATA__)(.*)/ms;
$c =~ s{
/ (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*)
| ( "[^"\\]*(?:\\.[^"\\]*)*"
| '[^'\\]*(?:\\.[^'\\]*)*' )
| ($HS+) }{ defined $2 ? ' ' : ($1 || '') }gsex;
$c =~ s!\s+$!!mg;
$c =~ s!^$LF!!mg;
$c =~ s!^\s*#\s*!#!mg;
$c =~ s!^\s+!!mg;
open OUT, ">$0" or die "cannot strip $0: $!\n";
print OUT "$pl$c\n";
exit 0;
}
__DATA__
*/
#ifndef _P_P_PORTABILITY_H_
#define _P_P_PORTABILITY_H_
#ifndef DPPP_NAMESPACE
# define DPPP_NAMESPACE DPPP_
#endif
#define DPPP_CAT2(x,y) CAT2(x,y)
lib/Algorithm/TrunkClassifier.pm view on Meta::CPAN
my $CLASSIFY = "loocv"; #Classification procedure (loocv|split|dual)
my $SPLITPERCENT = 20; #Percentage of samples to use as test set when using -c split
my $TESTSET = ""; #Name of test dataset when using -c dual
my $CLASSNAME = "TISSUE"; #Name of classification variable
my $OUTPUT = "."; #Name of output folder
my $LEVELS = 0; #Number of levels in decision trunks (forced)
my $PROSPECT = ""; #Check input data without running classifier
my $SUPPFILE = ""; #File containing class information
my $VERBOSE = 0; #Report progress during classifier run
my $USEALL = 0; #Circumvent level selection and use all trunks for classification
my $DATAFILE = ""; #File containing input data
#Description: Wrapper function for running the decision trunk classifier
#Parameters: Command line arguments
#Return value: None
sub runClassifier{
#Handle commands line arguments
my $processor = Algorithm::TrunkClassifier::CommandProcessor->new(\$CLASSIFY, \$SPLITPERCENT, \$TESTSET, \$CLASSNAME, \$OUTPUT, \$LEVELS, \$PROSPECT, \$SUPPFILE, \$VERBOSE, \$USEALL, \$DATAFILE);
$processor->processCmd(@_);
#Read input data
if($VERBOSE){
print("Trunk classifier: Reading input data\n");
}
my $dataWrapper = Algorithm::TrunkClassifier::DataWrapper->new($CLASSNAME, $PROSPECT, $SUPPFILE, $DATAFILE, $VERBOSE, "input data file");
my $testset;
if($CLASSIFY eq "dual"){
$testset = Algorithm::TrunkClassifier::DataWrapper->new($CLASSNAME, $PROSPECT, $SUPPFILE, $TESTSET, $VERBOSE, "testset data file");
if($VERBOSE){
print("Trunk classifier: Two datasets used, checking probe overlap\n");
}
my @probeSet1 = $dataWrapper->getProbeList();
my @probeSet2 = $testset->getProbeList();
foreach my $query (@probeSet1){
my $found = 0;
lib/Algorithm/TrunkClassifier.pm view on Meta::CPAN
last;
}
}
if(!$found){
die "Error: Probe '$query' in input data file not found in testset data file\n";
}
}
}
#Run cross validation loop
Algorithm::TrunkClassifier::Classification->trainAndClassify($dataWrapper, $testset, $CLASSIFY, $SPLITPERCENT, $TESTSET, $CLASSNAME, $OUTPUT, $LEVELS, $VERBOSE, $DATAFILE, $USEALL);
}
return 1;
lib/Algorithm/TrunkClassifier/Classification.pm view on Meta::CPAN
our $VERSION = "v1.0.1";
#Description: Function responsible for building decision trunks and classifying test samples using LOOCV
#Parameters: (1) Package, (2) input dataset, (3) test dataset, (4) classification procedure, (5) split percent,
# (6) testset data file name, (7) classification variable name, (8) output folder name,
# (9) number of levels, (10) verbose flag, (11) input data file name (12) useall flag
#Return value: None
sub trainAndClassify($ $ $ $ $ $ $ $ $ $ $ $ $){
shift(@_);
my ($dataWrapper, $testset, $CLASSIFY, $SPLITPERCENT, $TESTFILE, $CLASSNAME, $OUTPUT, $LEVELS, $VERBOSE, $DATAFILE, $USEALL) = @_;
#Create output files
if(!-e $OUTPUT && $OUTPUT ne "."){
system("mkdir $OUTPUT");
}
open(PERFORMANCE, ">$OUTPUT/performance.txt") or die "Error: Unable to create output file\n";
open(LOO_TRUNKS, ">$OUTPUT/loo_trunks.txt") or die "Error: Unable to create output file\n";
open(CTS_TRUNKS, ">$OUTPUT/cts_trunks.txt") or die "Error: Unable to create output file\n";
open(REPORT, ">$OUTPUT/class_report.txt") or die "Error: Unable to create output file\n";
open(LOG, ">$OUTPUT/log.txt") or die "Error: Unable to create output file\n";
lib/Algorithm/TrunkClassifier/Classification.pm view on Meta::CPAN
print(REPORT join("\n", @classReport));
if($CLASSIFY ne "dual"){
$TESTFILE = "NA";
}
if($CLASSIFY ne "split"){
$SPLITPERCENT = "NA";
}
my $name1 = $dataWrapper->getClassOneName();
my $name2 = $dataWrapper->getClassTwoName();
my $log = "Trunk classifier log\n";
$log .= "Input data file: $DATAFILE\n";
$log .= "Testset data file: $TESTFILE\n";
$log .= "Procedure: $CLASSIFY\n";
$log .= "Split percent: $SPLITPERCENT\n";
$log .= "Number of levels: $numTrunkLevels[0]\n";
$log .= "Classification variable: $CLASSNAME\n";
$log .= "Training set classes:\n";
if($CLASSIFY eq "loocv"){
$log .= "\tClass one size: " . $dataWrapper->getClassSize($name1) . " ($name1)\n";
$log .= "\tClass two size: " . $dataWrapper->getClassSize($name2) . " ($name2)\n";
}
lib/Algorithm/TrunkClassifier/DataWrapper.pm view on Meta::CPAN
if(scalar(keys(%{$classes{$classVar}})) != 2){
die "Error: Class variable $classVar in supplementary file does not have two classes\n";
}
}
if(!%sampleClasses){
warn "Warning: No sample classes found in supplementary file\n";
return $dataFileName;
}
#Read input data file and write new data file with classification info
open(DATA_FILE, $dataFileName) or die "Unable to open $datasetType '$dataFileName'\n";
my @dataFile = <DATA_FILE>;
close(DATA_FILE);
my @header = split(/\t/, $dataFile[0]);
shift(@header);
chomp(@header);
foreach my $sampleName (@header){
$sampleName = uc($sampleName);
$sampleName =~ s/\n|\r//g;
}
$dataFileName =~ s/\.[^.]+$/_wmeta.txt/;
if($VERBOSE){
print("Trunk classifier: Supplementary file supplied, writing new $datasetType with meta data\n");
}
open(DATA_FILE, ">$dataFileName") or die "Unable to create new data file '$dataFileName'\n";
my $meta = "";
for(my $classVarIndex = 0; $classVarIndex < scalar(@classNames); $classVarIndex++){
my $className = $classNames[$classVarIndex];
my @classKeys = keys(%{$classes{$className}});
$meta .= "#CLASSVAR $className @classKeys\n";
$meta .= "#CLASSMEM $className";
foreach my $sampleName (@header){
if(!$sampleClasses{$sampleName}[$classVarIndex]){
warn "Warning: Sample '$sampleName' has no '$className' class in supplementary file\n";
$meta .= " " . "#NA";
}
else{
$meta .= " " . $sampleClasses{$sampleName}[$classVarIndex];
}
}
$meta .= "\n";
}
print(DATA_FILE $meta . join("", @dataFile));
close(DATA_FILE);
return $dataFileName;
}
#Description: Reads input data file with expression values and meta data
#Parameters: (1) TrunkClassifier::DataWrapper object, (2) classification variable name
# (3) prospect flag, (4) input data file name, (5) dataset type
#Return value: None
sub readExpData($ $ $ $ $){
my ($self, $className, $prospect, $dataFileName, $datasetType) = @_;
$className = uc($className);
#Read input data file
if(!open(DATA_FILE, $dataFileName)){
die "Error: Unable to open $datasetType '$dataFileName'\n";
}
my @dataFile = <DATA_FILE>;
close(DATA_FILE);
my $content = join("", @dataFile);
$content =~ s/\r|\n\r|\r\n/\n/g;
@dataFile = split(/\n+/, $content);
foreach my $row (@dataFile){
$row =~ s/\n//g;
}
#Extract meta data rows
my @metarows;
pod/TrunkClassifier.pod view on Meta::CPAN
the classifier. This is done for every sample in the input dataset. See the the algorithm
publication for more details. A PubMed link can be found in L</"SEE ALSO">.
=head2 ARGUMENTS
Following installation, the algorithm can be run from the terminal using the
run_classifier.pl script supplied in the t/ folder. The command should be in this form
C<perl run_classifier.pl [Options] [Input data file]>
=head3 INPUT DATA FILE
The last argument must be the name of the input data file containing the expression
data in table format, where columns are tab-separated. The first row must contains
column names and the first column must contain row names. Samples need to be given in
columns and probes/attributes in rows. Before the name of the input data file, a number of
optional arguments may be given, see L</"OPTIONS"> below. A data file containing random data
is provided in the t/ folder.
=head3 META DATA
At the top of the input data file, before the expression data table, an number of meta data
rows starting with # can be given. The purpose of these rows is to tell the algorithm
what classification variables that are defined for the data and what classes the samples
belong to. The classification variable is the name of the property by which the samples
are divided into two groups. For example, if the samples should be classified as either
early or late stage cancer, the name of the classification variable would be STAGE.
Classification variables are defined on rows starting with #CLASSVAR, followed by the
name of the variable and the two class labels.
( run in 2.202 seconds using v1.01-cache-2.11-cpan-007c89162af )