#! perl -w

use strict;
use warnings;
no warnings 'recursion';

my $VERSION = "1.0";

use Neuron::SWC::Read;
use Neuron::SWC::Write;
use Neuron::XML::Write;

use Neuron::Morphometrics::EntireNeuron;
use Neuron::Morphometrics::Segment;
use Neuron::Morphometrics::Bifurcation;
use Neuron::Morphometrics::Compartment;
use Neuron::Morphometrics::Tools;

use Neuron::Statistics::StdDev;

sub usage 
{
	print<<"EOU";

usage: MorphometricsList <inputfile>
EOU
	exit;
}

usage if !defined($ARGV[0]);
usage if defined($ARGV[1]);
-e $ARGV[0] || die "Error: $ARGV[0] does not exist.";

print "MorphometricsList $VERSION (Neuron $NEURON_VERSION)\n";
print "parsing $ARGV[0], please wait...";

my @arr = readData("$ARGV[0]");
my $rall = rall(\@arr);
my $ralldev = stdDev(\@arr, "rall");

print "\n\n";
print "=========================================================\n";
print "STATISTICS ON ENTIRE NEURON\n";
print "=========================================================\n";
print "Number of stems        = ", numStems(\@arr), "\n";
print "Number of terminals    = ", numTerminals(\@arr), "\n";
print "Minimum X              = ", minX(\@arr), "\n";
print "Maximum X              = ", maxX(\@arr), "\n";
print "Minimum Y              = ", minY(\@arr), "\n";
print "Maximum Y              = ", maxY(\@arr), "\n";
print "Minimum Z              = ", minZ(\@arr), "\n";
print "Maximum Z              = ", maxZ(\@arr), "\n";
print "Minimum branch order   = ", minBranchOrder(\@arr), "\n";
print "Maximum branch order   = ", maxBranchOrder(\@arr), "\n";
print "Average branch order   = ", avgBranchOrder(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "order"), "\n";
print "Volume                 = ", volume(\@arr), "\n";
print "Area                   = ", area(\@arr), "\n";
print "=========================================================\n";
print "STATISTICS ON COMPARTMENTS\n";
print "=========================================================\n";
print "Number of compartments = ", numCompartments(\@arr), "\n";
print "Minimum diameter       = ", minDiameter(\@arr), "\n";
print "Maximum diameter       = ", maxDiameter(\@arr), "\n";
print "Average diameter       = ", avgDiameter(\@arr), "\n";
print "Average volume         = ", avgVolume(\@arr), "\n";
print "Average area           = ", avgArea(\@arr), "\n";
print "Min path distance      = ", minCompartmentPathDistance(\@arr), "\n";
print "Max path distance      = ", maxCompartmentPathDistance(\@arr), "\n";
print "Avg path distance      = ", avgCompartmentPathDistance(\@arr), "\n";
print "Min eucl. distance     = ", minCompartmentEuclidianDistance(\@arr), "\n";
print "Max eucl. distance     = ", maxCompartmentEuclidianDistance(\@arr), "\n";
print "Avg eucl. distance     = ", avgCompartmentEuclidianDistance(\@arr), "\n";
print "Min comp. length       = ", minCompartmentLength(\@arr), "\n";
print "Max comp. length       = ", maxCompartmentLength(\@arr), "\n";
print "Avg comp. length       = ", avgCompartmentLength(\@arr), "\n";
print "Min Burke's Taper Rate = ", minBurkeTaperRate(\@arr), "\n";
print "Max Burke's Taper Rate = ", maxBurkeTaperRate(\@arr), "\n";
print "Avg Burke's Taper Rate = ", avgBurkeTaperRate(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "taper"), "\n";
print "=========================================================\n";
print "STATISTICS ON BIFURCATIONS\n";
print "=========================================================\n";
print "Number of bifurcations = ", numBifurcations(\@arr), "\n";
print "Average daughter ratio = ", avgDaughterRatio(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "kidratio"), "\n";
print "Asymmetry              = ", avgAsymmetry(\@arr), "\n";
print "Avg comp. ampl. angle  = ", compartmentAmplitudeAngle(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "caangle"), "\n";
print "Avg seg. ampl. angle   = ", segmentAmplitudeAngle(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "saangle"), "\n";
print "Avg bifurcation torque = ", bifurcationTorqueAngle(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "btangle"), "\n";
print "Tilt                   = ", tilt(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "tilt"), "\n";
print "Rall's Value           = ", $rall, "\n";
print " standard deviation    = ", $ralldev, "\n";
print "Power Correction       = ", powerCorrection(\@arr, $rall), "\n";
print " standard deviation    = ", stdDev(\@arr, "pc"), "\n";
print "P/C diameter ratio     = ", diameterRatio(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "dratio"), "\n";
print "=========================================================\n";
print "STATISTICS ON SEGMENTS\n";
print "=========================================================\n";
print "Number of segments     = ", numSegments(\@arr), "\n";
print "Min Segment Taper      = ", minSegmentTaper(\@arr), "\n";
print "Max Segment Taper      = ", maxSegmentTaper(\@arr), "\n";
print "Avg Segment Taper      = ", avgSegmentTaper(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "taper"), "\n";
print "Min Fragmentation      = ", minFragmentation(\@arr), "\n";
print "Max Fragmentation      = ", maxFragmentation(\@arr), "\n";
print "Avg Fragmentation      = ", avgFragmentation(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "fragmentation"), "\n";
print "Contraction            = ", contraction(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "contraction"), "\n";
print "Min eucl. seg. length  = ", minSegmentEuclidianLength(\@arr), "\n";
print "Max eucl. seg. length  = ", maxSegmentEuclidianLength(\@arr), "\n";
print "Avg eucl. seg. length  = ", avgSegmentEuclidianLength(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "elength"), "\n";
print "Min seg. path length   = ", minSegmentPathLength(\@arr), "\n";
print "Max seg. path length   = ", maxSegmentPathLength(\@arr), "\n";
print "Avg seg. path length   = ", avgSegmentPathLength(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "length"), "\n";
print "Min eucl. distance     = ", minSegmentEuclidianDistance(\@arr), "\n";
print "Max eucl. distance     = ", maxSegmentEuclidianDistance(\@arr), "\n";
print "Avg eucl. distance     = ", avgSegmentEuclidianDistance(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "edistance"), "\n";
print "Min path distance      = ", minSegmentPathDistance(\@arr), "\n";
print "Max path distance      = ", maxSegmentPathDistance(\@arr), "\n";
print "Avg path distance      = ", avgSegmentPathDistance(\@arr), "\n";
print " standard deviation    = ", stdDev(\@arr, "distance"), "\n";