Ejemplo n.º 1
0
        public static bool CheckSettings(string filepath, ISettingsData currentSettings)
        {
            if (string.IsNullOrWhiteSpace(filepath) || !File.Exists(filepath))
            {
                return(false);
            }

            var fileSettings = new SettingsData();

            using (var streamReader = new StreamReader(new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                var line = streamReader.ReadLine();
                if (line != null && !line.StartsWith("#"))
                {
                    // Later versions: comment line is the second line (after the headers)
                    line = streamReader.ReadLine();
                }

                if (string.IsNullOrWhiteSpace(line) || !line.StartsWith("#"))
                {
                    return(false);
                }

                fileSettings.PopulateFromTsvComment(line);
            }

            return(currentSettings.SettingsEquals(fileSettings));
        }
Ejemplo n.º 2
0
        private void Init()
        {
            if (isUsingActualConfig)
            {
                // Load configurations
                GameConfiguration.Load();
                settingsData = GameConfiguration.Settings;
            }
            else
            {
                settingsData = new SettingsData();
                var a = settingsData.AddTabData(new SettingsTab("A", "icon-arrow-left"));
                a.AddEntry(new SettingsEntryBool("a-a", testDataAA            = new BindableBool(false)));
                a.AddEntry(new SettingsEntryBool("a-b", testDataAB            = new BindableBool(true)));
                a.AddEntry(new SettingsEntryEnum <TestType>("a-c", testDataAC = new Bindable <TestType>(TestType.TypeB)));

                var b = settingsData.AddTabData(new SettingsTab("B", "icon-backward"));
                b.AddEntry(new SettingsEntryFloat("b-a", testDataBA = new BindableFloat(0f, -10f, 10f)));
                b.AddEntry(new SettingsEntryFloat("b-b", testDataBB = new BindableFloat(5f, 10f, 20f)));
                b.AddEntry(new SettingsEntryInt("b-c", testDataBC   = new BindableInt(0, -20, 5)));
            }

            // Create nav bar.
            navBar = RootMain.CreateChild <NavBar>("nav-bar");
            {
                navBar.Size = new Vector2(64f, 400f);
                navBar.SetSettingsData(settingsData);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WallboxClient"/> class.
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="logger"></param>
 public WallboxClient(ISettingsData settings,
                      ILogger <WallboxClient> logger) : base(logger)
 {
     HostName = settings.HostName;
     Port     = settings.Port;
     Timeout  = settings.Timeout;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the settings data to build nav tabs based on.
        /// </summary>
        public void SetSettingsData(ISettingsData data)
        {
            if (data == null)
            {
                Cleanup();
                return;
            }
            if (this.settingsData == data)
            {
                return;
            }

            Cleanup();
            this.settingsData = data;

            InvokeAfterTransformed(1, () =>
            {
                CellSize = new Vector2(Width, Height / data.TabCount);

                foreach (var tabData in data.GetTabs())
                {
                    var tabButton = CreateChild <NavTab>("tab-" + tabData.Name, tabs.Count);
                    tabButton.SetTabData(tabData);
                    tabs.Add(tabButton);

                    tabButton.OnTriggered += () =>
                    {
                        OnTabFocused?.Invoke(tabData);
                    };
                }
            });
        }
 public static void SetDefaultThresholds(this ISettingsData settings)
 {
     settings.DefaultIntensityThreshold          = 10000;
     settings.EdgeNETThresholdMinutes            = 0.5;
     settings.ElutionConcurrenceThresholdMinutes = 0.5;
     settings.SignalToNoiseHeuristicThreshold    = 10;
     settings.CheckAllCompounds = false;
 }
Ejemplo n.º 6
0
 public SettingsProcess(ISettingsData settingsData,
                        IFieldofwaterData fieldOfWater,
                        IIdeaStatusData ideaStatusData)
 {
     this.settingsData   = settingsData;
     this.fieldOfWater   = fieldOfWater;
     this.ideaStatusData = ideaStatusData;
 }
Ejemplo n.º 7
0
 public IdeaProcess(IFieldofwaterData fieldOfWaterData,
                    ISettingsData settingsData,
                    IIdeasData ideaData,
                    IFileProcess fileProcess)
 {
     this.fieldOfWaterData = fieldOfWaterData;
     this.settingsData     = settingsData;
     this.ideaData         = ideaData;
     this.fileProcess      = fileProcess;
 }
        public static bool SettingsEquals(this ISettingsData settings1, ISettingsData settings2)
        {
            if (settings1 == null || settings2 == null)
            {
                return(false);
            }

            if (!settings1.DefaultIntensityThreshold.Equals(settings2.DefaultIntensityThreshold) ||
                !settings1.EdgeNETThresholdMinutes.Equals(settings2.EdgeNETThresholdMinutes) ||
                !settings1.ElutionConcurrenceThresholdMinutes.Equals(settings2.ElutionConcurrenceThresholdMinutes) ||
                !settings1.SignalToNoiseHeuristicThreshold.Equals(settings2.SignalToNoiseHeuristicThreshold))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(settings1.CompoundThresholdFileSha1Hash) &&
                string.IsNullOrWhiteSpace(settings1.CompoundThresholdFileSha1Hash) &&
                string.IsNullOrWhiteSpace(settings1.CompoundThresholdFilePath) &&
                string.IsNullOrWhiteSpace(settings1.CompoundThresholdFilePath))
            {
                return(true);
            }

            if (string.IsNullOrWhiteSpace(settings1.CompoundThresholdFileSha1Hash) ||
                string.IsNullOrWhiteSpace(settings1.CompoundThresholdFileSha1Hash))
            {
                return(false);
            }

            if (!settings1.CompoundThresholdFileSha1Hash.Equals(settings2.CompoundThresholdFileSha1Hash))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(settings1.CompoundThresholdFilePath) ||
                string.IsNullOrWhiteSpace(settings1.CompoundThresholdFilePath))
            {
                return(false);
            }

            if (settings1.CompoundThresholdFilePath.Equals(settings2.CompoundThresholdFilePath))
            {
                return(true);
            }

            // If direct equality was false, try again, comparing only the file names
            if (!Path.GetFileName(settings1.CompoundThresholdFilePath).Equals(Path.GetFileName(settings2.CompoundThresholdFilePath)))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the settings data to display content for.
        /// </summary>
        public void SetSettingsData(ISettingsData settingsData)
        {
            if (settingsData == null)
            {
                Cleanup();
                return;
            }
            else if (this.settingsData == settingsData)
            {
                return;
            }

            Cleanup();
            this.settingsData = settingsData;

            InvokeAfterTransformed(1, () =>
            {
                scrollviewHeight = Height;

                // Create content groups.
                ResetPosition();
                container.Height = containerHeight = 0f;
                foreach (var tab in settingsData.GetTabs())
                {
                    var group = container.CreateChild <ContentGroup>(tab.Name);
                    {
                        group.Anchor = AnchorType.TopStretch;
                        group.Pivot  = PivotType.Top;
                        group.Y      = -container.Height;
                        group.SetOffsetHorizontal(0f);
                    }
                    group.SetTabData(tab);
                    groups.Add(group);

                    container.Height = (containerHeight += group.Height);
                }

                maxScrollPos = Math.Max(containerHeight - scrollviewHeight, 0f);

                // Cache position progress of each group for tab focus feature.
                if (maxScrollPos > 0f)
                {
                    foreach (var group in groups)
                    {
                        group.PositionProgress = -group.Y / containerHeight;
                    }
                }
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Removes previous states and child components for a new settings data.
        /// </summary>
        public void Cleanup()
        {
            for (int i = 0; i < groups.Count; i++)
            {
                groups[i].Destroy();
            }
            groups.Clear();

            settingsData = null;
            focusedTab   = null;

            scrollviewHeight = 0f;
            containerHeight  = 0f;
            maxScrollPos     = 0f;
        }
        public static void ComputeSha1(this ISettingsData settings)
        {
            if (string.IsNullOrWhiteSpace(settings.CompoundThresholdFilePath) || !File.Exists(settings.CompoundThresholdFilePath))
            {
                settings.CompoundThresholdFileSha1Hash = "";
                return;
            }

            using (var stream = new FileStream(settings.CompoundThresholdFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (var sha1 = new SHA1Managed())
                {
                    var hash = sha1.ComputeHash(stream);
                    settings.CompoundThresholdFileSha1Hash = string.Join("", hash.Select(x => x.ToString("x2")));
                }
        }
        public static string ConvertToTsvComment(this ISettingsData settings)
        {
            var formatted = $"DefaultIntensityThreshold: {settings.DefaultIntensityThreshold:0.###}; NET time threshold (min): {settings.EdgeNETThresholdMinutes:0.###}";

            formatted += $"; Elution Concurrence threshold (min): {settings.ElutionConcurrenceThresholdMinutes:0.###}; S/N Heuristic threshold: {settings.SignalToNoiseHeuristicThreshold:0.###}";

            if (!string.IsNullOrWhiteSpace(settings.CompoundThresholdFilePath))
            {
                if (string.IsNullOrWhiteSpace(settings.CompoundThresholdFileSha1Hash))
                {
                    settings.ComputeSha1();
                }
                formatted += $"; CompoundThresholdsFile: \"{settings.CompoundThresholdFilePath}\"; SHA1Hash {settings.CompoundThresholdFileSha1Hash}";
            }

            return(formatted);
        }
Ejemplo n.º 13
0
        public static List <CompoundData> ReadMethodData(this IMethodReader reader, ISettingsData settings)
        {
            var transitions = reader.GetAllTransitions();

            if (!settings.CheckAllCompounds)
            {
                transitions = transitions.GetHeavyTransitions();
            }

            //Console.WriteLine($"File \"{reader.DatasetPath}\": {transitions.Count} heavy transitions in instrument method.");
            if (transitions.Count == 0)
            {
                var heavy = settings.CheckAllCompounds ? "" : " heavy";
                Console.WriteLine($"ERROR: Could not read instrument methods or find{heavy} transitions for file \"{reader.DatasetPath}\"");
                return(null);
            }
            // TODO: Could determine heavy peptides by checking names vs. precursor m/z?
            return(transitions.JoinTransitions(settings));
        }
Ejemplo n.º 14
0
        public MainWindowViewModel(
            IWindowManager windowManager,
            IArgipApiData argipApiData,
            ISettingsData settingsData,
            AccessTokenService accessTokenService,
            CartHolder cartHolder)
        {
            this.windowManager      = windowManager;
            this.argipApiData       = argipApiData;
            this.settingsData       = settingsData;
            this.accessTokenService = accessTokenService;
            this.cartHolder         = cartHolder;

            ProductList        = new BindableCollection <Product>();
            ProductCustomIndex = new BindableCollection <Product>();

            // read settings from store
            var settings = settingsData.ReadSettings();

            BaseApiAddress = settings.BaseApiAddress;
            TokenEndpoint  = settings.TokenEndpoint;
            ClientId       = settings.ClientId;
            ClientSecret   = settings.ClientSecret;
        }
        public static void PopulateFromTsvComment(this ISettingsData settings, string tsvCommentLine)
        {
            var match = TsvCommentSettingsRegex.Match(tsvCommentLine);

            var defaultThreshold = match.Groups["defaultThreshold"].Value;

            if (!string.IsNullOrWhiteSpace(defaultThreshold))
            {
                settings.DefaultIntensityThreshold = double.Parse(defaultThreshold);
            }

            var netTimeThreshold = match.Groups["netTimeThreshold"].Value;

            if (!string.IsNullOrWhiteSpace(netTimeThreshold))
            {
                settings.EdgeNETThresholdMinutes = double.Parse(netTimeThreshold);
            }

            var elutionConcurrenceThreshold = match.Groups["elutionConcurrenceThreshold"].Value;

            if (!string.IsNullOrWhiteSpace(elutionConcurrenceThreshold))
            {
                settings.ElutionConcurrenceThresholdMinutes = double.Parse(elutionConcurrenceThreshold);
            }

            var snHeuristicThreshold = match.Groups["snHeuristicThreshold"].Value;

            if (!string.IsNullOrWhiteSpace(snHeuristicThreshold))
            {
                settings.SignalToNoiseHeuristicThreshold = double.Parse(snHeuristicThreshold);
            }

            // if not match, the value is string.Empty. (also .Success will be false)
            settings.CompoundThresholdFilePath     = match.Groups["filepath"].Value.Trim().Trim('"', '\'');
            settings.CompoundThresholdFileSha1Hash = match.Groups["fileHash"].Value.Trim();
        }
Ejemplo n.º 16
0
        public static void WriteCombinedResultsToFile(string filepath, List <CompoundData> results, ISettingsData settings)
        {
            foreach (var compound in results)
            {
                if (compound.Transitions.Count >= 10)
                {
                    System.Console.WriteLine(@"Warning: Will not output additional transition for compound ""{0}"": it already has 10 transitions.", compound.CompoundName);
                }

                compound.CalculateSummaryData();
            }
            var maxTrans = results.Max(x => x.Transitions.Count);

            using (var csv = new CsvWriter(new StreamWriter(new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))))
            {
                csv.Configuration.RegisterClassMap(new CompoundResultMap(maxTrans));
                csv.Configuration.Delimiter     = "\t";
                csv.Configuration.Comment       = '#';
                csv.Configuration.AllowComments = true;

                // write the header first
                csv.WriteHeader <CompoundData>();
                csv.NextRecord();

                // Write the settings comment
                csv.WriteComment(" Settings: " + settings.ConvertToTsvComment());
                // Make sure to finish the line
                csv.NextRecord();

                // Write everything else (which shouldn't include the headers).
                csv.WriteRecords(results);
            }
        }
        public static Dictionary <string, CompoundThresholdData> LoadCompoundThresholds(this ISettingsData settings)
        {
            if (string.IsNullOrWhiteSpace(settings.CompoundThresholdFilePath) || !File.Exists(settings.CompoundThresholdFilePath))
            {
                return(null);
            }

            var thresholds = CompoundThresholdData.ReadFromFile(settings.CompoundThresholdFilePath).ToList();

            return(CompoundThresholdData.ConvertToSearchMap(thresholds));
        }
Ejemplo n.º 18
0
        //Client program that connect to the server.
        void OpenPipeClient()
        {
            try
            {
                NetNamedPipeBinding binding = new NetNamedPipeBinding();
                binding.MaxBufferPoolSize = 100000000;
                binding.MaxBufferSize = 100000000;
                binding.MaxReceivedMessageSize = 100000000;
                binding.SendTimeout = TimeSpan.MaxValue;
                binding.ReceiveTimeout = TimeSpan.MaxValue;

                binding.ReaderQuotas.MaxArrayLength = 100000000;
                binding.ReaderQuotas.MaxBytesPerRead = 100000000;
                binding.ReaderQuotas.MaxDepth = 100000000;
                binding.ReaderQuotas.MaxNameTableCharCount = 100000000;
                binding.ReaderQuotas.MaxStringContentLength = 100000000;

                EndpointAddress endpoint = new EndpointAddress("net.pipe://localhost/ISettingsData");
                LockerChannel = new ChannelFactory<ISettingsData>(binding, endpoint);
                LockerAccess = LockerChannel.CreateChannel();
                LockerChannel.Faulted += LockerChannel_Faulted;
                LockerChannel.Closed += LockerChannel_Closed;

                nVenTory = new StoredInventoryWrapper(LockerAccess);
                cHarActors = new ServerCharStatsWrapper(LockerAccess);

            }catch(Exception ex){LogError(ex);}
        }
 internal StoredInventoryWrapper(ISettingsData PipeAccess)
 {
     LockerAccess = PipeAccess;
 }
Ejemplo n.º 20
0
        public void WritePdf(List <CompoundData> results, ISettingsData settings, bool useNonVectorImages = false)
        {
            if (useNonVectorImages && Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
            {
                var thread = new Thread(() => WritePdf(results, settings, useNonVectorImages));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
                return;
            }

            Func <List <CompoundData>, int, int, int, XImage> summaryPlotCreateMethod = CreatePlot;
            Func <CompoundData, int, int, int, XImage>        plotCreateMethod        = CreatePlot;
            var plotSizeMultiplier = 3d;

            if (useNonVectorImages)
            {
                summaryPlotCreateMethod = CreatePlotBitmapWpf;
                plotCreateMethod        = CreatePlotBitmapWpf;
                // Plot text is naturally larger in OxyPlot.WPF-rendered images, so increase the size multiplier
                plotSizeMultiplier = 4;
            }

            // Guarantee that the plots will be backed at 300+ DPI
            var desiredResolution = 300;
            var resolution        = 96;

            // Add a header: Dataset name
            currentPageY += AddText(DatasetName, fontHeader, 0.75, position: XStringFormats.BaseLineCenter);

            // Add the analysis settings
            currentPageY += AddText("Q4SRM Analysis settings:", fontHeader2);
            currentPageY += AddText($"Input file path: {DatasetPath}", fontDefault);
            currentPageY += AddText($"Compound minimum summed intensity threshold: {settings.DefaultIntensityThreshold:F0}", fontDefault);
            currentPageY += AddText($"Compound peak elution concurrence threshold (minutes): {settings.ElutionConcurrenceThresholdMinutes:F2}", fontDefault);
            currentPageY += AddText($"Transition minimum peak distance from elution window edge (minutes): {settings.ElutionConcurrenceThresholdMinutes:F2}", fontDefault);
            currentPageY += AddText($"Transition minimum signal to noise heuristic (max intensity / median intensity): {settings.SignalToNoiseHeuristicThreshold:F2}", fontDefault);
            if (!string.IsNullOrWhiteSpace(settings.CompoundThresholdFilePath))
            {
                currentPageY += AddText($"Per-compound intensity threshold file path: {settings.CompoundThresholdFilePath}", fontDefault);
                currentPageY += AddText($"Per-compound intensity threshold file SHA1: {settings.CompoundThresholdFileSha1Hash}", fontDefault);
            }

            // Add the summary plot
            var summaryPlotAspectRatio = 4.0 / 3.0;
            var summaryPlotWidth       = currentPage.Width - DoublePageMargin;
            var summaryPlotHeight      = summaryPlotWidth / summaryPlotAspectRatio;
            var summaryPlotWidthWpf    = (int)(summaryPlotWidth * plotSizeMultiplier);
            var summaryPlotHeightWpf   = (int)(summaryPlotHeight * plotSizeMultiplier);
            var summaryPlotImage       = summaryPlotCreateMethod(results, summaryPlotWidthWpf, summaryPlotHeightWpf, resolution);

            AddPlot(summaryPlotImage, PageMargin, summaryPlotWidth, summaryPlotHeight, null);
            currentPageY += summaryPlotHeight + 25;

            AddPage();

            // Add the error plots
            currentPageY += AddText("Errors:", fontHeader2);
            currentPageY += AddText("Key: int=intensity, pp=peak position, ec=elution concurrence, sn=S/N heuristic", fontDefault);

            var plotSize      = (currentPage.Width - DoublePageMargin - 10) / 3;
            var wpfRenderSize = (int)(plotSize * plotSizeMultiplier);

            // Check the resolution vs. pdf render size
            if (wpfRenderSize < desiredResolution / (double)resolution * plotSize)
            {
                wpfRenderSize = (int)(desiredResolution / (double)resolution * plotSize);
            }

            var counter    = 0;
            var xOffset    = PageMargin;
            var textHeight = GetTextHeight("int", currentPageGraphics, fontDefault);

            foreach (var result in results.Where(x => !x.PassesAllThresholds).OrderBy(x => x.CompoundName))
            {
                if (counter % 3 == 0 && counter > 0)
                {
                    xOffset       = PageMargin;
                    currentPageY += textHeight + plotSize + 25;
                    if (currentPageY + textHeight + plotSize > currentPage.Height - PageMargin)
                    {
                        AddPage();
                    }
                }

                counter++;

                var plotImage = plotCreateMethod(result, wpfRenderSize, wpfRenderSize, resolution);
                AddPlot(plotImage, xOffset, plotSize, plotSize, $"{counter}: {GetCompoundDataHeader(result)}");
                xOffset += plotSize + 5;
            }

            currentPageY += textHeight + plotSize + 25;
            if (currentPageY + textHeight + plotSize > currentPage.Height - PageMargin)
            {
                AddPage();
            }

            // Add the passing plots
            currentPageY += AddText("Passes:", fontHeader2);

            counter = 0;
            xOffset = PageMargin;
            foreach (var result in results.Where(x => x.PassesAllThresholds).OrderBy(x => x.CompoundName))
            {
                if (counter % 3 == 0 && counter > 0)
                {
                    xOffset       = PageMargin;
                    currentPageY += plotSize;
                    if (currentPageY + plotSize > currentPage.Height - PageMargin)
                    {
                        AddPage();
                    }
                }
                counter++;

                var plotImage = plotCreateMethod(result, wpfRenderSize, wpfRenderSize, resolution);
                AddPlot(plotImage, xOffset, plotSize, plotSize, null);
                xOffset += plotSize;
            }

            currentPageY += plotSize + 25;
            //if (currentPageY + plotSize > currentPage.Height - PageMargin)
            //{
            //    AddPage();
            //}

            document.Save(SavePath);
        }
 internal ServerCharStatsWrapper(ISettingsData PipeAccess)
 {
     LockerAccess = PipeAccess;
 }
 /// <summary>
 /// Event called when the settings data has changed.
 /// </summary>
 private void OnSettingsDataChange(ISettingsData data)
 {
     navBar.SetSettingsData(data);
     contentHolder.SetSettingsData(data);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Sets the settings data to visually represent.
 /// </summary>
 public void SetSettingsData(ISettingsData settings)
 {
     currentSettings.Value = settings;
 }
Ejemplo n.º 24
0
        public static List <CompoundData> JoinTransitions(this List <TransitionData> transitions, ISettingsData settings)
        {
            var compoundThresholds = settings.LoadCompoundThresholds();

            if (compoundThresholds == null)
            {
                compoundThresholds = new Dictionary <string, CompoundThresholdData>();
            }
            var combined = new Dictionary <string, CompoundData>();

            foreach (var item in transitions)
            {
                if (!combined.TryGetValue(item.CompoundName, out var group))
                {
                    group = new CompoundData(item)
                    {
                        IntensityThreshold                 = settings.DefaultIntensityThreshold,
                        EdgeNETThresholdMinutes            = settings.EdgeNETThresholdMinutes,
                        ElutionConcurrenceThresholdMinutes = settings.ElutionConcurrenceThresholdMinutes,
                        SignalToNoiseHeuristicThreshold    = settings.SignalToNoiseHeuristicThreshold
                    };
                    // Look for and handle custom thresholds
                    if (compoundThresholds.TryGetValue(item.CompoundName, out var cThreshold))
                    {
                        group.IntensityThreshold = cThreshold.Threshold;
                    }
                    combined.Add(group.CompoundName, group);
                }
                group.Transitions.Add(item);
            }

            return(combined.Values.ToList());
        }
Ejemplo n.º 25
0
 public void InjectMetod(ISettingsData settingsData)
 {
     this.settingsData = settingsData;
 }