Пример #1
0
        public string GetNextTitle()
        {
            string result = string.Empty;

            long position = StreamUtils.GetCharpos(this.reader);

            try
            {
                string line;
                while ((line = this.reader.ReadLine()) != null)
                {
                    if (line.StartsWith(MascotGenericFormatConstants.TITLE_TAG))
                    {
                        result = line.Substring(line.IndexOf('=') + 1);
                        break;
                    }
                }
            }
            finally
            {
                this.reader.SetCharpos(position);
            }

            return(result);
        }
        public void TestGetCharpos()
        {
            using (StreamReader sr = new StreamReader(@TestContext.CurrentContext.TestDirectory + "/../../../data//20030428_4_29L_15.outs"))
            {
                Assert.AreEqual(0, StreamUtils.GetCharpos(sr));

                char[] buffer = new char[100];
                sr.Read(buffer, 0, 90);

                Assert.AreEqual(90, StreamUtils.GetCharpos(sr));
            }
        }
Пример #3
0
        public override void Open(string fileName)
        {
            Close();
            sr = new StreamReader(fileName);

            this.FileName = fileName;
            iter          = new MascotGenericFormatIterator <Peak>(sr);

            string line;
            int    scan     = 1;
            long   position = 0;

            while ((line = sr.ReadLine()) != null)
            {
                if (line.StartsWith(MascotGenericFormatConstants.MSMS_SCAN_TAG))
                {
                    Match m = scanRegex.Match(line);
                    scan            = Convert.ToInt32(m.Groups[1].Value);
                    positions[scan] = new PositionClass()
                    {
                        Position = position
                    };
                }
                else if (line.StartsWith(MascotGenericFormatConstants.RETENTION_TIME_TAG))
                {
                    positions[scan].RetentionTimeInSecond = MyConvert.ToDouble(line.Substring(MascotGenericFormatConstants.RETENTION_TIME_TAG.Length + 1));
                }
                else if (line.StartsWith(MascotGenericFormatConstants.END_PEAK_LIST_TAG))
                {
                    position = StreamUtils.GetCharpos(sr);
                }
            }

            List <int> scans = new List <int>(positions.Keys);

            if (scans.Count > 0)
            {
                firstScan = scans[0];
                lastScan  = scans[scans.Count - 1];
            }
            else
            {
                firstScan = 0;
                lastScan  = -1;
            }
        }
        private void ReadFile(List <Sequence> sw, string filename, StringBuilder sb, List <int> seqLengths)
        {
            using (StreamReader sr = new StreamReader(filename))
            {
                Progress.SetRange(0, sr.BaseStream.Length);

                Sequence seq;
                while ((seq = ff.ReadSequence(sr)) != null)
                {
                    Progress.SetPosition(StreamUtils.GetCharpos(sr));

                    if (combined)
                    {
                        sw.Add(seq);
                    }

                    sb.Append(seq.SeqString);
                    seqLengths.Add(seq.SeqString.Length);
                }
            }
        }
Пример #5
0
        private void ProcessFile(ref int index, StreamWriter sw, string fastaFile, bool isContaminant)
        {
            FastaFormat ff = new FastaFormat();

            using (StreamReader sr = new StreamReader(fastaFile))
            {
                Progress.SetRange(0, sr.BaseStream.Length);

                Sequence seq;
                while ((seq = ff.ReadSequence(sr)) != null)
                {
                    Progress.SetPosition(StreamUtils.GetCharpos(sr));

                    if (isContaminant)
                    {
                        if (!seq.Reference.StartsWith("CON_"))
                        {
                            seq.Reference = "CON_" + seq.Reference;
                        }
                    }

                    if (combined)
                    {
                        ff.WriteSequence(sw, seq);
                    }

                    if (pseudoAminoacid)
                    {
                        builder.Build(seq);
                    }

                    index++;
                    Sequence reversedSeq = SequenceUtils.GetReversedSequence(seq.SeqString, index);

                    ff.WriteSequence(sw, reversedSeq);
                }
            }
        }
Пример #6
0
        public override IEnumerable <string> Process(string fileName)
        {
            FastaFormat ff     = new FastaFormat();
            var         result = Path.ChangeExtension(fileName, ".dM.fasta");

            using (StreamReader sr = new StreamReader(fileName))
                using (StreamWriter sw = new StreamWriter(result))
                {
                    Sequence seq;
                    Progress.SetRange(1, sr.BaseStream.Length);
                    while ((seq = ff.ReadSequence(sr)) != null)
                    {
                        Progress.SetPosition(StreamUtils.GetCharpos(sr));
                        if (seq.SeqString.StartsWith("M"))
                        {
                            seq.SeqString = seq.SeqString.Substring(1);
                            seq.Reference = seq.Name + " N-terminal-M-Removed " + seq.Description;
                        }
                        ff.WriteSequence(sw, seq);
                    }
                }

            return(new string[] { result });
        }
        public List <PeakList <Peak> > ReadFromFile(string fileName)
        {
            List <PeakList <Peak> > result = new List <PeakList <Peak> >();

            using (StreamReader sr = new StreamReader(fileName))
            {
                Progress.SetRange(0, sr.BaseStream.Length);
                string line;
                Dictionary <string, string> headers = new Dictionary <string, string>();
                List <string> peaks = new List <string>();
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Trim().Equals("peaklist start"))
                    {
                        Progress.SetPosition(StreamUtils.GetCharpos(sr));

                        headers.Clear();
                        peaks.Clear();

                        bool inHeader = true;
                        while ((line = sr.ReadLine()) != null)
                        {
                            var tline = line.Trim();
                            if (tline.Equals("peaklist end"))
                            {
                                break;
                            }

                            if (tline.Length == 0)
                            {
                                continue;
                            }

                            if (!inHeader)
                            {
                                peaks.Add(tline);
                            }
                            else if (Char.IsLetter(tline[0]))
                            {
                                var pos   = tline.IndexOf('=');
                                var key   = tline.Substring(0, pos);
                                var value = tline.Substring(pos + 1);
                                headers[key] = value;
                            }
                            else
                            {
                                inHeader = false;
                                peaks.Add(tline);
                            }
                        }

                        if (headers.Count > 0 && peaks.Count > 0)
                        {
                            PeakList <Peak> pkl = new PeakList <Peak>();
                            pkl.PrecursorMZ     = MyConvert.ToDouble(headers["mz"]);
                            pkl.PrecursorCharge = Convert.ToInt32(headers["charge"]);
                            pkl.MsLevel         = 2;
                            pkl.ScanMode        = headers["fragmentation"];
                            SequestFilename sf = parser.GetValue(headers["header"]);
                            pkl.ScanTimes.Add(new ScanTime(sf.FirstScan, 0.0));
                            pkl.Experimental = sf.Experimental;

                            result.Add(pkl);

                            foreach (var l in peaks)
                            {
                                var p = l.Split('\t');
                                if (p.Length > 1)
                                {
                                    pkl.Add(new Peak(MyConvert.ToDouble(p[0]), MyConvert.ToDouble(p[1])));
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }