public ParseXML(String file, Boolean flag) { XmlReader xml = XmlReader.Create(file); map = new List<GlycoRecord>(); GlycoRecord record = new GlycoRecord(); GlobalVar.assignMzKeys(); while (xml.Read()) { if (xml.IsStartElement()) { switch (xml.Name) { case "ID": xml.Read(); record.id = int.Parse(xml.ReadString()); break; case "Mass": xml.Read(); record.mass = double.Parse(xml.ReadString()); if (flag) { if (GlobalVar.REFCMAXMAS < record.mass) { GlobalVar.REFCMAXMAS = record.mass; } if (GlobalVar.REFCMINMAS > record.mass) { GlobalVar.REFCMINMAS = record.mass; } } else { if (GlobalVar.TARGMAXMAS < record.mass) { GlobalVar.TARGMAXMAS = record.mass; } if (GlobalVar.TARGMINMAS > record.mass) { GlobalVar.TARGMINMAS = record.mass; } } break; case "NET": xml.Read(); record.net = double.Parse(xml.ReadString()); if (flag) { //record.net = double.Parse(xml.ReadString());// if (GlobalVar.REFCMAXNET < record.net) { GlobalVar.REFCMAXNET = record.net; } if (GlobalVar.REFCMINNET > record.net) { GlobalVar.REFCMINNET = record.net; } } else { //record.net = double.Parse(xml.ReadString()) + 0.024;// if (GlobalVar.TARGMAXNET < record.net) { GlobalVar.TARGMAXNET = record.net; } if (GlobalVar.TARGMINNET > record.net) { GlobalVar.TARGMINNET = record.net; } } break; case "Protein": xml.Read(); if (flag) { string prot = xml.ReadString(); if (!prot.Contains("decoy")) { record.protein = prot; } else { record = new GlycoRecord(); continue; } } break; case "Peptide": xml.Read(); record.peptide = xml.ReadString(); break; case "PeptideMass": xml.Read(); record.pepmass = double.Parse(xml.ReadString()); break; case "Site": xml.Read(); record.site = xml.ReadString(); break; case "Glycan": xml.Read(); record.glycan = xml.ReadString(); break; case "GlycanSequence": xml.Read(); break; case "GlycanMass": xml.Read(); record.glymass = double.Parse(xml.ReadString()); break; case "FalseHit": xml.Read(); break; case "IDType": record.type = xml.ReadString(); break; case "RepresentativeCIDLength": xml.Read(); record.cidlen = int.Parse(xml.ReadString()); break; case "RepresentativeCIDSpectra": xml.Read(); record.cidstr = xml.ReadString(); Spectra cid = Utilities.parseBase64(record.cidlen, record.cidstr); record.cidspec = Utilities.assignMzBucket(cid.mz); break; case "RepresentativeHCDLength": xml.Read(); record.hcdlen = int.Parse(xml.ReadString()); break; case "RepresentativeHCDSpectra": xml.Read(); record.hcdstr = xml.ReadString(); //Spectra hcd = Utilities.parseBase64(record.hcdlen, record.hcdstr); //record.hcdspec = Utilities.assignMzBucket(hcd.mz); break; case "RepresentativeETDLength": xml.Read(); record.etdlen = int.Parse(xml.ReadString()); break; case "RepresentativeETDSpectra": xml.Read(); record.etdstr = xml.ReadString(); //Spectra etd = Utilities.parseBase64(record.etdlen, record.etdstr); //record.etdspec = Utilities.assignMzBucket(etd.mz); break; case "RepCIDScore": xml.Read(); record.cidscore = double.Parse(xml.ReadString()); break; case "RepHCDScore": xml.Read(); record.hcdscore = double.Parse(xml.ReadString()); break; case "RepETDScore": xml.Read(); record.etdscore = double.Parse(xml.ReadString()); break; case "RepCIDSequencing": xml.Read(); if (record.mass > 0) { map.Add(record); } break; } } } /*if (flag) { if ((GlobalVar.RMAXNET + GlobalVar.TOLNET) < 1.0) { GlobalVar.RMAXNET += GlobalVar.TOLNET; GlobalVar.RMAXNET = (Convert.ToInt32(GlobalVar.RMAXNET / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; } else { GlobalVar.RMAXNET = 1.0; } if ((GlobalVar.RMINNET - GlobalVar.TOLNET) > 0.0) { GlobalVar.RMINNET -= GlobalVar.TOLNET; GlobalVar.RMINNET = (Convert.ToInt32(GlobalVar.RMINNET / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; } else { GlobalVar.RMINNET = GlobalVar.BINNET; } GlobalVar.RMAXMAS = ((GlobalVar.RMAXMAS * (1 - GlobalVar.TOLMAS)) / (1 + GlobalVar.TOLMAS)); GlobalVar.RMAXMAS = (Convert.ToInt32(GlobalVar.RMAXMAS / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; GlobalVar.RMINMAS = ((GlobalVar.RMINMAS * (1 + GlobalVar.TOLMAS)) / (1 - GlobalVar.TOLMAS)); GlobalVar.RMINMAS = (Convert.ToInt32(GlobalVar.RMINMAS / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; GlobalVar.assignNetKeys(); }*/ }
private void calculateStdDev() { List<double> masdiff = new List<double>(); List<double> netdiff = new List<double>(); maserr = new Dictionary<double, int>(); neterr = new Dictionary<double, int>(); for (double i = (-GlobalVar.TOLMAS * 1000000); i < (GlobalVar.TOLMAS * 1000000); i += GlobalVar.ERRBINMAS) { maserr[Math.Round(i, 3)] = 0; } for (double i = (-GlobalVar.TOLNET * 100); i < (GlobalVar.TOLNET * 100); i += GlobalVar.ERRBINNET) { neterr[Math.Round(i, 1)] = 0; } string str = "TargetID,TargetMass,TargetNET,ReferenceID,ReferenceMass,ReferenceNET,Protein,Site,Peptide,Glycan,Type\n";// foreach (double okey in GlobalVar.NETKEYS) { foreach (double ikey in GlobalVar.NETKEYS) { int count = 0; foreach (GlycoRecord outs in targ_buck[okey]) { double dm = 0.0, dn = 0.0, euc = 100.0; GlycoRecord temprec = new GlycoRecord();// int chk = 0; foreach (GlycoRecord ins in refc_buck[ikey]) { if (Utilities.check(outs.mass, ins.mass, outs.net, ins.net)) { double tempmd = Math.Abs((outs.mass - ins.mass) / (outs.mass + ins.mass)); double tempnd = Math.Abs(outs.net - ins.net); double tempeuc = Math.Sqrt(Math.Pow(tempmd, 2) + Math.Pow(tempnd, 2)); if (euc > tempeuc) { dm = tempmd; dn = tempnd; euc = tempeuc; temprec = ins;// } chk = 1; } } if (chk == 1) { masdiff.Add(dm); netdiff.Add(dn); maserr[Utilities.assignMasbin((outs.mass - temprec.mass) / (outs.mass + temprec.mass))] += 1; neterr[Utilities.assignNetbin(outs.net - temprec.net)] += 1; str += outs.id + "," + outs.mass + "," + outs.net + "," + temprec.id + "," + temprec.mass + "," + temprec.net + "," + temprec.protein + "," + temprec.site + "," + temprec.peptide + "," + temprec.glycan + "," + temprec.type + "\n";// count++; } } ///* int left; if (targ_buck[okey].Count == 0) { left = (refc_buck[ikey].Count - count); } else if (refc_buck[ikey].Count == 0) { left = (targ_buck[okey].Count - count); } else if ((targ_buck[okey].Count - count) < (refc_buck[ikey].Count - count)) { left = (targ_buck[okey].Count - count); } else { left = (refc_buck[ikey].Count - count); } //*/ //int left = (targ_buck[okey].Count - count) + (refc_buck[ikey].Count - count); for (int i = 0; i < left; i++) { masdiff.Add(GlobalVar.TOLMAS); netdiff.Add(GlobalVar.TOLNET); } } } System.IO.File.WriteAllText("hits.csv", str); masstddev = Utilities.deviation(masdiff); netstddev = Utilities.deviation(netdiff); }
public ParseCSV(String name, Boolean flag) { StreamReader file = new StreamReader(name); String line; String[] values; map = new List<GlycoRecord>(); GlycoRecord record = new GlycoRecord(); file.ReadLine(); while ((line = file.ReadLine()) != null) { values = line.Split(','); if (flag) { if (!values[3].Contains("decoy")) { if (values[10].Equals("true", StringComparison.OrdinalIgnoreCase)) { record.id = int.Parse(values[0]); record.mass = double.Parse(values[1]); record.net = double.Parse(values[2]); record.protein = values[3]; record.peptide = values[4]; record.site = values[5]; record.glycan = values[6]; record.pepmass = double.Parse(values[7]); record.glymass = double.Parse(values[8]); record.type = values[9]; record.hcdscore = double.Parse(values[11]); record.cidscore = double.Parse(values[12]); record.etdscore = double.Parse(values[13]); if (GlobalVar.REFCMAXMAS < record.mass) { GlobalVar.REFCMAXMAS = record.mass; } if (GlobalVar.REFCMINMAS > record.mass) { GlobalVar.REFCMINMAS = record.mass; } if (GlobalVar.REFCMAXNET < record.net) { GlobalVar.REFCMAXNET = record.net; } if (GlobalVar.REFCMINNET > record.net) { GlobalVar.REFCMINNET = record.net; } } } } else { record.id = int.Parse(values[0]); record.mass = double.Parse(values[2]); record.net = double.Parse(values[3]); if (GlobalVar.TARGMAXMAS < record.mass) { GlobalVar.TARGMAXMAS = record.mass; } if (GlobalVar.TARGMINMAS > record.mass) { GlobalVar.TARGMINMAS = record.mass; } if (GlobalVar.TARGMAXNET < record.net) { GlobalVar.TARGMAXNET = record.net; } if (GlobalVar.TARGMINNET > record.net) { GlobalVar.TARGMINNET = record.net; } } map.Add(record); } /*if (flag) { if ((GlobalVar.RMAXNET + GlobalVar.TOLNET) < 1.0) { GlobalVar.RMAXNET += GlobalVar.TOLNET; GlobalVar.RMAXNET = (Convert.ToInt32(GlobalVar.RMAXNET / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; } else { GlobalVar.RMAXNET = (1.0 + GlobalVar.BINNET); } if ((GlobalVar.RMINNET - GlobalVar.TOLNET) > 0.0) { GlobalVar.RMINNET -= GlobalVar.TOLNET; GlobalVar.RMINNET = (Convert.ToInt32(GlobalVar.RMINNET / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; } else { GlobalVar.RMINNET = GlobalVar.BINNET; } GlobalVar.RMAXMAS = ((GlobalVar.RMAXMAS * (1 - GlobalVar.TOLMAS)) / (1 + GlobalVar.TOLMAS)); GlobalVar.RMAXMAS = (Convert.ToInt32(GlobalVar.RMAXMAS / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; GlobalVar.RMINMAS = ((GlobalVar.RMINMAS * (1 + GlobalVar.TOLMAS)) / (1 - GlobalVar.TOLMAS)); GlobalVar.RMINMAS = (Convert.ToInt32(GlobalVar.RMINMAS / GlobalVar.BINNET) + 1) * GlobalVar.BINNET; GlobalVar.assignNetKeys(); }*/ file.Close(); }
private void copyData(List<GlycoRecord> targ_ikey, List<GlycoRecord> refc_jkey) { foreach (GlycoRecord outs in targ_ikey) { double dm = 0.0, dn = 0.0, euc = 100.0; GlycoRecord temprec = new GlycoRecord();// int chk = 0; foreach (GlycoRecord ins in refc_jkey) { if (Utilities.check(outs.mass, ins.mass, outs.net, ins.net)) { double tempmd = Math.Abs((outs.mass - ins.mass) / (outs.mass + ins.mass)); double tempnd = Math.Abs(outs.net - ins.net); double tempeuc = Math.Sqrt(Math.Pow(tempmd, 2) + Math.Pow(tempnd, 2)); if (euc > tempeuc) { dm = tempmd; dn = tempnd; euc = tempeuc; temprec = ins;// } chk = 1; //break; } } if (chk == 1) { merg.Add(temprec); str += outs.id + "," + outs.mass + "," + outs.net + "," + temprec.id + "," + temprec.mass + "," + temprec.net + "," + temprec.protein + "," + temprec.site + "," + temprec.peptide + "," + temprec.glycan + "," + temprec.type + "\n";// } if (chk == 0) { //tempmap.Add(outs); } } }