コード例 #1
0
        private void ReverseComplement(RichTextBox textBoxToReverseComplement)
        {
            textBoxToReverseComplement.Enabled = false;
            char[] charArray = textBoxToReverseComplement.Text.ToCharArray();
            Array.Reverse(charArray);

            textBoxToReverseComplement.Enabled = true;
            this.ActiveControl = textBoxToReverseComplement;
            textBoxToReverseComplement.Text = DataFunctions.ReturnComplement(charArray);
            textBoxToReverseComplement.Select(textBoxToReverseComplement.Text.Length, 0);
        }
コード例 #2
0
        private void findSubsequenceButton_Click(object sender, EventArgs e)
        {
            int  permitedMismatchCount   = (int)this.mismatchCounter.Value;
            bool searchComplement        = this.complementCheckbox.Checked;
            bool searchReverseComplement = this.reverseComplementCheckbox.Checked;

            /// Just in case
            string inputFromFindBox = string.Join("", this.searchTextBox.Text.Split(new[] { " ", "\r\n", "\r", "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)).ToUpper();
            string sequence         = this.rtb.Text.ToUpper();

            int subsequenceLength = inputFromFindBox.Length;

            Dictionary <int, int> foundPositions       = new Dictionary <int, int>();
            List <string>         subsequencesToSearch = new List <string>();

            subsequencesToSearch.Add(inputFromFindBox);

            if (searchComplement)
            {
                subsequencesToSearch.Add(DataFunctions.ReturnComplement(inputFromFindBox));
            }

            if (searchReverseComplement)
            {
                char[] charSubsequence = inputFromFindBox.ToCharArray();
                Array.Reverse(charSubsequence);
                subsequencesToSearch.Add(DataFunctions.ReturnComplement(charSubsequence));
            }

            for (int i = 0; i < sequence.Length - subsequenceLength + 1; i++)
            {
                foreach (string searchSubstring in subsequencesToSearch)
                {
                    int currentCycleMismatchCount = 0;

                    for (int j = 0; j < subsequenceLength; j++)
                    {
                        if (searchSubstring[j] == sequence[i + j] || searchSubstring[j] == 'N' || sequence[i + j] == 'N')
                        {
                            continue;
                        }
                        else
                        {
                            currentCycleMismatchCount++;
                        }
                    }

                    if (currentCycleMismatchCount > permitedMismatchCount)
                    {
                        continue;
                    }
                    else
                    {
                        foundPositions.Add(i, i + subsequenceLength);
                    }
                }
            }

            foreach (KeyValuePair <int, int> positions in foundPositions)
            {
                int beginning     = positions.Key;
                int end           = positions.Value;
                int rtbTextLength = this.rtb.Text.Length;

                //Check in case the content of textbox has changed (in this case the results may be invalid anyway)
                if (beginning >= rtbTextLength || end > rtbTextLength)
                {
                    continue;
                }

                rtb.Select(beginning, (end - beginning));
                rtb.SelectionColor     = System.Drawing.Color.Yellow;
                rtb.SelectionBackColor = System.Drawing.Color.Black;
            }

            rtb.Select(rtb.Text.Length, 0);
            rtb.SelectionColor     = Color.Black;
            rtb.SelectionBackColor = Color.White;
        }