Exemple #1
0
        public void filterTaggedSeqFile()
        {
            using (StreamReader snpTagReader = File.OpenText(filePath))
            {
                string line;

                string       outputFile = folderPath + "\\filteredSnpTaggedSeqs.txt";
                FileVerifier fv         = new FileVerifier();
                int          verified   = fv.verifyFileExistence(outputFile, " filtered sequence file ", folderPath, formObj);
                if (verified == 1)
                {
                    Stream stream = null;
                    try
                    {
                        stream = new FileStream(outputFile, FileMode.Append, FileAccess.Write);
                        using (StreamWriter sw = new StreamWriter(stream))
                        {
                            while ((line = snpTagReader.ReadLine()) != null)
                            {
                                string[] items  = line.Split('\t');
                                int      snpCnt = int.Parse(items[1]); // Total snps in transcript
                                if (snpCnt >= snpMin)
                                {
                                    stream = null;
                                    sw.WriteLine(line);
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Dispose();
                        }
                    }
                }
            }
        }
Exemple #2
0
        /*****************************************************
        * Event handler for calculating snp frequencies
        *****************************************************/
        /// <summary>
        /// Event-handler that generates a snp-tagged sequence,
        /// i.e., a sequence of "x" and "s" characters, where
        /// "s" represents the presence of a snp at a specific
        /// index in the "x" string
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createTaggedSeqButton_Click(object sender, EventArgs e)
        {
            // First do some validation (no field can be empty)
            foreach (Control control in ActiveForm.Controls)
            {
                string controlType = control.GetType().ToString();
                if (controlType == "System.Windows.Forms.TextBox")
                {
                    TextBox txtBox = (TextBox)control;
                    if (string.IsNullOrEmpty(txtBox.Text))
                    {
                        MessageBox.Show("All fields must be filled.");
                        txtBox.Focus();
                        return;
                    }
                }
            }


            // Add the contents of the snps loci file to an array
            /****************************************************/
            try
            {
                outF = this.outputFolderTextBox.Text;
                string       pathResultFile = outF + "\\snpTaggedSeqs.txt";
                FileVerifier fv             = new FileVerifier();
                int          verified       = fv.verifyFileExistence(pathResultFile, " masked sequence file ", outF, this);

                if (verified == 1)
                {
                    try
                    {
                        int[][] snps = (from line in File.ReadAllLines(snpFileTextBox.Text)
                                        select(from item in line.Split('\t')
                                               select int.Parse(item)).ToArray()).ToArray();
                        // Call method that will mark snps in seqs
                        string seqF = this.seqFileTextBox.Text;

                        SeqMasker sm = new SeqMasker(seqF, outF);
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        Cursor.Current = Cursors.WaitCursor;
                        sm.tagSnpsOnSeqs(snps);
                        Cursor.Current = Cursors.Default;
                        sw.Stop();
                        MessageBox.Show("Finished Creating Masked Sequences! It took " + sw.Elapsed + Environment.NewLine + "Now filtering ...", "Completed Phase 1");
                    }
                    catch
                    {
                        MessageBox.Show("Please, make sure that your snp file includes only integers as chromosome names.\n" +
                                        "In case you have chromosome names with strings, replace those with integers.\n" +
                                        "This includes chromosomes X and Y.", "Error reading snp file", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Possible issue with the path to output folder; please verify that you have entered the complete plath.",
                                "Error reading snp file", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }