private static List <PeptideAnnotation <AminoAcidReference> > ExtractAnnotations(IList <string> lines, char chainId, Peptide peptide) { var helices = lines .Where(line => ReadLineCode(line) == "HELIX") .Select(ParseHelix) .Where(helix => helix.FirstResidueChainId == chainId); var annotations = new List <PeptideAnnotation <AminoAcidReference> >(); foreach (var helix in helices) { var annotation = new PeptideAnnotation <AminoAcidReference>( PeptideSecondaryStructure.AlphaHelix, peptide.AminoAcids .Where(aa => aa.SequenceNumber >= helix.FirstResidueNumber && aa.SequenceNumber <= helix.LastResidueNumber) .ToList()); annotations.Add(annotation); } var sheetStrandGroups = lines .Where(line => ReadLineCode(line) == "SHEET") .Select(ParseSheetStrand) .Where(strand => strand.FirstResidueChainId == chainId) .GroupBy(strand => strand.SheetId); foreach (var sheetStrands in sheetStrandGroups) { var sheetAminoAcids = new List <AminoAcidReference>(); foreach (var strand in sheetStrands) { var aminoAcids = peptide.AminoAcids.Where(aa => aa.SequenceNumber >= strand.FirstResidueNumber && aa.SequenceNumber <= strand.LastResidueNumber); sheetAminoAcids.AddRange(aminoAcids); } var annotation = new PeptideAnnotation <AminoAcidReference>( PeptideSecondaryStructure.BetaSheet, sheetAminoAcids); annotations.Add(annotation); } return(annotations); }
/// <summary> /// Detects alpha helixes in a peptide. Does NOT add these annotations to peptide. /// </summary> public List <PeptideAnnotation <AminoAcidReference> > Detect(Peptide peptide) { var slidingWindow = new SlidingWindow <AminoAcidReference>( peptide.AminoAcids, x => x.SequenceNumber, 4.5, WindowPositioningType.StartingAtPosition); const int MinimumHelixLength = 7; var helixAnnotations = new List <PeptideAnnotation <AminoAcidReference> >(); PeptideAnnotation <AminoAcidReference> currentAnnotation = null; foreach (var aminoAcid in peptide.AminoAcids.OrderBy(x => x.SequenceNumber)) { if (currentAnnotation != null && aminoAcid.SequenceNumber > currentAnnotation.AminoAcidReferences.Last().SequenceNumber) { if (currentAnnotation.AminoAcidReferences.Count >= MinimumHelixLength) { helixAnnotations.Add(currentAnnotation); } currentAnnotation = null; } slidingWindow.SetPosition(aminoAcid.SequenceNumber - 0.1); // -0.1 to avoid problems with rounding var secondAminoAcid = slidingWindow.FirstOrDefault(x => x.SequenceNumber == aminoAcid.SequenceNumber + 1); if (secondAminoAcid == null) { continue; } var thirdAminoAcid = slidingWindow.FirstOrDefault(x => x.SequenceNumber == aminoAcid.SequenceNumber + 2); if (thirdAminoAcid == null) { continue; } var fourthAminoAcid = slidingWindow.FirstOrDefault(x => x.SequenceNumber == aminoAcid.SequenceNumber + 3); if (fourthAminoAcid == null) { continue; } try { var firstVector = FindPositionVector(aminoAcid, secondAminoAcid); var secondVector = FindPositionVector(aminoAcid, thirdAminoAcid); var thirdVector = FindPositionVector(aminoAcid, fourthAminoAcid); var isAlphaHelix = IsAlphaHelix(firstVector, secondVector, thirdVector); if (isAlphaHelix) { if (currentAnnotation == null) { currentAnnotation = new PeptideAnnotation <AminoAcidReference>( PeptideSecondaryStructure.AlphaHelix, new List <AminoAcidReference> { aminoAcid, secondAminoAcid, thirdAminoAcid, fourthAminoAcid }); } else { currentAnnotation.AminoAcidReferences.Add(fourthAminoAcid); } } else { if (currentAnnotation != null) { if (currentAnnotation.AminoAcidReferences.Count >= MinimumHelixLength) { helixAnnotations.Add(currentAnnotation); } currentAnnotation = null; } } } catch (KeyNotFoundException) { continue; } } return(helixAnnotations); }