private string displayHeatMapData(AlignmentResult alignmentResult)
        {
            var sb = new StringBuilder();

            for (var i = alignmentResult.AlignmentHeatmapScores.GetLength(1) - 1; i >= 0; i--)
            {
                for (var k = 0; k < alignmentResult.AlignmentHeatmapScores.GetLength(0); k++)
                {
                    sb.Append(alignmentResult.AlignmentHeatmapScores[k, i]);
                    sb.Append("\t");
                }
                sb.Append(Environment.NewLine);
            }
            return(sb.ToString());
        }
        public clsAlignmentFunction GetAlignment(List <TargetBase> massTagList, List <TargetedResultDTO> featuresToAlign)
        {
            var multialignMassTagDB = new clsMassTagDB();

            //TODO: I might be able to dynamically update these values. Take my foundFeatures and calculate their avg PPMDiff. Then use that info here.
            var alignmentOptions = new clsAlignmentOptions();

            alignmentOptions.MassCalibrationWindow         = this.AlignerParameters.MassCalibrationWindow; //note -  it seems that 50 ppm is used as a default setting in VIPER.
            alignmentOptions.ContractionFactor             = this.AlignerParameters.ContractionFactor;
            alignmentOptions.IsAlignmentBaselineAMasstagDB = this.AlignerParameters.IsAlignmentBaselineAMassTagDB;
            alignmentOptions.MassBinSize = this.AlignerParameters.MassBinSize;
            alignmentOptions.MassCalibrationLSQNumKnots      = this.AlignerParameters.MassCalibrationLSQNumKnots;
            alignmentOptions.MassCalibrationLSQZScore        = this.AlignerParameters.MassCalibrationLSQZScore;
            alignmentOptions.MassCalibrationMaxJump          = this.AlignerParameters.MassCalibrationMaxJump;
            alignmentOptions.MassCalibrationMaxZScore        = this.AlignerParameters.MassCalibrationMaxZScore;
            alignmentOptions.MassCalibrationNumMassDeltaBins = this.AlignerParameters.MassCalibrationNumMassDeltaBins;
            alignmentOptions.MassCalibrationNumXSlices       = this.AlignerParameters.MassCalibrationNumXSlices;
            alignmentOptions.MassCalibrationUseLSQ           = this.AlignerParameters.MassCalibrationUseLSQ;
            alignmentOptions.MassCalibrationWindow           = this.AlignerParameters.MassCalibrationWindow;
            alignmentOptions.MassTolerance        = this.AlignerParameters.MassToleranceForNETAlignment;
            alignmentOptions.MaxPromiscuity       = this.AlignerParameters.MaxPromiscuity;
            alignmentOptions.MaxTimeJump          = this.AlignerParameters.MaxTimeJump;
            alignmentOptions.NETBinSize           = this.AlignerParameters.NETBinSize;
            alignmentOptions.NETTolerance         = this.AlignerParameters.NETTolerance;
            alignmentOptions.NumTimeSections      = this.AlignerParameters.NumTimeSections;
            alignmentOptions.UsePromiscuousPoints = this.AlignerParameters.UsePromiscuousPoints;

            var processor = new clsAlignmentProcessor();

            processor.AlignmentOptions = alignmentOptions;


            var multiAlignMassTags = convertDeconToolsMassTagsToMultialignMassTags(massTagList);

            multialignMassTagDB.AddMassTags(multiAlignMassTags);
            processor.SetReferenceDatasetFeatures(multialignMassTagDB);

            var multialignUMCs = convertDeconToolsLCMSFeaturesToMultialignFeatures(featuresToAlign);

            processor.SetAligneeDatasetFeatures(multialignUMCs, alignmentOptions.MZBoundaries[0]);
            processor.PerformAlignmentToMSFeatures();

            this.Result = getResultsForAlignment(processor);


            return(processor.GetAlignmentFunction());
        }
        private AlignmentResult getResultsForAlignment(clsAlignmentProcessor processor)
        {
            float[] scanLCValues = null;
            float[] NETValues    = null;

            float[,] scores = null;

            processor.GetAlignmentHeatMap(ref scores, ref scanLCValues, ref NETValues);

            var result = new AlignmentResult();

            result.ScanLCValues           = scanLCValues;
            result.NETValues              = NETValues;
            result.AlignmentHeatmapScores = scores;


            //get massResiduals_vs_scan and massResiduals_vs_m/z
            var residuals = processor.GetResidualData();


            result.Mass_vs_scan_ResidualsBeforeAlignment = residuals.massError;
            result.Mass_vs_scan_ResidualsAfterAlignment  = residuals.massErrorCorrected;
            result.Mass_vs_scan_ResidualsScanValues      = residuals.scans;


            result.Mass_vs_mz_ResidualsBeforeAlignment = residuals.mzMassError;
            result.Mass_vs_mz_ResidualsAfterAlignment  = residuals.mzMassErrorCorrected;
            result.Mass_vs_mz_ResidualsMZValues        = residuals.mz;


            //get stats on variability
            result.NETStDev    = processor.GetNETStandardDeviation();
            result.NETAverage  = processor.GetNETMean();
            result.MassAverage = processor.GetMassMean();
            result.MassStDev   = processor.GetMassStandardDeviation();

            double[,] massHistogramData  = null;
            double[,] netHistogramData   = null;
            double[,] driftHistogramData = null;
            processor.GetErrorHistograms(0.1, 0.002, 0.1, ref massHistogramData, ref netHistogramData, ref driftHistogramData);

            result.massHistogramData = massHistogramData;
            result.NETHistogramData  = netHistogramData;


            return(result);
        }
        public void Result([FromBody] string JobResult)
        {
            AlignmentResult AlignmentResultFormGrid = JsonConvert.DeserializeObject <AlignmentResult>(JobResult);
            string          Email     = Repo.GetEmailByAlingmnetJobId(AlignmentResultFormGrid.JobId);
            string          Decrypted = Serializer.Decrypt(AlignmentResultFormGrid.Result, "ResultComputing");

            Repo.FinalizeJob(AlignmentResultFormGrid.JobId, Decrypted);
            MailMessage EMailMessage = new MailMessage("*****@*****.**", Email);

            EMailMessage.Subject    = "Grid Notification";
            EMailMessage.IsBodyHtml = true;
            EMailMessage.Body       = $"We Have done your Alignment Job, you can check it out in your history page! <a href='http://mtidna.azurewebsites.net/Display/{AlignmentResultFormGrid.JobId}'> Check my History Now </a>";
            SmtpClient SC = new SmtpClient("smtp.gmail.com", 587);

            SC.DeliveryMethod = SmtpDeliveryMethod.Network;
            SC.Credentials    = new NetworkCredential("*****@*****.**", "Mti_dna2017");
            SC.EnableSsl      = true;
            SC.Send(EMailMessage);
        }
Beispiel #5
0
        /// <summary>
        /// Main Edlib method.
        /// </summary>
        /// <param name="originalQuery">String a</param>
        /// <param name="originalTarget">String b</param>
        /// <param name="config">Configuration</param>
        /// <returns>Result of the alignment</returns>
        public static AlignmentResult Align(string originalQuery, string originalTarget, AlignmentConfig config)
        {
            // NOTE: Is other mode useful? If so, why?
            if (config.Mode == AlignmentMode.Hw || config.Mode == AlignmentMode.Shw)
            {
                throw new NotImplementedException();
            }

            AlignmentResult result = new AlignmentResult
            {
                Status            = (int)AlignmentStatus.Ok,
                EditDistance      = -1,
                EndLocations      = null,
                StartingLocations = null,
                NumberOfLocations = 0,
                Alignment         = null,
                AlignmentLength   = 0,
                AlphabetLength    = 0,
            };

            // Transform sequences and recognize alphabet
            byte[] query, target;
            string alphabet = TransformSequences(originalQuery, originalTarget, out query, out target);

            result.AlphabetLength = alphabet.Length;

            // Initialization
            int queryLength  = originalQuery.Length;
            int targetLength = originalTarget.Length;
            int maxBlocks    = CeilDivision(queryLength, WordSize);
            int w            = maxBlocks * WordSize - queryLength;
            EqualityDefinition equalityDefinition = new EqualityDefinition(alphabet, config.AdditionalEqualities,
                                                                           config.AdditionalEqualitiesLength);

            ulong[] peq = BuildPeq(alphabet.Length, query, queryLength, ref equalityDefinition);

            // Main Calculation
            int           positionNw    = -1;
            AlignmentData alignmentData = new AlignmentData();
            bool          dynamicK      = false;
            int           k             = config.K;

            if (k < 0) // If valid k is not given, auto-adjust k until solution is found.
            {
                dynamicK = true;
                k        = WordSize; // Gives better results than smaller k.
            }

            do
            {
                MyersEditDistanceNw(peq, w, maxBlocks, queryLength, target, targetLength, k, false, -1,
                                    ref result.EditDistance, ref positionNw, ref alignmentData);
                k *= 2;
            } while (dynamicK && result.EditDistance == -1);

            // NOTE: Do we need this block code? We only care about editing distance
            // Since we only care about the editing distance score, this is where we stop
            if (result.EditDistance >= 0)
            {
                // If NW mode, set end location explicitly.
                if (config.Mode == AlignmentMode.Nw)
                {
                    result.EndLocations      = new int[sizeof(int) * 1];
                    result.EndLocations[0]   = targetLength - 1;
                    result.NumberOfLocations = 1;
                }

//                if (!(config.Task == AlignmentTask.TaskLocate || config.Task == AlignmentTask.TaskPath))
//                {
//                    for (int i = 0; i < result.NumberOfLocations; i++) {
//                        result.StartingLocations[i] = 0;
//                    }
//                }
            }

            return(result);
        }