Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ControlOptions()
        {
            InitializeComponent();

            this.cmbSettings.DisplayMember = nameof(NeedlemanWunschOptions.Name);
            this.cmbSettings.Items.AddRange(NeedlemanWunschOptions.LoadOptions().ToArray());
        }
        public void NeedlemanWunschDirectionTest(string seqDirA, string seqDirB, string optionSet, string resultDir)
        {
            List <Sequence> seqA = Controller.GetSequences(seqDirA);

            ConvertSequences(seqA);
            List <Sequence> seqB = Controller.GetSequences(seqDirB);

            ConvertSequences(seqB);

            decimal[,] resultArr = ReadResultMatrix(resultDir);
            int[,] expectedDirs  = new int[resultArr.GetLength(0), resultArr.GetLength(1)];
            for (int i = 0; i < resultArr.GetLength(0); i++)
            {
                for (int j = 0; j < resultArr.GetLength(1); j++)
                {
                    expectedDirs[i, j] = (int)resultArr[i, j];
                }
            }

            NeedlemanWunschOptions options = ReadOptionsFromFile(optionSet);

            NeedlemanWunsch matrix = new NeedlemanWunsch(seqA.ToList(), seqB.ToList(), options);

            int[,] actualDirs = GetAlignDirections(matrix);

            CollectionAssert.AreEqual(expectedDirs, actualDirs);
        }
Beispiel #3
0
 private void cmbSettings_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.cmbSettings.SelectedItem is NeedlemanWunschOptions options)
     {
         this.varOptions = options;
     }
 }
Beispiel #4
0
        private void SetDataToGui(NeedlemanWunschOptions _options)
        {
            this.txtName.Text = _options.Name;

            this.cbxUberLogic.Checked = _options.UberLogic;

            this.nudGapPenalty.Value          = _options.GapPenalty;
            this.cbxAffineGap.Checked         = _options.UseAffineGaps;
            this.nudAffineGapPenalty.Value    = _options.GapExtensionPenalty;
            this.nudDamagePenalty.Value       = _options.DamagePenalty;
            this.cbxAffineDamage.Checked      = _options.UseAffineDamages;
            this.nudAffineDamagePenalty.Value = _options.DamageExtensionPenalty;
            this.nudConversionPenalty.Value   = _options.ConversionPenalty;
            // Weights - Rest
            this.nudRestDuration.Value      = _options.WeightRestDuration;
            this.nudRestBreveduration.Value = _options.WeightRestBreveDuration;
            // Weights - Note
            this.nudNoteBreveduration.Value    = _options.WeightNoteBreveduration;
            this.nudNoteColoration.Value       = _options.WeightNoteColoration;
            this.nudNoteDuration.Value         = _options.WeightNoteDuration;
            this.nudNoteFermata.Value          = _options.WeightNoteFermata;
            this.nudNoteLigatureForm.Value     = _options.WeightNoteLigatureForm;
            this.nudNoteLigaturePosition.Value = _options.WeightNoteLigaturePosition;
            this.nudNotePitchWithAccid.Value   = _options.WeightNotePitchWithAccid;
            this.nudNoteStem.Value             = _options.WeightNoteStem;
            this.nudNoteWrittenPitch.Value     = _options.WeightNoteWrittenPitch;
            // Weights - Mensur
            this.nudMensurLogic.Value = _options.WeightMensurMaximodus;
            this.nudMensurRatio.Value = _options.WeightMensurRatio;
            this.nudMensurSign.Value  = _options.WeightMensurSign;
            // Weights - Proportion
            this.nudProportionAffected.Value = _options.WeightProportionAffected;
            this.nudProportionRatio.Value    = _options.WeightProportionRatio;
            this.nudProportioSign.Value      = _options.WeightProportionSign;
        }
Beispiel #5
0
        private void btnSaveSettings_Click(object sender, EventArgs e)
        {
            // Check if settings with the Name already exists
            NeedlemanWunschOptions optionsFound = this.lstOptions.FirstOrDefault(option => option.Name == this.txtName.Text);

            // If yes ask the user if he wants to replace them
            if (optionsFound != null)
            {
                if (MessageBox.Show(this.FindForm(), "Settings with this name already exist. Replace them?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return;
                }
                // We're still here, read the data from the gui into the object
                this.GetDataFromGui(optionsFound);
            }
            else
            {
                this.GetDataFromGui(this.options2Edit);
                // And append them to the list
                this.lstOptions.Add(this.options2Edit);
            }

            NeedlemanWunschOptions.SaveOptions();

            MessageBox.Show(this.FindForm(), "Options saved!");

            /*
             * // Refresh the ComboBox
             * this.cmbSettings.Items.Clear();
             * this.cmbSettings.Items.AddRange(this.lstOptions.ToArray());
             */
        }
Beispiel #6
0
        private void btnNewOptions_Click(object sender, EventArgs e)
        {
            this.varOptions = new NeedlemanWunschOptions();

            using (DialogNeedlemanWunschOptions dialogOptions = new DialogNeedlemanWunschOptions())
            {
                dialogOptions.Options = this.varOptions;
                if (dialogOptions.ShowDialog(this.FindForm()) == DialogResult.OK)
                {
                    this.varOptions = dialogOptions.Options;
                    this.RefillCombobox();
                }
            }
        }
        //[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "..\\..\\files\\tests.csv", "..\\..\\files\\tests#csv", DataAccessMethod.Sequential)]
        public void NeedlemanWunschMatrixTest(string seqDirA, string seqDirB, string optionSet, string resultDir)
        {
            //List<Sequence> seqA = Controller.GetSequences(TestContext.DataRow["seqA"].ToString());
            List <Sequence> seqA = Controller.GetSequences(seqDirA);

            ConvertSequences(seqA);

            //List<Sequence> seqB = Controller.GetSequences(TestContext.DataRow["seqB"].ToString());
            List <Sequence> seqB = Controller.GetSequences(seqDirB);

            ConvertSequences(seqB);

            decimal[,] expectedResult = ReadResultMatrix(resultDir);

            NeedlemanWunschOptions options = ReadOptionsFromFile(optionSet);

            NeedlemanWunsch matrix = new NeedlemanWunsch(seqA.ToList(), seqB.ToList(), options);

            decimal[,] alignmatrix = GetAlignmatrix(matrix);

            CollectionAssert.AreEqual(expectedResult, alignmatrix);
        }
Beispiel #8
0
        private void GetDataFromGui(NeedlemanWunschOptions _options)
        {
            _options.Name = this.txtName.Text;

            _options.UberLogic = this.cbxUberLogic.Checked;

            _options.GapPenalty             = this.nudGapPenalty.Value;
            _options.UseAffineGaps          = this.cbxAffineGap.Checked;
            _options.GapExtensionPenalty    = this.nudAffineGapPenalty.Value;
            _options.DamagePenalty          = this.nudDamagePenalty.Value;
            _options.UseAffineDamages       = this.cbxAffineDamage.Checked;
            _options.DamageExtensionPenalty = this.nudAffineDamagePenalty.Value;
            _options.ConversionPenalty      = this.nudConversionPenalty.Value;
            // Weights - Rest
            _options.WeightRestDuration      = this.nudRestDuration.Value;
            _options.WeightRestBreveDuration = this.nudRestBreveduration.Value;
            // Weights - Note
            _options.WeightNoteBreveduration    = this.nudNoteBreveduration.Value;
            _options.WeightNoteColoration       = this.nudNoteColoration.Value;
            _options.WeightNoteDuration         = this.nudNoteDuration.Value;
            _options.WeightNoteFermata          = this.nudNoteFermata.Value;
            _options.WeightNoteLigatureForm     = this.nudNoteLigatureForm.Value;
            _options.WeightNoteLigaturePosition = this.nudNoteLigaturePosition.Value;
            _options.WeightNotePitchWithAccid   = this.nudNotePitchWithAccid.Value;
            _options.WeightNoteStem             = this.nudNoteStem.Value;
            _options.WeightNoteWrittenPitch     = this.nudNoteWrittenPitch.Value;
            // Weights - Mensur
            _options.WeightMensurMaximodus = this.nudMensurLogic.Value;
            _options.WeightMensurModus     = this.nudMensurLogic.Value;
            _options.WeightMensurProlatio  = this.nudMensurLogic.Value;
            _options.WeightMensurTempus    = this.nudMensurLogic.Value;
            _options.WeightMensurRatio     = this.nudMensurRatio.Value;
            _options.WeightMensurSign      = this.nudMensurSign.Value;
            // Weights - Proportion
            _options.WeightProportionAffected = this.nudProportionAffected.Value;
            _options.WeightProportionRatio    = this.nudProportionRatio.Value;
            _options.WeightProportionSign     = this.nudProportioSign.Value;
        }
Beispiel #9
0
 private void RefillCombobox()
 {
     this.cmbSettings.Items.Clear();
     this.cmbSettings.Items.AddRange(NeedlemanWunschOptions.LoadOptions().ToArray());
     this.cmbSettings.SelectedItem = this.varOptions;
 }
Beispiel #10
0
        /// <summary>
        /// Konstruktor - Mostly harmless
        /// </summary>
        public DialogNeedlemanWunschOptions()
        {
            InitializeComponent();

            this.lstOptions = NeedlemanWunschOptions.LoadOptions();
        }
Beispiel #11
0
        private void btnRandomSequenceModel_Click(object sender, EventArgs e)
        {
            // Check if we either have an saved Sequence or the user has chosen a sequence to use
            if (this.listBoxChosenCompares.Items.Count == 0 && this.lstRandomizedObjectsA == null && this.lstRandomizedObjectsB == null)
            {
                MessageBox.Show("Please select at least one compare or load a randomized set of data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Extract the options
            NeedlemanWunschOptions options = this.controlOptions.Options;

            List <ObjectInSequence> lstSequenceA = new List <ObjectInSequence>(), lstSequenceB = new List <ObjectInSequence>();
            // Make 2 List for the ObjectsInSequences
            List <List <ObjectInSequence> > lstSequencesA = new List <List <ObjectInSequence> >(), lstSequencesB = new List <List <ObjectInSequence> >();

            // Differ if we have loaded sequences or use the chosen compares
            if (this.lstRandomizedObjectsA != null && this.lstRandomizedObjectsB != null)
            {
                lstSequenceA  = this.lstRandomizedObjectsA[0];
                lstSequencesA = this.lstRandomizedObjectsA.GetRange(1, this.lstRandomizedObjectsA.Count - 1);
                lstSequenceB  = this.lstRandomizedObjectsB[0];
                lstSequencesB = this.lstRandomizedObjectsB.GetRange(1, this.lstRandomizedObjectsB.Count - 1);

                // GO!
                ConcurrentBag <Tuple <decimal, int, int, int, int> > lstDistances = new ConcurrentBag <Tuple <decimal, int, int, int, int> >();

                // Create the Alignment
                NeedlemanWunsch nw = new NeedlemanWunsch(lstSequenceA, lstSequenceB, options, true);

                // DebugCode if we need to see the Original Alignment
                //DialogNeedlemanWunschShowAlign dialogShow = new DialogNeedlemanWunschShowAlign();
                //dialogShow.SetData(nw);
                //dialogShow.ShowDialog(this.FindForm());

                // Now loop over the created sequences and compare all of them
                Parallel.ForEach(lstSequencesA, seqA =>
                {
                    Parallel.ForEach(lstSequencesB, seqB =>
                    {
                        // Build the alignment
                        NeedlemanWunsch nwRandom = new NeedlemanWunsch(seqA, seqB, options, true);
                        // Now we need the distance
                        lstDistances.Add(Tuple.Create(nwRandom.Distance, nwRandom.NumberOfChanges, nwRandom.Backtraces.Min(bt => bt.WayBack.Count), nwRandom.SequenceA.Count, nwRandom.SequenceB.Count));
                    });
                });

                MessageBox.Show(this.FindForm(), $"Distance: {nw.Distance}{Environment.NewLine}" +
                                $"Average Random Distance: {lstDistances.Sum(dis => dis.Item1) / lstDistances.Count}{Environment.NewLine}" +
                                $"Minimum Random Distance: {lstDistances.Min(dis => dis.Item1)}{Environment.NewLine}" +
                                $"Maximum Random Distance: {lstDistances.Max(dis => dis.Item1)}{Environment.NewLine}");

                // Export all distances if wanted
                if (this.saveFileDialogCSV.ShowDialog(this.FindForm()) == DialogResult.OK)
                {
                    SaveCSV(this.saveFileDialogCSV.FileName, nw, lstDistances, lstSequenceA, lstSequenceB);
                }
            }
            else
            {
                // Here we loop over the chosen Compares
                foreach (object objAktuell in this.listBoxChosenCompares.Items)
                {
                    if (objAktuell is CompareObject compObj)
                    {
                        // Create the original sequences - Copy the choosen ones from the List if possible as default
                        lstSequenceA = new List <ObjectInSequence>();
                        lstSequenceB = new List <ObjectInSequence>();
                        compObj.SequenceA.ForEach(item => lstSequenceA.AddRange(item.ObjectsInSequence));
                        compObj.SequenceB.ForEach(item => lstSequenceB.AddRange(item.ObjectsInSequence));

                        // Check if we have locked sequences or create new ones
                        if (compObj.RandomizedSequencesA != null && compObj.RandomizedSequencesB != null)
                        {
                            lstSequencesA = new List <List <ObjectInSequence> >(compObj.RandomizedSequencesA);
                            lstSequencesB = new List <List <ObjectInSequence> >(compObj.RandomizedSequencesB);
                        }
                        else
                        {
                            RandomizeSequence(compObj.SequenceA, lstSequencesA);
                            RandomizeSequence(compObj.SequenceB, lstSequencesB);
                        }

                        // Now we have everything, runrunrun
                        ConcurrentBag <Tuple <decimal, int, int, int, int> > lstDistances = new ConcurrentBag <Tuple <decimal, int, int, int, int> >();

                        // Create the Alignment
                        NeedlemanWunsch nw = new NeedlemanWunsch(lstSequenceA, lstSequenceB, options, true);

                        // DebugCode if we need to see the Original Alignment
                        //DialogNeedlemanWunschShowAlign dialogShow = new DialogNeedlemanWunschShowAlign();
                        //dialogShow.SetData(nw);
                        //dialogShow.ShowDialog(this.FindForm());

                        // Now loop over the created sequences and compare all of them
                        Parallel.ForEach(lstSequencesA, seqA =>
                        {
                            Parallel.ForEach(lstSequencesB, seqB =>
                            {
                                // Build the alignment
                                NeedlemanWunsch nwRandom = new NeedlemanWunsch(seqA, seqB, options, true);
                                // Now we need the distance
                                lstDistances.Add(Tuple.Create(nwRandom.Distance, nwRandom.NumberOfChanges, nwRandom.Backtraces.Min(bt => bt.WayBack.Count), nwRandom.SequenceA.Count, nwRandom.SequenceB.Count));

                                //if (nwRandom.Distance < 35m)
                                //{
                                //  lstSusp.Add(nwRandom);
                                //}
                            });
                        });

                        // We get the filename from the CompareObject
                        string strSavePath = Path.Combine(Path.GetDirectoryName(compObj.SavePath), Path.GetFileNameWithoutExtension(compObj.SavePath) + $"_{options.Name}" + Path.GetExtension(compObj.SavePath));
                        SaveCSV(strSavePath, nw, lstDistances, lstSequenceA, lstSequenceB);
                        // Also save the Sequences
                        string strSavePathSequencesA, strSavePathSequencesB;
                        strSavePathSequencesA = Path.Combine(Path.GetDirectoryName(compObj.SavePath), Path.GetFileNameWithoutExtension(compObj.SavePath) + "_sequencesA.xml");
                        strSavePathSequencesB = Path.Combine(Path.GetDirectoryName(compObj.SavePath), Path.GetFileNameWithoutExtension(compObj.SavePath) + "_sequencesB.xml");
                        // Insert the original Sequence in A and save them
                        lstSequencesA.Insert(0, lstSequenceA);
                        DataContractSerializer serializer = new DataContractSerializer(typeof(List <List <ObjectInSequence> >));
                        using (XmlWriter writer = XmlWriter.Create(strSavePathSequencesA))
                        {
                            serializer.WriteObject(writer, lstSequencesA);
                            writer.Close();
                        }
                        // Same for B
                        lstSequencesB.Insert(0, lstSequenceB);
                        using (XmlWriter writer = XmlWriter.Create(strSavePathSequencesB))
                        {
                            serializer.WriteObject(writer, lstSequencesB);
                            writer.Close();
                        }

                        // Save the options?
                    }
                }

                // Show something so the user knows were done
                MessageBox.Show(this.FindForm(), "Done!");
            }
        }