Example #1
0
        /// <summary>
        /// The execution method for the activity.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        /// <returns>The execution status.</returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            String          inputFileName = InputFile;
            ISequenceParser parser        = SequenceParsers.FindParserByFileName(inputFileName);

            parser.Open(inputFileName);
            SequenceResult = parser.Parse().FirstOrDefault();
            parser.Close();
            return(ActivityExecutionStatus.Closed);
        }
Example #2
0
        // Parses a sequence and adds it to the displayed list

        private void ParseSequence(ISequenceParser parser, string filename)
        {
            parser.Open(filename);
            IEnumerable <ISequence> parsed = parser.Parse();
            ListBox sequenceList           = (ListBox)FindName("SequencesListBox");

            foreach (ISequence seq in parsed)
            {
                sequenceList.Items.Add(seq);
            }
            parser.Close();
        }
Example #3
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));
                    if (parser != null)
                    {
                        parser.Open(openFileDialog.FileName);
                    }
                }

                // 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(sequence));
                    }
                }
                catch (Exception ex)
                {
                    ShowError("Cannot Parse File", "Failed to open " + openFileDialog.FileName, ex);
                }
            }
        }
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Need source and destination filenames.");
                return;
            }

            string sourceFilename = args[0];
            string destFilename   = args[1];

            ISequenceParser parser = SequenceParsers.FindParserByFileName(sourceFilename);

            if (parser == null)
            {
                parser = SequenceParsers.All.FirstOrDefault(
                    sp => sp.SupportedFileTypes.Contains(Path.GetExtension(sourceFilename)));
                if (parser == null)
                {
                    Console.WriteLine("Failed to locate parser for {0}", sourceFilename);
                    return;
                }
                parser.Open(sourceFilename);
            }

            ISequenceFormatter formatter = SequenceFormatters.FindFormatterByFileName(destFilename);

            if (formatter == null)
            {
                formatter = SequenceFormatters.All.FirstOrDefault(
                    sp => sp.SupportedFileTypes.Contains(Path.GetExtension(destFilename)));
                if (formatter == null)
                {
                    Console.WriteLine("Failed to locate formatter for {0}", destFilename);
                    return;
                }
                formatter.Open(destFilename);
            }

            foreach (var sequence in parser.Parse())
            {
                formatter.Write(sequence);
            }

            parser.Close();
            formatter.Close();
        }
Example #5
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>
        public void ParseSequence(string fileName)
        {
            ISequenceParser parser = SequenceParsers.FindParserByFileName(fileName);

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

            using (parser.Open(fileName))
            {
                // Get the first sequence from the file
                SequenceToSplit = parser.ParseOne();
                if (SequenceToSplit == null)
                {
                    throw new ArgumentException("Unable to parse a sequence from file " + fileName);
                }
            }
        }
Example #6
0
        public void openProject(String file)
        {
            Sequence sequence = null;

            parser = SequenceParsers.GenBank;
            parser.Open(file);
            sequence = (Sequence)parser.Parse().ToList()[0];
            parser.Close();

            Fragment        project = new Fragment(file, "project", sequence);
            GenBankMetadata meta    = sequence.Metadata["GenBank"] as GenBankMetadata;

            FragmentDict = new Dictionary <string, Fragment>();
            foreach (var feat in meta.Features.MiscFeatures)
            {
                String subseq = project.GetString().Substring(feat.Location.LocationStart - 1, feat.Location.LocationEnd - feat.Location.LocationStart + 1);
                FragmentDict.Add(feat.StandardName, new Fragment(file, feat.StandardName, new Sequence(Alphabets.DNA, subseq)));
            }
        }
Example #7
0
        public void openProject(String file)
        {
            Sequence sequence = null;

            parser = SequenceParsers.GenBank;
            parser.Open(file);
            sequence = (Sequence)parser.Parse().ToList()[0];
            parser.Close();

            Fragment project = new Fragment(file, "project", sequence);
            GenBankMetadata meta = sequence.Metadata["GenBank"] as GenBankMetadata;
            FragmentDict = new Dictionary<string, Fragment>();
            foreach (var feat in meta.Features.MiscFeatures)
            {
                String subseq = project.GetString().Substring(feat.Location.LocationStart-1, feat.Location.LocationEnd - feat.Location.LocationStart + 1);
                FragmentDict.Add(feat.StandardName, new Fragment(file, feat.StandardName, new Sequence(Alphabets.AmbiguousDNA, subseq)));
            }
        }