internal static CrossSectionWorkflowResult CreateResultFromAssociationHypothesis(CrossSectionSearchParameters parameters, AssociationHypothesis optimalHypothesis, IImsTarget target, IEnumerable<VoltageGroup> allVoltageGroups, IEnumerable<ObservedPeak> allPeaks, string datasetPath, string analysisPath, string  sampleCollectionDate, double viperCompatibleMass = 0)
        {
            // Initialize the result struct.
            AssociationHypothesisInfo associationHypothesisInfo = new AssociationHypothesisInfo(optimalHypothesis.ProbabilityOfDataGivenHypothesis, optimalHypothesis.ProbabilityOfHypothesisGivenData);

            double averageVoltageGroupScore = VoltageGroupScoring.ComputeAverageVoltageGroupStabilityScore(allVoltageGroups);
            IEnumerable<PeakScores> allFeatureStatistics = allPeaks.Select(x => x.Statistics);
            PeakScores averageObservedPeakStatistics = FeatureScoreUtilities.AverageFeatureStatistics(allFeatureStatistics);

            IEnumerable<IsomerTrack> tracks = optimalHypothesis.Tracks.ToList();

            // Find the conformer with the closest m/z
            IsomerTrack trackWithBestMz = tracks.OrderBy(x => Math.Abs(Metrics.DaltonToPpm(x.AverageMzInDalton - target.MassWithAdduct, target.MassWithAdduct))).First();
            double bestMzInPpm = Metrics.DaltonToPpm(trackWithBestMz.AverageMzInDalton - target.MassWithAdduct, target.MassWithAdduct);
            IList<IdentifiedIsomerInfo> isomersInfo = tracks.Select(x => x.ExportIdentifiedIsomerInfo(viperCompatibleMass, allVoltageGroups.Count() - parameters.MaxOutliers, parameters.MinR2,  target, bestMzInPpm)).ToList();

            AnalysisStatus finalStatus = TrackToHypothesisConclusionLogic(isomersInfo.Select(info => info.AnalysisStatus));

            CrossSectionWorkflowResult informedResult = new CrossSectionWorkflowResult(
            datasetPath,
            target,
            finalStatus,
            associationHypothesisInfo,
            isomersInfo,
            averageObservedPeakStatistics,
            averageVoltageGroupScore,
            analysisPath,
            sampleCollectionDate
            );

            return informedResult;
        }
 /// Initializes a new instance of the <see cref="CrossSectionWorkflowResult"/> class. 
 /// Constructor for no isomer result. 
 public CrossSectionWorkflowResult(
     string datasetPath,
     IImsTarget target,
     AnalysisStatus analysisStatus,
     AssociationHypothesisInfo associationHypothesisInfo, 
     PeakScores averageObservedPeakStatistics, 
     double averageVoltageGroupStability, 
     string analysisDirectory, string dateTime)
     : this(datasetPath,
     target,
     analysisStatus,
     associationHypothesisInfo,
     new List<IdentifiedIsomerInfo>(), 
     averageObservedPeakStatistics, 
     averageVoltageGroupStability, 
     analysisDirectory, 
     dateTime)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CrossSectionWorkflowResult"/> class. 
 /// Multiple isomer result constructor
 /// </summary>
 /// <param name="datasetName">
 /// The dataset name.
 /// </param>
 /// <param name="target">
 /// The target.
 /// </param>
 /// <param name="analysisStatus">
 /// The analysis status.
 /// </param>
 /// <param name="associationHypothesisInfo">
 /// The analysis scores holder.
 /// </param>
 /// <param name="isomerResults">
 /// The isomer results.
 /// </param>
 /// <param name="averageObservedPeakStatistics"></param>
 /// <param name="averageVoltageGroupStability"></param>
 /// <param name="datasetPath"></param>
 /// <param name="analysisDirectory"></param>
 /// <param name="dateTime"></param>
 public CrossSectionWorkflowResult(
     string datasetPath,
     IImsTarget target, 
     AnalysisStatus analysisStatus, 
     AssociationHypothesisInfo associationHypothesisInfo, 
     IList<IdentifiedIsomerInfo> isomerResults, 
     PeakScores averageObservedPeakStatistics, 
     double averageVoltageGroupStability, 
     string analysisDirectory, 
     string dateTime)
 {
     this.Target = target;
     this.AnalysisStatus = analysisStatus;
     this.AssociationHypothesisInfo = associationHypothesisInfo;
     this.isomerResults = isomerResults;
     this.AverageObservedPeakStatistics = averageObservedPeakStatistics;
     this.AverageVoltageGroupStability = averageVoltageGroupStability;
     this.AnalysisDirectory = analysisDirectory;
     this.DateTime = dateTime;
     this.DatasetPath = datasetPath;
     this.DatasetName = Path.GetFileNameWithoutExtension(datasetPath);
     this.DateTime = dateTime;
 }