/// <summary> /// Shortens a 2D object to a given length, starting at a given connector. /// </summary> /// <param name="length">New length of the object.</param> /// <param name="connector">Connector from which the new length is measured.</param> /// <exception cref="InvalidOperationException">If the object is not new /// or its vertices is not Segment3D or the required length >= than the current one.</exception> public void ShortenTo(double length, ConnectorOnTileInSpace connector) { var segment = Vertices as Segment3D; if (State != FState.Create || segment == null) { throw new InvalidOperationException($"{Name} is not a new 2D object and so it cannot be shortened."); } if (length >= segment.Vector.Length) { throw new ArgumentException($"Shortened length of object {Name} must be smaller than the current one."); } Note = "mutated"; int start = connector.Positions[0].MyEquals(Vertices[0]) ? 0 : 1; var newStartPoint = Vertices[start]; var newEndPoint = newStartPoint + length * (Vertices[1 - start] - newStartPoint).Normalize(); Vertices = new Segment3D(newStartPoint, newEndPoint, Name); // Move connectors at the cut-off end to the new end foreach (var conn in Connectors.Where(conn => conn.Positions[0].DistanceTo(newStartPoint) > length)) { conn.Positions = new ReadOnlyCollection <Point3D>(new[] { newEndPoint }); } // Move proteins at the cut-off end to the new end foreach (var prot in Proteins.Where(prot => prot.Position.DistanceTo(newStartPoint) > length)) { prot.Position = newEndPoint; } }
/// <summary> /// Aggregate the proteins based on the data from the mass tags /// </summary> private void AggregateProteins() { Dictionary <string, Protein> proteinMap = new Dictionary <string, Protein>(); foreach (ConsensusTarget tag in m_massTags) { List <Protein> proteins = tag.GetProteins(); foreach (Protein p in proteins) { if (!proteinMap.ContainsKey(p.Reference)) { proteinMap.Add(p.Reference, p); p.AddConsensusTarget(tag); } else { Protein existingProtein = proteinMap[p.Reference]; existingProtein.AddConsensusTarget(tag); // Add the mass tag to the protein tag.AddProtein(existingProtein); // Add the protein to the mass tag... } } } int globalCount = 0; foreach (Protein p in proteinMap.Values) { p.Id = globalCount++; Proteins.Add(p); } }
public void ShowInfo() { var header = "\"" + Name + "\""; MenuManager.DrawHeader(header, 73); if (Duration != 0) { Console.WriteLine($"Duration: {Duration} minutes"); } var calories = new string[1][]; calories[0] = new string[] { Proteins.ToString(), Fats.ToString(), Carbonohydrates.ToString() }; TableBuilder.DrawTable(new string[] { "Proteins", "Fats", "Carbonohydrates" }, calories); string[] columnsHeaders = new string[] { "Ingredient", "Unit", "Quantity" }; string[][] input = new string[Ingredients.Count][]; for (int i = 0; i < input.Length; i++) { var temp = Ingredients[i].ToDataArray(); temp[2] = Quantities[i].ToString(); input[i] = temp; } TableBuilder.DrawTable(columnsHeaders, input); //Console.WriteLine($"Calories: {"|".PadLeft(27)}{Calories.ToString().PadLeft(18)}{"|".PadLeft(18)}"); Console.WriteLine("-------------------------------------".PadLeft(73)); }
/// <summary> /// Remove a Protein-Spectrum-Match identification from the tree. /// </summary> /// <param name="id">Protein-Spectrum-Match to remove.</param> public void Remove(PrSm id) { if (Proteins.ContainsKey(id.ProteinName)) { Proteins[id.ProteinName].Remove(id); } }
public void Clear() { Targets.Clear(); Proteins.Clear(); RegressionResults = null; ProcessedState = ProcessingState.NotProcessed; m_featureCount = 0; }
public override string ToString() { return ($"\nProteins {Proteins.ToString("0.##")} g = {(Proteins * 4).ToString("0.##")} Kcal" + $"\nFat {Fat.ToString("0.##")} g = {(Fat * 9).ToString("0.##")} Kcal" + $"\nCarbs {Carbs.ToString("0.##")} g = {(Carbs * 4).ToString("0.##")} Kcal" + $"\nTotalgram {TotalGrams.ToString("0.##")} g = {Kcal.ToString("0.##")} Kcal"); }
private void ProteinsToolStripMenuItemOnClick(object sender, EventArgs e) { if (RowSource is Proteins) { return; } RowSource = new Proteins(_dataSchema); }
/// <summary> /// Remove unidentified scans given a PRSM ID containing protein name, proteoform, and scan number. /// </summary> /// <param name="data">PRSM to remove.</param> public void RemoveUnidentifiedScan(PrSm data) { if (Proteins.TryGetValue(string.Empty, out var protein) && protein.Proteoforms.TryGetValue(string.Empty, out var proteoform) && proteoform.ChargeStates.TryGetValue(0, out var chargeState)) { chargeState.Remove(data); } }
/// <summary> /// Clear all proteins without proteoforms. /// </summary> public void ClearEmptyProteins() { Proteins.Clear(); foreach (var protein in allProteins) { if (protein.Value.Proteoforms.Count > 0) { Proteins.Add(protein.Key, protein.Value); } } }
/// <summary> /// Get a protein associated with a certain ID. /// </summary> /// <param name="id">ID to search for.</param> /// <returns>The protein ID found.</returns> public ProteinId GetProtein(PrSm id) { ProteinId protein = null; if (Proteins.ContainsKey(id.ProteinName)) { protein = Proteins[id.ProteinName]; } return(protein); }
public void MergeProteinGroupWith(ProteinGroup other) { this.Proteins.UnionWith(other.Proteins); this.AllPeptides.UnionWith(other.AllPeptides); this.UniquePeptides.UnionWith(other.UniquePeptides); this.AllPsmsBelowOnePercentFDR.UnionWith(other.AllPsmsBelowOnePercentFDR); other.ProteinGroupScore = 0; ListOfProteinsOrderedByAccession = Proteins.OrderBy(p => p.Accession).ToList(); ProteinGroupName = string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.Accession)); }
/// <summary> /// Loads data from a peptide identification file /// </summary> /// <param name="merge"> /// A <see cref="System.Boolean"/> indicating wether merge the new file with the existing data /// </param> public void Load( string path, bool merge ) { if( !merge || m_Run == 0 ) { m_InputFiles.Clear(); Proteins.Clear(); Peptides.Clear(); Spectra.Clear(); m_gid = 1; m_SortedProteins = new SortedList<string, Protein>(); m_Run = 1; } else m_Run++; Load( path ); m_InputFiles.Add( Path.GetFileName(path) ); }
public void AddProtein(Protein protein) { Proteins.Add(protein); if (RepresentativeProtein == null) { RepresentativeProtein = protein; } else { if (protein.Length > RepresentativeProtein.Length) { RepresentativeProtein = protein; } } }
public void ShowIngredients() { var calories = new string[1][]; calories[0] = new string[] { Proteins.ToString(), Fats.ToString(), Carbonohydrates.ToString() }; TableBuilder.DrawTable(new string[] { "Proteins", "Fats", "Carbonohydrates" }, calories); string[] columnsHeaders = new string[] { "Ingredient", "Unit", "Quantity" }; string[][] input = new string[Ingredients.Count][]; for (int i = 0; i < input.Length; i++) { var temp = Ingredients[i].ToDataArray(); temp[2] = Quantities[i].ToString(); input[i] = temp; } TableBuilder.DrawTable(columnsHeaders, input); }
/// <summary> /// Add a Protein-Spectrum-Match identification. /// </summary> /// <param name="id">Protein-Spectrum-Math to add</param> public void Add(PrSm id) { RemoveUnidentifiedScan(id); if (!allProteins.ContainsKey(id.ProteinName)) { return; ////this.allProteins.Add(id.ProteinName, new ProteinId(id.Sequence, id.ProteinName)); } if (!Proteins.ContainsKey(id.ProteinName)) { Proteins.Add(id.ProteinName, allProteins[id.ProteinName]); } var protein = Proteins[id.ProteinName]; protein.Add(id); }
private SortedList<string,string> LoadProteins() { SortedList<string,string> SortedAccession = new SortedList<string, string>(); foreach( DBSequenceType prot in m_mzid.ListProteins ) { if( SortedAccession.ContainsKey(prot.id) ) // Avoids duplicated entries in the same file continue; SortedAccession.Add( prot.id, prot.accession ); if( m_SortedProteins.ContainsKey(prot.accession) ) // Avoids duplicated entries between different files continue; CVParamType cv = mzidFile1_1.FindCV("MS:1001352", prot.Items); string entry = cv == null ? "" : cv.value; cv = mzidFile1_1.FindCV("MS:1001088", prot.Items); string desc = cv == null ? "" : cv.value; Protein p = new Protein( m_pid++, entry, prot.accession, desc, prot.Seq ); p.DBRef = prot.id; Proteins.Add( p ); m_SortedProteins.Add( p.Accession, p ); } return SortedAccession; }
private void LoadData( string xmlpath ) { SortedList<int,string> SortedAccession = new SortedList<int, string>(); XmlDocument doc = new XmlDocument(); doc.Load( xmlpath ); // Load proteins XmlNodeList proteins = doc.GetElementsByTagName( "PROTEIN" ); foreach( XmlElement element in proteins ) { int id = int.Parse(element.GetAttribute("ID")); if( SortedAccession.ContainsKey(id) ) continue; string acc = element.GetElementsByTagName("ACCESSION")[0].InnerText; SortedAccession.Add( id, acc ); if( m_SortedProteins.ContainsKey(acc) ) continue; string entry = element.GetElementsByTagName("ENTRY")[0].InnerText; string desc = element.GetElementsByTagName("DESCRIPTION")[0].InnerText.Replace('+',' '); string seq = element.GetElementsByTagName("SEQUENCE")[0].InnerText.ToUpper(); Protein p = new Protein(m_pid++, entry, acc, desc, seq); Proteins.Add( p ); m_SortedProteins.Add( acc, p ); } // Load peptides SortedList<int,Peptide> SortedPeptides = new SortedList<int, Peptide>(); XmlNodeList peptides = doc.GetElementsByTagName( "PEPTIDE" ); foreach( XmlElement element in peptides ) { int id = int.Parse(element.GetAttribute("ID")); int pid = int.Parse(element.GetAttribute("PROT_ID")); int mid = 0; if( PlgsThreshold != Peptide.ConfidenceType.NoThreshold ) mid = int.Parse(element.GetAttribute("QUERY_MASS_ID")); string seq = element.GetAttribute("SEQUENCE").ToUpper(); Peptide f = new Peptide(id, seq); XmlNodeList mods = element.GetElementsByTagName( "MATCH_MODIFIER" ); f.Runs.Add( m_Run ); foreach( XmlElement mod in mods ) { PTM ptm = new PTM(); string[] strs = mod.GetAttribute("NAME").Split(new char[]{'+'}); ptm.Name = strs[0]; string str = mod.GetAttribute("POS"); ptm.Pos = str.Length == 0 ? -1 : int.Parse(str); if( strs.Length > 1 ) ptm.Residues = strs[1]; f.AddPTM( ptm ); } Protein p = null; try { p = m_SortedProteins[SortedAccession[pid]]; } catch { Notify( "Peptide '" + id + "' references unknown protein '" + pid + "'" ); } if( p != null ) { p.Peptides.Add( f ); f.Proteins.Add( p ); if( !p.Sequence.Contains(f.Sequence) ) throw new ApplicationException( "Inconsistent sequence data" ); } Peptides.Add( f ); if( PlgsThreshold != Peptide.ConfidenceType.NoThreshold ) SortedPeptides.Add(mid,f); } if( PlgsThreshold == Peptide.ConfidenceType.NoThreshold ) return; // Scores XmlNodeList scores = doc.GetElementsByTagName( "MASS_MATCH" ); foreach( XmlElement element in scores ) { int id = int.Parse(element.GetAttribute("ID")); double score = double.Parse(element.GetAttribute("SCORE"), m_Format); SortedPeptides[id].Score = score; } }
/// <summary> /// Add another protein the ConsensusTarget occurs in /// </summary> /// <param name="protein"></param> public void AddProtein(ProteinInformation protein) { Proteins.Add(protein); protein.Consensus.Add(this); }
public void CalculateSequenceCoverage() { var proteinsWithUnambigSeqPsms = new Dictionary <Protein, List <PeptideWithSetModifications> >(); var proteinsWithPsmsWithLocalizedMods = new Dictionary <Protein, List <PeptideWithSetModifications> >(); foreach (var protein in Proteins) { proteinsWithUnambigSeqPsms.Add(protein, new List <PeptideWithSetModifications>()); proteinsWithPsmsWithLocalizedMods.Add(protein, new List <PeptideWithSetModifications>()); } foreach (var psm in AllPsmsBelowOnePercentFDR) { // null BaseSequence means that the amino acid sequence is ambiguous; do not use these to calculate sequence coverage if (psm.BaseSequence != null) { var peptides = psm.BestMatchingPeptides.Select(p => p.Peptide); foreach (var peptide in peptides) { // might be unambiguous but also shared; make sure this protein group contains this peptide+protein combo if (Proteins.Contains(peptide.Protein)) { proteinsWithUnambigSeqPsms[peptide.Protein].Add(peptide); // null FullSequence means that mods were not successfully localized; do not display them on the sequence coverage mods info if (psm.FullSequence != null) { proteinsWithPsmsWithLocalizedMods[peptide.Protein].Add(peptide); } } } } } foreach (var protein in ListOfProteinsOrderedByAccession) { HashSet <int> coveredOneBasedResidues = new HashSet <int>(); // get residue numbers of each peptide in the protein and identify them as observed if the sequence is unambiguous foreach (var peptide in proteinsWithUnambigSeqPsms[protein]) { for (int i = peptide.OneBasedStartResidueInProtein; i <= peptide.OneBasedEndResidueInProtein; i++) { coveredOneBasedResidues.Add(i); } } // calculate sequence coverage percent double seqCoverageFract = (double)coveredOneBasedResidues.Count / protein.Length; // add the percent coverage SequenceCoverageFraction.Add(seqCoverageFract); // convert the observed amino acids to upper case if they are unambiguously observed string sequenceCoverageDisplay = protein.BaseSequence.ToLower(); var coverageArray = sequenceCoverageDisplay.ToCharArray(); foreach (var obsResidueLocation in coveredOneBasedResidues) { coverageArray[obsResidueLocation - 1] = char.ToUpper(coverageArray[obsResidueLocation - 1]); } sequenceCoverageDisplay = new string(coverageArray); // add the coverage display SequenceCoverageDisplayList.Add(sequenceCoverageDisplay); // put mods in the sequence coverage display // get mods to display in sequence (only unambiguously identified mods) var modsOnThisProtein = new HashSet <KeyValuePair <int, Modification> >(); foreach (var pep in proteinsWithPsmsWithLocalizedMods[protein]) { foreach (var mod in pep.AllModsOneIsNterminus) { if (!mod.Value.ModificationType.Contains("PeptideTermMod") && !mod.Value.ModificationType.Contains("Common Variable") && !mod.Value.ModificationType.Contains("Common Fixed")) { modsOnThisProtein.Add(new KeyValuePair <int, Modification>(pep.OneBasedStartResidueInProtein + mod.Key - 2, mod.Value)); } } } var tempMods = modsOnThisProtein.OrderBy(p => p.Key).ToList(); foreach (var mod in tempMods) { if (mod.Value.LocationRestriction.Equals("N-terminal.")) { sequenceCoverageDisplay = sequenceCoverageDisplay.Insert( 0, $"[{mod.Value.IdWithMotif}]-"); } else if (mod.Value.LocationRestriction.Equals("Anywhere.")) { int modStringIndex = sequenceCoverageDisplay.Length - (protein.Length - mod.Key); sequenceCoverageDisplay = sequenceCoverageDisplay.Insert( modStringIndex, $"[{mod.Value.IdWithMotif}]"); } else if (mod.Value.LocationRestriction.Equals("C-terminal.")) { sequenceCoverageDisplay = sequenceCoverageDisplay.Insert( sequenceCoverageDisplay.Length, $"-[{mod.Value.IdWithMotif}]"); } } SequenceCoverageDisplayListWithMods.Add(sequenceCoverageDisplay); if (!modsOnThisProtein.Any()) { continue; } // calculate spectral count % of modified observations var pepModTotals = new List <int>(); // count of modified peptides for each mod/index var pepTotals = new List <int>(); // count of all peptides for each mod/index var modIndex = new List <(int index, string modName)>(); // index and name of the modified position foreach (var pep in proteinsWithPsmsWithLocalizedMods[protein]) { foreach (var mod in pep.AllModsOneIsNterminus) { int pepNumTotal = 0; //For one mod, The total Pep Num if (mod.Value.ModificationType.Contains("Common Variable") || mod.Value.ModificationType.Contains("Common Fixed") || mod.Value.LocationRestriction.Equals(ModLocationOnPeptideOrProtein.PepC) || mod.Value.LocationRestriction.Equals(ModLocationOnPeptideOrProtein.NPep)) { continue; } int indexInProtein; if (mod.Value.LocationRestriction.Equals("N-terminal.")) { indexInProtein = 1; } else if (mod.Value.LocationRestriction.Equals("Anywhere.")) { indexInProtein = pep.OneBasedStartResidueInProtein + mod.Key - 2; } else if (mod.Value.LocationRestriction.Equals("C-terminal.")) { indexInProtein = protein.Length; } else { // In case it's a peptide terminal mod, skip! // we don't want this annotated in the protein's modifications continue; } var modKey = (indexInProtein, mod.Value.IdWithMotif); if (modIndex.Contains(modKey)) { pepModTotals[modIndex.IndexOf(modKey)] += 1; } else { modIndex.Add(modKey); foreach (var pept in proteinsWithPsmsWithLocalizedMods[protein]) { if (indexInProtein >= pept.OneBasedStartResidueInProtein - (indexInProtein == 1 ? 1 : 0) && indexInProtein <= pept.OneBasedEndResidueInProtein) { pepNumTotal += 1; } } pepTotals.Add(pepNumTotal); pepModTotals.Add(1); } } } var modStrings = new List <(int aaNum, string part)>(); for (int i = 0; i < pepModTotals.Count; i++) { string aa = modIndex[i].index.ToString(); string modName = modIndex[i].modName.ToString(); string occupancy = ((double)pepModTotals[i] / (double)pepTotals[i]).ToString("F2"); string fractOccupancy = $"{pepModTotals[i].ToString()}/{pepTotals[i].ToString()}"; string tempString = ($"#aa{aa}[{modName},info:occupancy={occupancy}({fractOccupancy})]"); modStrings.Add((modIndex[i].index, tempString)); } var modInfoString = string.Join(";", modStrings.OrderBy(x => x.aaNum).Select(x => x.part)); if (!string.IsNullOrEmpty(modInfoString)) { ModsInfo.Add(modInfoString); } } }
public virtual string ToString(string format, IFormatProvider formatProvider) { return(NameProduct + " " + Weight.ToString() + " " + Proteins.ToString() + " " + Fats.ToString() + " " + Carbohydrates.ToString()); }
/// <summary> /// Add a protein to the list of proteins evidenced /// </summary> /// <param name="protein"></param> public void AddProtein(ProteinInformation protein) { Proteins.Add(protein); }
/// <summary> /// Clears an existing target and protein data /// </summary> public void ClearTargets() { ConsensusTargets.Clear(); Proteins.Clear(); }
/// <summary> /// Loads a mzIdentML file /// </summary> override protected void Load( string mzid ) { m_mzid = new mzidFile1_0(); m_mzid.Load( mzid ); // Proteins SortedList<string,string> SortedAccession = new SortedList<string, string>(); foreach( PSIPIanalysissearchDBSequenceType element in m_mzid.ListProteins ) { if( SortedAccession.ContainsKey(element.id) ) continue; string acc = element.accession; SortedAccession.Add( element.id, acc ); if( m_SortedProteins.ContainsKey(acc) ) continue; FuGECommonOntologycvParamType cv; cv = FuGECommonOntologycvParamType.Find( "MS:1001352", element.cvParam ); string entry = cv == null ? "" : cv.value; cv = FuGECommonOntologycvParamType.Find( "MS:1001088", element.cvParam ); string desc = cv == null ? "" : cv.value; string seq = element.seq;//.ToUpper(); Protein p = new Protein(m_pid++, entry, acc, desc, seq); p.DBRef = element.id; Proteins.Add( p ); m_SortedProteins.Add( acc, p ); } // Peptides SortedList<string,Peptide> SortedPeptides = new SortedList<string, Peptide>(); int id = 1; foreach( PSIPIpolypeptidePeptideType element in m_mzid.ListPeptides ) { string seq = element.peptideSequence;//.ToUpper(); Peptide f = new Peptide(id++, seq); f.Confidence = Peptide.ConfidenceType.PassThreshold; // It will be filtered later if neccessary SortedPeptides.Add( element.id, f ); f.Runs.Add( m_Run ); if( element.Modification != null ) foreach( PSIPIpolypeptideModificationType mod in element.Modification ) { PTM ptm = new PTM(); ptm.Pos = mod.locationSpecified ? mod.location : -1; if( mod.residues != null ) foreach( string residue in mod.residues ) ptm.Residues += residue; foreach( FuGECommonOntologycvParamType param in mod.cvParam ) if( param.cvRef.Equals("UNIMOD") ) ptm.Name = param.name; f.AddPTM( ptm ); } Peptides.Add( f ); } // Relations if( m_mzid.Data.DataCollection.AnalysisData.SpectrumIdentificationList.Length != 1 ) throw new ApplicationException( "Multiple spectrum identification lists not supported" ); foreach( PSIPIanalysissearchSpectrumIdentificationResultType idres in m_mzid.Data.DataCollection.AnalysisData.SpectrumIdentificationList[0].SpectrumIdentificationResult ) foreach( PSIPIanalysissearchSpectrumIdentificationItemType item in idres.SpectrumIdentificationItem ) { if( !item.passThreshold ) continue; Peptide f = SortedPeptides[item.Peptide_ref]; if( item.PeptideEvidence == null ) continue; f.Confidence = Peptide.ConfidenceType.PassThreshold; foreach( PSIPIanalysisprocessPeptideEvidenceType relation in item.PeptideEvidence ) { Protein p = m_SortedProteins[SortedAccession[relation.DBSequence_Ref]]; if( f.Proteins.Contains(p) ) continue; f.Names.Add( relation.DBSequence_Ref, relation.id ); p.Peptides.Add( f ); f.Proteins.Add( p ); } } }
//Returns Search History of specific query ie. search Parameters and Results public Searchview retrieve_searchview_db(string qid) { var result = new Searchview(); var qp = new QuerryParameters(); var res = new Results(); var qidArr = qid.Split('z'); qid = qidArr[0]; var fileId = Convert.ToInt32(qidArr[1]); var query1 = "SELECT * FROM proteomics.query where QueryId='" + qid + "';"; var queryT = "SELECT * FROM proteomics.timings where querry_ID='" + qid + "';"; if (OpenConnection()) { try { using (var trans = _connection.BeginTransaction()) { var cmd = new MySqlCommand(queryT, _connection); var reader = cmd.ExecuteReader(); if (reader.Read()) { res.Times.InsilicoTime = reader.GetValue(1).ToString(); res.Times.PtmTime = reader.GetValue(2).ToString(); res.Times.TunerTime = reader.GetValue(3).ToString(); res.Times.MwFilterTime = reader.GetValue(4).ToString(); res.Times.PstTime = reader.GetValue(5).ToString(); res.Times.TotalTime = reader.GetValue(6).ToString(); res.Times.FileName = reader.GetValue(7).ToString(); } reader.Close(); cmd = new MySqlCommand(query1, _connection); reader = cmd.ExecuteReader(); if (reader.Read()) { qp.QueryId = reader.GetValue(0).ToString(); qp.UserId = reader.GetValue(1).ToString(); qp.Title = reader.GetValue(2).ToString(); qp.ProtDb = reader.GetValue(3).ToString(); //qp.OutputFormat = Convert.ToInt32(reader.GetValue(4)); qp.InsilicoFragType = reader.GetValue(5).ToString(); qp.FilterDb = Convert.ToInt32(reader.GetValue(6)); qp.PtmTolerance = Convert.ToDouble(reader.GetValue(7)); qp.MwTolUnit = reader.GetValue(8).ToString(); qp.MwTolerance = Convert.ToDouble(reader.GetValue(9)); qp.HopThreshhold = Convert.ToDouble(reader.GetValue(10)); qp.MinimumEstLength = Convert.ToInt32(reader.GetValue(11)); qp.MaximumEstLength = Convert.ToInt32(reader.GetValue(12)); qp.GuiMass = Convert.ToDouble(reader.GetValue(13)); qp.HandleIons = reader.GetValue(14).ToString(); qp.Autotune = Convert.ToInt32(reader.GetValue(15)); qp.PeakListFile = reader.GetValue(16).ToString().Split('<'); qp.FileType = reader.GetValue(17).ToString(); qp.HopTolUnit = reader.GetValue(18).ToString(); qp.MwSweight = Convert.ToDouble(reader.GetValue(19)); qp.PstSweight = Convert.ToDouble(reader.GetValue(20)); qp.InsilicoSweight = Convert.ToDouble(reader.GetValue(21)); qp.NumberOfOutputs = Convert.ToInt32(reader.GetValue(22)); qp.DenovoAllow = Convert.ToInt32(reader.GetValue(23)); qp.PtmAllow = Convert.ToInt32(reader.GetValue(24)); qp.NeutralLoss = Convert.ToDouble(reader.GetValue(25)); //NeutralLoss Added!!! qp.PSTTolerance = Convert.ToDouble(reader.GetValue(26)); //PSTTolerance Added!!! } reader.Close(); query1 = "SELECT fixed_mod FROM fixed_modifications where QueryId='" + qid + "';"; cmd = new MySqlCommand(query1, _connection); using (reader = cmd.ExecuteReader()) { qp.PtmCodeFix = new List <int>(); while (reader.Read()) { qp.PtmCodeFix.Add(Convert.ToInt32(reader["fixed_mod"])); } } reader.Close(); query1 = "SELECT variable_mod FROM variable_modifications where QueryId='" + qid + "';"; cmd = new MySqlCommand(query1, _connection); using (reader = cmd.ExecuteReader()) { qp.PtmCodeVar = new List <int>(); while (reader.Read()) { qp.PtmCodeVar.Add(Convert.ToInt32(reader["variable_mod"])); } } reader.Close(); var query2 = "SELECT * FROM results where Querry_ID='" + qid + "' AND file_ID = " + fileId + " ORDER BY Score DESC LIMIT " + qp.NumberOfOutputs + ";"; cmd = new MySqlCommand(query2, _connection); res.QueryId = qid; res.FinalProt = new List <Proteins>(); var resid = new List <string>(); using (reader = cmd.ExecuteReader()) { while (reader.Read()) { var tempProt = new Proteins(); resid.Add(reader.GetValue(0).ToString()); tempProt.Header = reader.GetValue(2).ToString(); tempProt.Sequence = reader.GetValue(3).ToString(); tempProt.EstScore = Convert.ToDouble(reader.GetValue(4)); tempProt.InsilicoScore = Convert.ToDouble(reader.GetValue(5)); tempProt.PtmScore = Convert.ToDouble(reader.GetValue(6)); tempProt.Score = Convert.ToDouble(reader.GetValue(7)); tempProt.MwScore = Convert.ToDouble(reader.GetValue(8)); tempProt.Mw = Convert.ToDouble(reader.GetValue(9)); res.FinalProt.Add(tempProt); } } reader.Close(); for (var i = 0; i < resid.Count; i++) { query2 = "SELECT * FROM ptm_sites where result_id='" + resid[i] + "';"; cmd = new MySqlCommand(query2, _connection); using (reader = cmd.ExecuteReader()) { while (reader.Read()) { var tempSite = new Sites { Index = Convert.ToInt32(reader.GetValue(1)), Score = Convert.ToInt32(reader.GetValue(2)), ModWeight = Convert.ToInt32(reader.GetValue(3)), ModName = reader.GetValue(4).ToString(), Site = Convert.ToChar(reader.GetValue(5)) }; var tempaa = reader.GetValue(6).ToString(); foreach (char aminoacid in tempaa) { tempSite.AminoAcid.Add(aminoacid); } res.FinalProt[i].PtmParticulars.Add(tempSite); } } } reader.Close(); string xx; for (var i = 0; i < resid.Count; i++) { query2 = "SELECT matched_peak_left FROM insilico_matches_left where result_id='" + resid[i] + "';"; cmd = new MySqlCommand(query2, _connection); using (reader = cmd.ExecuteReader()) { if (reader.Read()) { xx = reader.GetValue(0).ToString(); res.FinalProt[i].InsilicoDetails.PeaklistMassLeft = xx.Split(',').Select(double.Parse).ToList(); } } query2 = "SELECT Ions FROM leftions where ProteinID='" + res.FinalProt[i].Header + "';"; cmd = new MySqlCommand(query2, _connection); using (reader = cmd.ExecuteReader()) { if (!reader.Read()) { continue; } xx = reader.GetValue(0).ToString(); xx = Decompress(xx); res.FinalProt[i].InsilicoDetails.InsilicoMassLeft = xx.Split(',').Select(double.Parse).ToList(); } } reader.Close(); for (var i = 0; i < resid.Count; i++) { query2 = "SELECT matchedpeak_right FROM insilico_matches_right where result_id='" + resid[i] + "';"; cmd = new MySqlCommand(query2, _connection); using (reader = cmd.ExecuteReader()) { if (reader.Read()) { xx = reader.GetValue(0).ToString(); res.FinalProt[i].InsilicoDetails.PeaklistMassRight = xx.Split(',').Select(double.Parse).ToList(); } } query2 = "SELECT Ions FROM rightions where ProteinID='" + res.FinalProt[i].Header + "';"; cmd = new MySqlCommand(query2, _connection); using (reader = cmd.ExecuteReader()) { if (reader.Read()) { xx = reader.GetValue(0).ToString(); xx = Decompress(xx); res.FinalProt[i].InsilicoDetails.InsilicoMassRight = xx.Split(',').Select(double.Parse).ToList(); } } } reader.Close(); result.Param = qp; result.Result = res; trans.Commit(); _connection.Close(); } } catch (Exception e) { Debug.WriteLine(e.Message); } return(result); } return(result); }
public void CalculateSequenceCoverage() { var proteinsWithUnambigSeqPsms = new Dictionary <Protein, List <PeptideWithSetModifications> >(); var proteinsWithPsmsWithLocalizedMods = new Dictionary <Protein, List <PeptideWithSetModifications> >(); foreach (var protein in Proteins) { proteinsWithUnambigSeqPsms.Add(protein, new List <PeptideWithSetModifications>()); proteinsWithPsmsWithLocalizedMods.Add(protein, new List <PeptideWithSetModifications>()); } foreach (var psm in AllPsmsBelowOnePercentFDR) { // null BaseSequence means that the amino acid sequence is ambiguous; do not use these to calculate sequence coverage if (psm.BaseSequence != null) { var PepsWithSetMods = psm.CompactPeptides.SelectMany(b => b.Value.Item2); foreach (var pepWithSetMods in PepsWithSetMods) { // might be unambiguous but also shared; make sure this protein group contains this peptide+protein combo if (Proteins.Contains(pepWithSetMods.Protein)) { proteinsWithUnambigSeqPsms[pepWithSetMods.Protein].Add(pepWithSetMods); // null FullSequence means that mods were not successfully localized; do not display them on the sequence coverage mods info if (psm.FullSequence != null) { proteinsWithPsmsWithLocalizedMods[pepWithSetMods.Protein].Add(pepWithSetMods); } } } } } foreach (var protein in ListOfProteinsOrderedByAccession) { bool errorResult = false; var sequenceCoverageDisplay = protein.BaseSequence.ToLower(CultureInfo.InvariantCulture); HashSet <int> coveredOneBasedResidues = new HashSet <int>(); // get residue numbers of each peptide in the protein and identify them as observed if the sequence is unambiguous foreach (var peptide in proteinsWithUnambigSeqPsms[protein]) { string sequenceExtractedFromProtein = ""; for (int i = peptide.OneBasedStartResidueInProtein; i <= peptide.OneBasedEndResidueInProtein; i++) { // check for bugs in sequence coverage; make sure we have the right amino acids! sequenceExtractedFromProtein += sequenceCoverageDisplay[i - 1]; coveredOneBasedResidues.Add(i); } if (!sequenceExtractedFromProtein.ToUpper().Equals(peptide.BaseSequence)) { errorResult = true; } } // calculate sequence coverage percent double seqCoveragePercent = (double)coveredOneBasedResidues.Count / protein.Length; if (seqCoveragePercent > 1) { errorResult = true; } // add the percent coverage or NaN if there was an error if (!errorResult) { SequenceCoveragePercent.Add(seqCoveragePercent); } else { SequenceCoveragePercent.Add(double.NaN); } // convert the observed amino acids to upper case if they are unambiguously observed var coverageArray = sequenceCoverageDisplay.ToCharArray(); foreach (var obsResidueLocation in coveredOneBasedResidues) { coverageArray[obsResidueLocation - 1] = char.ToUpper(coverageArray[obsResidueLocation - 1]); } sequenceCoverageDisplay = new string(coverageArray); // check to see if there was an errored result; if not, add the coverage display if (!errorResult) { SequenceCoverageDisplayList.Add(sequenceCoverageDisplay); } else { SequenceCoverageDisplayList.Add("Error calculating sequence coverage"); } // put mods in the sequence coverage display if (!errorResult) { // get mods to display in sequence (only unambiguously identified mods) var modsOnThisProtein = new HashSet <KeyValuePair <int, ModificationWithMass> >(); foreach (var pep in proteinsWithPsmsWithLocalizedMods[protein]) { foreach (var mod in pep.AllModsOneIsNterminus) { if (!mod.Value.modificationType.Contains("PeptideTermMod") && !mod.Value.modificationType.Contains("Common Variable") && !mod.Value.modificationType.Contains("Common Fixed")) { modsOnThisProtein.Add(new KeyValuePair <int, ModificationWithMass>(pep.OneBasedStartResidueInProtein + mod.Key - 2, mod.Value)); } } } var temp1 = modsOnThisProtein.OrderBy(p => p.Key).ToList(); foreach (var mod in temp1) { if (mod.Value.terminusLocalization.Equals(TerminusLocalization.NProt)) { sequenceCoverageDisplay = sequenceCoverageDisplay.Insert(0, "[" + mod.Value.id + "]-"); } else if (mod.Value.terminusLocalization.Equals(TerminusLocalization.Any)) { int modStringIndex = sequenceCoverageDisplay.Length - (protein.Length - mod.Key); sequenceCoverageDisplay = sequenceCoverageDisplay.Insert(modStringIndex, "[" + mod.Value.id + "]"); } else if (mod.Value.terminusLocalization.Equals(TerminusLocalization.ProtC)) { sequenceCoverageDisplay = sequenceCoverageDisplay.Insert(sequenceCoverageDisplay.Length, "-[" + mod.Value.id + "]"); } } SequenceCoverageDisplayListWithMods.Add(sequenceCoverageDisplay); if (modsOnThisProtein.Any()) { // calculate spectral count percentage of modified observation string tempModStrings = ""; //The whole string List <int> tempPepModTotals = new List <int>(); //The List of (For one mod, The Modified Pep Num) List <int> tempPepTotals = new List <int>(); //The List of (For one mod, The total Pep Num) List <string> tempPepModValues = new List <string>(); //The List of (For one mod, the Modified Name) List <int> tempModIndex = new List <int>(); //The Index of the modified position. foreach (var pep in proteinsWithPsmsWithLocalizedMods[protein]) { foreach (var mod in pep.AllModsOneIsNterminus) { int tempPepNumTotal = 0; //For one mod, The total Pep Num if (!mod.Value.modificationType.Contains("Common Variable") && !mod.Value.modificationType.Contains("Common Fixed") && !mod.Value.terminusLocalization.Equals(TerminusLocalization.PepC) && !mod.Value.terminusLocalization.Equals(TerminusLocalization.NPep)) { int tempIndexInProtein; if (mod.Value.terminusLocalization.Equals(TerminusLocalization.NProt)) { tempIndexInProtein = 1; } else if (mod.Value.terminusLocalization.Equals(TerminusLocalization.Any)) { tempIndexInProtein = pep.OneBasedStartResidueInProtein + mod.Key - 2; } else if (mod.Value.terminusLocalization.Equals(TerminusLocalization.ProtC)) { tempIndexInProtein = protein.Length; } else { // In case it's a peptide mod, skip! continue; } if (tempModIndex.Contains(tempIndexInProtein) && tempPepModValues[tempModIndex.IndexOf(tempIndexInProtein)] == mod.Value.id) { tempPepModTotals[tempModIndex.IndexOf(tempIndexInProtein)] += 1; } else { tempModIndex.Add(tempIndexInProtein); foreach (var pept in proteinsWithPsmsWithLocalizedMods[protein]) { if (tempIndexInProtein >= pept.OneBasedStartResidueInProtein - (tempIndexInProtein == 1 ? 1 : 0) && tempIndexInProtein <= pept.OneBasedEndResidueInProtein) { tempPepNumTotal += 1; } } tempPepTotals.Add(tempPepNumTotal); tempPepModValues.Add(mod.Value.id); tempPepModTotals.Add(1); } } } } for (int i = 0; i < tempPepModTotals.Count; i++) { string tempString = ("#aa" + tempModIndex[i].ToString() + "[" + tempPepModValues[i].ToString() + ",info:occupancy=" + ((double)tempPepModTotals[i] / (double)tempPepTotals[i]).ToString("F2") + "(" + tempPepModTotals[i].ToString() + "/" + tempPepTotals[i].ToString() + ")" + "];"); tempModStrings += tempString; } if (!string.IsNullOrEmpty(tempModStrings)) { ModsInfo.Add(tempModStrings); } } } } }
IEnumerator IEnumerable.GetEnumerator() { return(Proteins.GetEnumerator()); }
public IEnumerator <Protein> GetEnumerator() { return(Proteins.GetEnumerator()); }
public bool Equals(ProteinGroup other) { return(Proteins.SetEquals(other.Proteins)); }