コード例 #1
0
        public void FindGenBankParser()
        {
            string          dummyFileName = "dummy.gb";
            ISequenceParser parser        = SequenceParsers.FindParserByFile(dummyFileName);

            Assert.IsInstanceOfType(parser, typeof(GenBankParser));
        }
コード例 #2
0
        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override IEnumerable <ISequence> Execute(CodeActivityContext context)
        {
            string          filename = Filename.Get(context);
            ISequenceParser parser   = SequenceParsers.FindParserByFileName(filename);

            if (parser == null)
            {
                throw new ArgumentException("Could not determine parser for " + filename);
            }

            string alphaName = DesiredAlphabet;

            if (!string.IsNullOrEmpty(alphaName))
            {
                alphaName = alphaName.ToLowerInvariant();
                IAlphabet alphabet = Alphabets.All.FirstOrDefault(a => a.Name.ToLowerInvariant() == alphaName);
                if (alphabet == null)
                {
                    throw new ArgumentException("Unknown alphabet name");
                }

                parser.Alphabet = alphabet;
            }

            if (LogOutput)
            {
                var tw = context.GetExtension <TextWriter>() ?? Console.Out;
                tw.WriteLine("Reading sequences from " + filename);
            }

            return(parser.Parse());
        }
コード例 #3
0
        /// <summary>
        /// convert input file to output file using the specified format conversion
        /// </summary>
        public void ConvertFile()
        {
            //make sure input file is valid
            if (!File.Exists(InputFile))
            {
                throw new Exception("Input file does not exist.");
            }

            //Finds a parser and opens the file
            var inputParser = SequenceParsers.FindParserByFileName(InputFile);

            if (inputParser == null)
            {
                throw new Exception("Input file not a valid file format to parse.");
            }

            IEnumerable <ISequence> sequences;

            //Finds a formatter and opens the file
            var outputFormatter = SequenceFormatters.FindFormatterByFileName(OutputFile);

            if (inputParser == null)
            {
                throw new Exception("Output file not a valid file format for conversion.");
            }

            sequences = inputParser.Parse();
            foreach (ISequence sequence in sequences)
            {
                outputFormatter.Write(sequence);
            }

            outputFormatter.Close();
            inputParser.Close();
        }
コード例 #4
0
        static void DumpStatsForOneSequence()
        {
            ISequence oneSequence = null;

            var parser = SequenceParsers.FindParserByFileName(Filename);

            if (parser != null)
            {
                oneSequence = parser.Parse().First();
                parser.Close();
            }

            if (oneSequence == null)
            {
                Console.WriteLine("Could not load sequence.");
                return;
            }

            SequenceStatistics stats =
                new SequenceStatistics(oneSequence);

            foreach (var symbol in oneSequence.Alphabet)
            {
                Console.WriteLine("{0} = Count={1}, Fraction={2}",
                                  (char)symbol, stats.GetCount(symbol),
                                  stats.GetFraction(symbol));
            }
        }
コード例 #5
0
        public void TestMissingFile()
        {
            string          filepath    = @"TestUtils\NoFileHere.fa";
            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.Fail("Should not get here!");
        }
コード例 #6
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestMissingFile()
        {
            string          filepath    = @"TestUtils\NoFileHere.fa";
            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.AreEqual(SequenceParsers.Fasta, foundParser);
        }
コード例 #7
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestMissingDirectory()
        {
            string          filepath    = @"NoDirectoryHere\NoFileHere.fa";
            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.AreEqual(SequenceParsers.Fasta, foundParser);
        }
コード例 #8
0
        public void ReturnNoParser()
        {
            string          dummyFileName = "dummy.abc";
            ISequenceParser parser        = SequenceParsers.FindParserByFile(dummyFileName);

            Assert.AreEqual(parser, null);
        }
コード例 #9
0
        public void FindFastaParser()
        {
            string          dummyFileName = "dummy.fasta";
            ISequenceParser parser        = SequenceParsers.FindParserByFile(dummyFileName);

            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.fa";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.mpfa";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.fna";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.faa";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.fsa";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));

            dummyFileName = "dummy.fas";
            parser        = SequenceParsers.FindParserByFile(dummyFileName);
            Assert.IsInstanceOfType(parser, typeof(FastaParser));
        }
コード例 #10
0
        public void TestMissingDirectory()
        {
            string          filepath    = @"NoDirectoryHere\NoFileHere.fa";
            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.Fail("Should not get here!");
        }
コード例 #11
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestUnknownFileExtension()
        {
            string filepath = @"Test.ukn";

            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.IsNull(foundParser);
        }
コード例 #12
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestSffFileExtension()
        {
            string filepath = @"TestUtils\dummy.sff";

            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.IsNotNull(foundParser);
            Assert.IsInstanceOf <SFFParser>(foundParser);
        }
コード例 #13
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestTxtFileExtension()
        {
            string filepath = @"TestUtils\BLOSUM50.txt";

            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.IsNull(foundParser);
            // Should not auto-locate FieldTextParser.
        }
コード例 #14
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestGffFileExtension()
        {
            string filepath = @"TestUtils\Simple_Gff_Dna.gff";

            ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath);

            Assert.IsNotNull(foundParser);
            Assert.IsInstanceOf <GffParser>(foundParser);
        }
コード例 #15
0
 /// <summary>
 /// Parses a file containing a sequence in .NET Bio supported formats.
 /// </summary>
 /// <param name="file">Path to a parsed file.</param>
 /// <returns>Fragment sequence.</returns>
 private ISequence ParseFile(String file)
 {
     parser = SequenceParsers.FindParserByFileName(file);
     if (parser == null)
     {
         throw new FileFormatException("Parser for " + file + " not found.");
     }
     return(ParseFragment(parser, file));
 }
コード例 #16
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            String          inputFileName = InputFile;
            ISequenceParser parser        = SequenceParsers.FindParserByFile(inputFileName);

            SequenceResult = parser.ParseOne(inputFileName);

            return(ActivityExecutionStatus.Closed);
        }
コード例 #17
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            ISequenceParser foundParser = (ISequenceParser)cbParserList.SelectedItem;

            if (foundParser != null)
            {
                SelectedParser = SequenceParsers.FindParserByName(FileName, foundParser.Name);
            }
        }
コード例 #18
0
ファイル: InputSubmission.cs プロジェクト: kcha/seqcos
        /// <summary>
        /// Constructor for processing the input file
        /// </summary>
        /// <param name="file">Input filename</param>
        public InputSubmission(string file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            this.Filename = file;
            this.Parser   = SequenceParsers.FindParserByFileName(file);
        }
コード例 #19
0
        /// <summary>
        /// Helper method to parse the given filename into a set
        /// of ISequence elements. This routine will load sequences from
        /// any support sequence parser in .NET Bio.
        /// </summary>
        /// <param name="fileName">Filename to load data from</param>
        /// <returns>Enumerable set of ISequence elements</returns>
        internal static IEnumerable <ISequence> ParseFile(string fileName)
        {
            ISequenceParser parser = SequenceParsers.FindParserByFileName(fileName);

            if (parser == null)
            {
                parser = new FastAParser(fileName);
            }

            return(parser.Parse());
        }
コード例 #20
0
        /// <summary>
        /// Helper method to parse the given filename into a set
        /// of ISequence elements. This routine will load sequences from
        /// any support sequence parser in .NET Bio.
        /// </summary>
        /// <param name="fileName">Filename to load data from</param>
        /// <returns>Enumerable set of ISequence elements</returns>
        protected static IEnumerable <ISequence> ParseFile(string fileName)
        {
            ISequenceParser parser = SequenceParsers.FindParserByFileName(fileName);

            if (parser == null)
            {
                throw new Exception("Could not locate an appropriate sequence parser for " + fileName);
            }

            return(parser.Parse());
        }
コード例 #21
0
        public void TestFastQFileExtension()
        {
            string[] extensions = { ".fq", ".fastq" };
            string   filepath   = @"TestUtils\SimpleDnaIllumina";

            foreach (var ext in extensions)
            {
                ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath + ext);
                Assert.IsNotNull(foundParser);
                Assert.IsInstanceOfType(foundParser, typeof(FastQParser));
            }
        }
コード例 #22
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestFastAFileExtension()
        {
            string[] extensions = { ".fa", ".fas", ".fasta", ".fna", ".fsa", ".mpfa" };
            string   filepath   = @"TestUtils\Simple_Fasta_DNA";

            foreach (var ext in extensions)
            {
                ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath + ext);
                Assert.IsNotNull(foundParser);
                Assert.IsInstanceOf <FastAParser>(foundParser);
            }
        }
コード例 #23
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestFastQFileExtension()
        {
            string[] extensions = { ".fq", ".fastq" };
            string   filepath   = @"TestUtils\SimpleDnaIllumina";

            foreach (var ext in extensions)
            {
                ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath + ext);
                Assert.IsNotNull(foundParser);
                Assert.AreEqual(SequenceParsers.FastQ.Name, foundParser.Name);
            }
        }
コード例 #24
0
ファイル: SequenceParserTests.cs プロジェクト: sjmercer65/bio
        public void TestGenBankFileExtension()
        {
            string[] extensions = { ".gbk", ".genbank" };
            string   filepath   = @"TestUtils\Simple_GenBank_DNA";

            foreach (var ext in extensions)
            {
                ISequenceParser foundParser = SequenceParsers.FindParserByFileName(filepath + ext);
                Assert.IsNotNull(foundParser);
                Assert.IsInstanceOf <GenBankParser>(foundParser);
            }
        }
コード例 #25
0
        static void Main(string[] args)
        {
            var parser = SequenceParsers.FindParserByFileName(Filename);

            if (parser == null)
            {
                Console.WriteLine("No parser found.");
                return;
            }

            List <ISequence> allSequences = parser
                                            .Parse()
                                            .ToList();

            IAlphabet alphabet = allSequences[0].Alphabet;

            long totalColums = allSequences.Min(s => s.Count);

            //byte[] data = new byte[allSequences.Count];
            for (int column = 0; column < totalColums; column++)
            {
                //    for (int row = 0; row < allSequences.Count; row++)
                //        data[row] = allSequences[row][column];
                //ISequence newSequence = new Sequence(alphabet, data);

                ISequence newSequence = new Sequence(AmbiguousRnaAlphabet.Instance,
                                                     allSequences
                                                     .Select(s => s[column]).ToArray());
                SequenceStatistics stats =
                    new SequenceStatistics(newSequence);
                var TopCount =
                    alphabet
                    .Where(symbol => !alphabet.CheckIsGap(symbol))
                    .Select(symbol =>
                            new
                {
                    Symbol    = (char)symbol,
                    Count     = stats.GetCount(symbol),
                    Frequency = stats.GetFraction(symbol)
                })
                    .Where(tc => tc.Count > 0)
                    .OrderByDescending(c => c.Count)
                    .FirstOrDefault();

                if (TopCount != null)
                {
                    Console.WriteLine("{0}: {1} = {2} of {3}",
                                      column, TopCount.Symbol, TopCount.Count, totalColums);
                }
            }
        }
コード例 #26
0
ファイル: NetBioExamples.cs プロジェクト: maciek-tee/bioInf
        public static void FindDifferencesInSequences(string firstFile, string secondFile)
        {
            // parsowanie pierwszej listy
            if (!SequenceParsers.IsFasta(firstFile))
            {
                Console.WriteLine("Nieprawidlowy format pierwszego pliku!");
                return;
            }

            if (!SequenceParsers.IsFasta(secondFile))
            {
                Console.WriteLine("Nieprawidlowy format drugiego pliku!");
                return;
            }

            var firstParser = SequenceParsers.FindParserByFileName(firstFile);

            firstParser.Alphabet = AmbiguousProteinAlphabet.Instance;
            var firstSequenceList  = firstParser.Parse();
            var firstFileSequences = Helper.ConvertIenumerableToList(firstSequenceList);

            // parsowanie drugiej listy
            var secondParser = SequenceParsers.FindParserByFileName(firstFile);

            secondParser.Alphabet = AmbiguousProteinAlphabet.Instance;
            var secondSequenceList  = secondParser.Parse();
            var secondFileSequences = Helper.ConvertIenumerableToList(secondSequenceList);

            // pobranie listy KMER'ów
            var kmerBuilder = new SequenceToKmerBuilder();
            var kmerList    = kmerBuilder.Build(firstFileSequences.First(), 2);
            var nodes       = WordMatch.BuildMatchTable(kmerList, secondFileSequences.First(), 2);

            var list2 = new List <WordMatch>(nodes);

            var matchList = WordMatch.GetMinimalList(list2, 2);

            var list3 = new List <WordMatch>(matchList);

            // znajdŸ ró¿nice miêdzy wêz³ami
            var diffNode = DifferenceNode.BuildDiffList(list3, firstFileSequences.First(), secondFileSequences.First());

            var list4 = new List <DifferenceNode>(diffNode);

            var features = DifferenceNode.OutputDiffList(list4, firstFileSequences.First(), secondFileSequences.First());

            foreach (var compareFeature in features)
            {
                Console.WriteLine(compareFeature.Feature);
            }
        }
コード例 #27
0
        /// <summary>
        /// Parses a sequence given a file name. Uses built in mechanisms to detect the
        /// appropriate parser based on the file name.
        /// </summary>
        /// <param name="fileName">The path of the file to be parsed for a sequence</param>
        internal void ParseSequence(string fileName)
        {
            ISequenceParser parser = SequenceParsers.FindParserByFile(fileName);

            if (parser == null)
            {
                throw new ArgumentException("Could not find an appropriate parser for " + fileName);
            }

            Sequence = parser.ParseOne(fileName);
            if (Sequence == null)
            {
                throw new ArgumentException("Unable to parse a sequence from file " + fileName);
            }
        }
コード例 #28
0
        /// <summary>
        /// This method loads new sequences from a file.
        /// </summary>
        private void OnLoadFile()
        {
            string filterString = "All Supported Formats|" + string.Join(";", SequenceParsers.All.Select(parser => parser.SupportedFileTypes.Replace(',', ';').Replace(".", "*."))) + "|" +
                                  string.Join("|", SequenceParsers.All.Select(parser => string.Format("{0}|{1}", parser.Name, parser.SupportedFileTypes.Replace(',', ';').Replace(".", "*."))));

            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                CheckFileExists = true,
                Filter          = filterString
            };

            // Prompt the user for the filename
            if (openFileDialog.ShowDialog() == true)
            {
                // See if we can auto-locate the parser
                ISequenceParser parser = SequenceParsers.FindParserByFileName(openFileDialog.FileName);
                if (parser == null)
                {
                    // Use the extension
                    string fileExtension = Path.GetExtension(openFileDialog.FileName);
                    parser = SequenceParsers.All.FirstOrDefault(sp => sp.SupportedFileTypes.Contains(fileExtension));
                }

                // Cannot parse this file.
                if (parser == null)
                {
                    MessageBox.Show(string.Format("Cannot locate a sequence parser for {0}", openFileDialog.FileName), "Cannot Parse File");
                    return;
                }

                // Parse the file - open it read-only as we will not be writing the sequences back out.
                try
                {
                    foreach (var sequence in parser.Parse())
                    {
                        LoadedSequences.Add(new SequenceViewModel(this, sequence));
                    }
                }
                catch (Exception ex)
                {
                    ShowError("Cannot Parse File", "Failed to open " + openFileDialog.FileName, ex);
                }
                finally
                {
                    parser.Close();
                }
            }
        }
コード例 #29
0
ファイル: InputSubmission.cs プロジェクト: kcha/seqcos
        /// <summary>
        /// Parse the input file with given parser type
        /// </summary>
        /// <param name="p">The parser name (i.e. FastQ)</param>
        /// <returns>
        /// true if parsing was successful
        /// false otherwise
        /// </returns>
        public bool CanParseInputByName(string ps)
        {
            if (string.IsNullOrEmpty(ps))
            {
                return(false);
            }

            this.Parser = SequenceParsers.FindParserByName(Filename, ps);

            if (this.Parser == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #30
0
ファイル: NetBioExamples.cs プロジェクト: maciek-tee/bioInf
        public static void ConvertFromOneFormatToAnother(string inputFileName, string outputFileName, ISequenceFormatter targetFormatter)
        {
            var parser       = SequenceParsers.FindParserByFileName(inputFileName);
            var sequenceList = parser.Parse();
            var sequences    = Helper.ConvertIenumerableToList(sequenceList);

            targetFormatter.Open(outputFileName);

            foreach (var sequence in sequences)
            {
                targetFormatter.Write(sequence);
            }

            targetFormatter.Close();
            targetFormatter.Dispose();
        }