public override IIdentifiedResult ReadFromFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Protein file not exist : " + fileName);
            }

            string peptideFilename = GetPeptideFileName(fileName);

            if (!File.Exists(peptideFilename))
            {
                throw new FileNotFoundException("Peptide file not exist : " + peptideFilename);
            }

            string linkFileName = GetLinkFileName(fileName);

            if (!File.Exists(linkFileName))
            {
                throw new FileNotFoundException("Peptide2group file not exist : " + linkFileName);
            }

            var pepFileReader = new PeptideTextReader(GetEngineName());
            List <IIdentifiedSpectrum> spectra = pepFileReader.ReadFromFile(peptideFilename);

            this.PeptideFormat = pepFileReader.PeptideFormat;

            var proFileReader = new ProteinTextReader(GetEngineName());
            List <IIdentifiedProtein> proteins = proFileReader.ReadFromFile(fileName);

            this.ProteinFormat = proFileReader.ProteinFormat;

            var peptideMap = spectra.ToDictionary(m => m.Id);
            var proteinMap = proteins.GroupBy(m => m.GroupIndex);

            IIdentifiedResult result = Allocate();

            foreach (var pros in proteinMap)
            {
                var group = new IdentifiedProteinGroup();
                pros.ToList().ForEach(m => group.Add(m));
                result.Add(group);
            }

            new Peptide2GroupTextReader().LinkPeptideToGroup(linkFileName, peptideMap, result.ToDictionary(m => m.Index));

            string fastaFile = fileName + ".fasta";

            if (File.Exists(fastaFile))
            {
                IdentifiedResultUtils.FillSequenceFromFasta(fastaFile, result, null);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public override IIdentifiedResult ReadFromFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File not exist : " + fileName);
            }

            IIdentifiedResult result = Allocate();

            Dictionary <string, IIdentifiedSpectrum> peptideMap = new Dictionary <string, IIdentifiedSpectrum>();

            using (StreamReader filein = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read)))
            {
                Progress.SetRange(0, filein.BaseStream.Length);

                IIdentifiedProteinGroup group;

                string lastLine = filein.ReadLine();
                if (lastLine == null)
                {
                    return(result);
                }

                if (ProteinFormat != null)
                {
                    ProteinFormat = new LineFormat <IIdentifiedProtein>(ProteinFormat.Factory, lastLine, GetEngineName());
                }
                else
                {
                    ProteinFormat = new ProteinLineFormat(lastLine, GetEngineName());
                }

                lastLine = filein.ReadLine();
                if (lastLine == null)
                {
                    return(result);
                }

                if (PeptideFormat != null)
                {
                    PeptideFormat = new LineFormat <IIdentifiedSpectrum>(PeptideFormat.Factory, lastLine, GetEngineName());
                }
                else
                {
                    PeptideFormat = new PeptideLineFormat(lastLine, GetEngineName());
                }

                lastLine = null;
                while ((group = ReadNextProteinGroup(filein, peptideMap, ref lastLine)) != null)
                {
                    result.Add(group);
                }
            }

            string fastaFile = fileName + ".fasta";

            if (File.Exists(fastaFile))
            {
                IdentifiedResultUtils.FillSequenceFromFasta(fastaFile, result, null);
            }

            return(result);
        }