Exemplo n.º 1
0
        public void WriteFasta(string fasta_file, FastaWriter Writer)
        {
            bool MakeDecoy = false;

            if (Options.OutputType == DatabaseType.Target || Options.OutputType == DatabaseType.Concatenated)
            {
                MakeDecoy = false;
            }
            else if (Options.OutputType == DatabaseType.Decoy || Options.OutputType == DatabaseType.Concatenated)
            {
                MakeDecoy = true;
            }

            using (FastaReader reader = new FastaReader(fasta_file))
            {
                foreach (Fasta fasta in reader.ReadNextFasta())
                {
                    Regex  uniprotRegex = new Regex(@"(.+)\|(.+)\|(.+?)\s(.+?)\sOS=(.+?)(?:\sGN=(.+?))?(?:$|PE=(\d+)\sSV=(\d+))", RegexOptions.ExplicitCapture);
                    Match  UniprotMatch = uniprotRegex.Match(fasta.Description);
                    string HeaderFile   = "InvalidUniprotheaders.txt";
                    string headerFolder = Path.GetDirectoryName(Options.InputFiles[0]);

                    if (Options.EnforceUniprot && !UniprotMatch.Success)
                    {
                        using (StreamWriter log = new StreamWriter(Path.Combine(headerFolder, HeaderFile), true))
                        {
                            log.WriteLine("Invalid Header:");
                            log.WriteLine();
                            log.WriteLine(fasta.Description);
                            log.WriteLine();
                            InvalidHeader(fasta);
                        }
                    }

                    if (UniprotMatch.Success)
                    {
                        bool excludeMethionine = false;
                        if (Options.ExcludeNTerminalMethionine && !Options.ExcludeNTerminalResidue)
                        {
                            excludeMethionine = true;
                        }

                        if (MakeDecoy)
                        {
                            Writer.Write(fasta.ToDecoy(Options.DecoyPrefix, Options.DecoyType, (excludeMethionine || Options.ExcludeNTerminalResidue), Options.ExcludeNTerminalMethionine));
                        }

                        else
                        {
                            Writer.Write(fasta);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static Dictionary <string, string> parseDB(string pathIn)
        {
            Dictionary <string, string> returnDict = new Dictionary <string, string>();

            List <string> badsequences = new List <string>();

            //StreamReader reader = new StreamReader(pathIn);

            var reader = new FastaReader(pathIn);

            foreach (var fasta in reader.ReadNextFasta())
            {
                if (!fasta.IsDecoy)
                {
                    string desc = fasta.Description.Replace(",", ";");
                    returnDict.Add(">" + desc, fasta.Sequence);
                }
            }
            return(returnDict);
        }