Ejemplo n.º 1
0
        public List <IProtein> Read(string path)
        {
            List <IProtein> proteins = new List <IProtein>();

            using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fileStream))
                {
                    string        line;
                    StringBuilder sequence = new StringBuilder();
                    IProtein      entry    = null;
                    // Read lines from the file until end of file (EOD) is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        // ignore comment lines
                        if (line.StartsWith(";"))
                        {
                            continue;
                        }
                        //e.g. >gi|186681228|ref|YP_001864424.1| phycoerythrobilin:ferredoxin oxidoreductase
                        else if (line.StartsWith(">"))
                        {
                            if (entry != null)
                            {
                                entry.SetSequence(sequence.ToString());
                                proteins.Add(entry);
                            }
                            sequence.Clear();
                            entry = new BaseProtein();
                            entry.SetID(line.TrimStart('>'));
                        }
                        else
                        {
                            sequence.Append(line.Trim());
                        }
                    }

                    if (sequence.Length > 0)
                    {
                        entry.SetSequence(sequence.ToString());
                        proteins.Add(entry);
                    }
                }
            }

            return(proteins);
        }