Example #1
0
        public async static void AnalysisDBTest()
        {
            var snapshot1 = new ArrivalTimeSnapShot();
            snapshot1.DriftTubeVoltageInVolt = 1000;
            snapshot1.MeasuredArrivalTimeInMs = 22;
            snapshot1.PressureInTorr = 4;
            snapshot1.TemperatureInKelvin = 10;
            var iso1 = new IdentifiedIsomerInfo(2 ,222, 0.9, 10.5, 115, 123, new List<ArrivalTimeSnapShot>(){snapshot1}, 100, AnalysisStatus.Positive, new PeakScores(1.0, 0.8, 0.7), new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), 0.1, 0);
            var idens = new List<IdentifiedIsomerInfo>() {iso1};
            
            PeakScores scores = new PeakScores(0, 0.5, 1);
            CrossSectionWorkflowResult result1 = new CrossSectionWorkflowResult("ABC_Dataset_01", new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.2), scores, 0.5, OutputFileDir, "123");
            CrossSectionWorkflowResult result2 = new CrossSectionWorkflowResult("ABC_Dataset_02", new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result3 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C2H4O16P2", IonizationMethod.Deprotonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result4 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C2H4O16P2", IonizationMethod.Sodiumated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result5 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C10H40", IonizationMethod.Protonated, "googlin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result6 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C10H40", IonizationMethod.Protonated, "googlin"), AnalysisStatus.Negative, null, idens, scores, 0.8, OutputFileDir, "123");

            string fileName = @"output\test.sqlite";
            AnalysisLibrary lib = new AnalysisLibrary(fileName);
            await lib.CreateTables();
            await lib.InsertResult(result1);
            await lib.InsertResult(result2);
            await lib.InsertResult(result3);
            await lib.InsertResult(result4);
            await lib.InsertResult(result5);
            await lib.InsertResult(result6);
        }
 /// <summary>
 /// The sum feature scores.
 /// </summary>
 /// <param name="a">
 /// The a.
 /// </param>
 /// <param name="b">
 /// The b.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public static PeakScores AddFeatureScores(PeakScores a, PeakScores b)
 {
     double intensityScore = a.IntensityScore + b.IntensityScore;
     double isotopicScore = a.IsotopicScore + b.IsotopicScore;
     double peakShapeScore = a.PeakShapeScore + b.PeakShapeScore;
     return new PeakScores(intensityScore, isotopicScore, peakShapeScore);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservedPeak"/> class with peak and its calculated statistics.
 /// </summary>
 /// <param name="group">
 /// The group.
 /// </param>
 /// <param name="peak">
 /// The peak.
 /// </param>
 /// <param name="statistics">
 /// The Statistics.
 /// </param>
 public ObservedPeak(VoltageGroup group, StandardImsPeak peak, PeakScores statistics)
 {
     this.VoltageGroup = group;
     this.Peak = peak;
     this.Statistics = statistics;
     this.ObservationType = ObservationType.Peak;
     this.mobilityPoint = null;
 }
Example #4
0
        public static void SerializerDeserializerTest()
        {
            IList<CrossSectionWorkflowResult> results = new List<CrossSectionWorkflowResult>();

            // create fake result 1
            IdentifiedIsomerInfo holyGrail1 = new IdentifiedIsomerInfo(10, 250, 6, 10, 22, 4, null, 5, AnalysisStatus.Positive, new PeakScores(1,2,3), new MolecularTarget("C2H34", IonizationMethod.APCI, "Carbon"), 1, 2);
            PeakScores averageFeatureScores1 = new PeakScores(3, 4, 5);

            IImsTarget target1 = new MolecularTarget("C2H5OH", IonizationMethod.Deprotonated, "Ginger ale");
            IImsTarget target2 = new MolecularTarget("C2H5OH", IonizationMethod.Sodiumated, "Volka");

            CrossSectionWorkflowResult result1 = new CrossSectionWorkflowResult(
                "France", 
                target1,
                AnalysisStatus.Positive,
                null,averageFeatureScores1,
                4,
                "",
                "");

            results.Add(result1);

            // Serialize fake result struct
            IFormatter formatter = new BinaryFormatter();
            using (Stream stream = new FileStream("serialized_result.bin", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                formatter.Serialize(stream, results);
            }

            IList<CrossSectionWorkflowResult> newResults;

            // deserialize fake result struct
            using (Stream stream = new FileStream("serialized_result.bin", FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                newResults = (IList<CrossSectionWorkflowResult>)formatter.Deserialize(stream);
            }

            CrossSectionWorkflowResult result2 = newResults.First();

            // Compare it
            var result = newResults.First();
            Assert.AreEqual(result.AnalysisStatus, result1.AnalysisStatus);
            Assert.AreEqual(result.DatasetName, result2.DatasetName);
            Assert.AreEqual(result.AverageObservedPeakStatistics.IntensityScore, result2.AverageObservedPeakStatistics.IntensityScore);
        }
        /// <summary>
        /// The average feature scores.
        /// </summary>
        /// <param name="scoreHolders">
        /// The score holders.
        /// </param>
        /// <returns>
        /// The <see cref="PeakScores"/>.
        /// </returns>
        public static PeakScores AverageFeatureStatistics(IEnumerable<PeakScores> scoreHolders)
        {
            int count = 0;
            PeakScores statistics = new PeakScores(0, 0, 0);

            foreach (var scoreHolder in scoreHolders)
            {
                count++;
                statistics = AddFeatureScores(statistics, scoreHolder);
            }

            if (count == 0)
            {
                return statistics;
            }
            else
            {
                double intensityScore = statistics.IntensityScore / count;
                double isotopicScore = statistics.IsotopicScore / count;
                double peakShapeScore = statistics.PeakShapeScore / count;
                return new PeakScores(intensityScore, isotopicScore, peakShapeScore);
            }
        }
 /// 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;
 }
 /// <summary>
 /// The compare feature input.
 /// </summary>
 /// <param name="a">
 /// The a.
 /// </param>
 /// <param name="b">
 /// The b.
 /// </param>
 /// <param name="likelihoodFunc">
 /// The likelihood Func.
 /// </param>
 /// <returns>
 /// The <see cref="int"/>.
 /// </returns>
 private static int CompareFeatureScore(PeakScores a, PeakScores b, LikelihoodFunc likelihoodFunc)
 {
     return likelihoodFunc(a).CompareTo(likelihoodFunc(b));
 }
        /// <summary>
        /// The report feature evaluation.
        /// </summary>
        /// <param name="peak">
        /// The peak.
        /// </param>
        /// <param name="scores">
        /// The scores.
        /// </param>
        /// <param name="verbose">
        /// The verbose.
        /// </param>
        /// <param name="target">
        /// The target.
        /// </param>
        /// <param name="badScanRange">
        /// The bad scan range.
        /// </param>
        /// <param name="lowAbsoluteIntensity">
        /// The low intensity.
        /// </param>
        /// <param name="lowRelativeIntensity"></param>
        /// <param name="badPeakShape">
        /// The bad peak shape.
        /// </param>
        /// <param name="lowIsotopicAffinity">
        /// The low isotopic affinity.
        /// </param>
        /// <returns>
        /// If the feature pass all the filters <see cref="bool"/>.
        /// </returns>
        private static string ReportFeatureEvaluation(StandardImsPeak peak, PeakScores scores, bool verbose, IImsTarget target, bool badScanRange, bool lowAbsoluteIntensity, bool lowRelativeIntensity, bool badPeakShape, bool lowIsotopicAffinity)
        {
            Trace.WriteLine(string.Format("        Candidate feature found at [centerMz = {0:F4}, drift time = {1:F2} ms(#{2})] ", peak.PeakApex.MzCenterInDalton, peak.PeakApex.DriftTimeCenterInMs,     peak.PeakApex.DriftTimeCenterInScanNumber));
            Trace.WriteLine(string.Format("            IntensityScore: {0:F4}", scores.IntensityScore));

            if (!lowAbsoluteIntensity)
            {
                Trace.WriteLine(string.Format("            peakShapeScore: {0:F4}", scores.PeakShapeScore));

                if (target.HasCompositionInfo)
                {
                    Trace.WriteLine(string.Format("            isotopicScore:  {0:F4}", scores.IsotopicScore));
                }
            }

            string rejectionReason = badScanRange ? "[Bad scan range] " :
                lowAbsoluteIntensity ? "[Low Absolute Intensity] " :
                badPeakShape ? "[Bad Peak Shape] " :
                lowIsotopicAffinity ? "[Different Isotopic Profile] " :
                lowRelativeIntensity ? "[Low Relative Intensity] " : string.Empty;

            bool rejected = badScanRange || lowAbsoluteIntensity || lowIsotopicAffinity || badPeakShape || lowRelativeIntensity;

            if (verbose)
            {
                if (rejected)
                {
                    Trace.WriteLine("        " + rejectionReason);
                }
                else
                {
                    Trace.WriteLine("        [PASS]");
                }

                Trace.WriteLine(string.Empty);
            }

            return rejectionReason;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IdentifiedIsomerInfo"/> class.
 /// </summary>
 /// <param name="numberOfFeaturePointsUsed">
 /// The number of feature points used.
 /// </param>
 /// <param name="mzInDalton"></param>
 /// <param name="rSquared">
 /// The r squred.
 /// </param>
 /// <param name="mobility">
 /// The mobility.
 /// </param>
 /// <param name="crossSectionalArea">
 /// The cross sectional area.
 /// </param>
 /// <param name="averageVoltageGroupStabilityScore">
 /// The average voltage group stability score.
 /// </param>
 /// <param name="arrivalTimeSnapShots">
 /// The arrival time snap shots.
 /// </param>
 /// <param name="viperCompatibleMass">
 /// The viper Compatible Mass.
 /// </param>
 /// <param name="analysisStatus"></param>
 /// <param name="peakScores"></param>
 /// <param name="target"></param>
 public IdentifiedIsomerInfo(
     int numberOfFeaturePointsUsed,
     double mzInDalton,
     double rSquared, 
     double mobility, 
     double crossSectionalArea, 
     double averageVoltageGroupStabilityScore, 
     IEnumerable<ArrivalTimeSnapShot> arrivalTimeSnapShots, 
     double viperCompatibleMass, 
     AnalysisStatus analysisStatus, 
     PeakScores peakScores,
     IImsTarget target,
     double t0,
     double bestMzInPpm)
 {
     this.NumberOfFeaturePointsUsed = numberOfFeaturePointsUsed;
     this.RSquared = rSquared;
     this.Mobility = mobility;
     this.CrossSectionalArea = crossSectionalArea;
     this.AverageVoltageGroupStabilityScore = averageVoltageGroupStabilityScore;
     this.ArrivalTimeSnapShots = arrivalTimeSnapShots;
     this.ViperCompatibleMass = viperCompatibleMass;
     this.AnalysisStatus = analysisStatus;
     this.PeakScores = peakScores;
     this.T0 = t0;
     this.MzInDalton = mzInDalton;
     this.MzInPpm = Metrics.DaltonToPpm(mzInDalton - target.MassWithAdduct, target.MassWithAdduct);
     this.RelativeMzInPpm = Math.Abs(MzInPpm - bestMzInPpm);
 }