public void HelicalWheelBuilderThreeLetter(string aminoAcids, SKCanvas canvas) { var aminoClass = new AminoAcids(); var listAminos = aminoAcids.Split(',').ToList(); float xval = 0; float yval = 0; float xModifier = 0; float yModifier = 0; float modIncrementer = 0; float scaleModifier = 19; int angle = 270; bool polarity = false; string lastAmino = ""; int incr = 1; var percentDiff = (App.ScreenHeight / ScaleFactor); foreach (var item in listAminos) { if (!string.IsNullOrWhiteSpace(item)) { if (!string.IsNullOrWhiteSpace(lastAmino)) { if (incr < 18) { canvas.DrawLine(xval, yval, (float)((RADIUS * percentDiff) * Math.Cos(angle * Math.PI / 180F)), (float)((RADIUS * percentDiff) * Math.Sin(angle * Math.PI / 180F)), Line); } if (polarity) { canvas.DrawText(lastAmino.Substring(0, 1).ToString().ToUpper() + lastAmino.Substring(1, 2) + incr, xval - 7, yval + 4, PolarLetters); } else { canvas.DrawText(lastAmino.Substring(0, 1).ToString().ToUpper() + lastAmino.Substring(1, 2) + incr, xval - 7, yval + 4, NonPolarLetters); } incr += 1; } xval = (float)((RADIUS * percentDiff) * Math.Cos(angle * Math.PI / 180F)); yval = (float)((RADIUS * percentDiff) * Math.Sin(angle * Math.PI / 180F)); HelicalStructure.Add(new KeyValuePair <string, Point>(item.Substring(0, 1).ToString().ToUpper() + item.Substring(1, 2) + incr, new Point(xval, yval))); if (incr % scaleModifier == 0) { modIncrementer += 1; scaleModifier = scaleModifier + 18; } xModifier = xval > 0 ? 13f * modIncrementer : -13f * modIncrementer; yModifier = yval > 0 ? 13f * modIncrementer : -13f * modIncrementer; if (Math.Abs(xval) < 5 && modIncrementer > 0) { yModifier = yModifier > 0 ? (yModifier - .5f) + (6 * modIncrementer) : (yModifier + .5f) - (6 * modIncrementer); xModifier = 0; } xval += xModifier; yval += yModifier; if (aminoClass.IsAminoAcid(item)) { if (polarity = aminoClass.IsPolar(item)) { canvas.DrawCircle(xval, yval, (AMINORADIUS * percentDiff), PolarAminoAcid); } else { canvas.DrawCircle(xval, yval, (AMINORADIUS * percentDiff), NonPolarAminoAcid); } } else { canvas.DrawCircle(xval, yval, (AMINORADIUS * percentDiff), InvalidAminoAcid); } angle += 100; if (angle > 360) { angle -= 360; } lastAmino = item; } } if (!string.IsNullOrWhiteSpace(lastAmino)) { if (polarity) { canvas.DrawText(lastAmino.Substring(0, 1).ToString().ToUpper() + lastAmino.Substring(1, 2) + incr, xval - 7, yval + 4, PolarLetters); } else { canvas.DrawText(lastAmino.Substring(0, 1).ToString().ToUpper() + lastAmino.Substring(1, 2) + incr, xval - 7, yval + 4, NonPolarLetters); } } }
private void RunAminoAnalysis(List <KeyValuePair <string, Point> > aminoList) { var items = aminoList; bool prolineFound = false; bool invalidAminoAcid = false; var structErrors = new List <string>(); StructureAnalysis.Text = "The following issues were found: \n"; StructureAnalysis.TextColor = Color.Red; foreach (var item in aminoList) { var countItem = item.Key.ToCharArray().ToList().Where(x => char.IsDigit(x)).Count(); if ((item.Key.Substring(0, 1).ToLower().Equals("p") || item.Key.Substring(0, item.Key.Length - countItem).ToLower().Equals("pro")) && !prolineFound) { prolineFound = true; structErrors.Add("-Found one or more prolines present on the wheel"); continue; } if ((item.Key.Length - countItem) > 2 && !invalidAminoAcid) { if (!aminoClass.IsAminoAcid(item.Key.Substring(0, item.Key.Length - countItem))) { structErrors.Add("-Your helical structure contains one or more invalid amino acid(s)."); invalidAminoAcid = true; continue; } } if ((item.Key.Length - countItem) == 1 && !invalidAminoAcid) { if (!aminoClass.IsAminoAcid(null, item.Key.ToCharArray()[0])) { structErrors.Add("-Your helical structure contains one or more invalid amino acid(s)."); invalidAminoAcid = true; continue; } } List <KeyValuePair <string, Point> > templist = aminoList.Where(x => !x.Key.Equals(item.Key)).ToList(); var closeAminos = templist.Where(x => Math.Sqrt(Math.Pow((x.Value.X - item.Value.X), 4) + Math.Pow((x.Value.Y - item.Value.Y), 2)) <= 4); List <KeyValuePair <string, string> > foundAminos = new List <KeyValuePair <string, string> >(); foreach (var item2 in closeAminos) { var countItem2 = item2.Key.ToCharArray().ToList().Where(x => char.IsDigit(x)); if (aminoClass.ContainsBulkyAminos(item.Key.Substring(0, item.Key.Length - countItem), item2.Key.Substring(0, item2.Key.Length - countItem2.Count()))) { var text = $"-{item.Key} & {item2.Key} are bulky amino acids and shouldn't be very close to each other."; KeyValuePair <string, string> keyPair1 = new KeyValuePair <string, string>(item.Key, item2.Key); KeyValuePair <string, string> keyPair2 = new KeyValuePair <string, string>(item2.Key, item.Key); if (!foundAminos.Contains(keyPair1)) { structErrors.Add(text); } foundAminos.Add(keyPair1); foundAminos.Add(keyPair2); } } } if (structErrors.Any()) { foreach (var error in structErrors) { StructureAnalysis.Text += error + "\n"; } } else { StructureAnalysis.Text = "Your helical structure looks good !"; StructureAnalysis.TextColor = Color.ForestGreen; } StructureAnalysis.IsVisible = true; Content = new ScrollView { Content = MainView }; //StructureAnalysis.HeightRequest = .40 * App.ScreenHeight; }
public void HelicalWheelBuilderLetter(string aminoAcids, SKCanvas canvas) { // init. my variables var aminoClass = new AminoAcids(); var listAminos = aminoAcids.ToCharArray().ToList(); float x = 0; float y = 0; int angle = 270; char lastChar = '0'; bool polarity = false; float xModifier = 0; float yModifier = 0; float modIncrementer = 0; float scaleModifier = 19; int incr = 1; var percentDiff = (App.ScreenHeight / ScaleFactor); // iterate over the amino acids foreach (var item in listAminos) { // if its a valid character if (char.IsLetter(item)) { // acheck to make sure to add the if (lastChar != '0') { //draw line if (incr < 18) { canvas.DrawLine(x, y, (float)((RADIUS * percentDiff) * Math.Cos(angle * Math.PI / 180F)), (float)((RADIUS * percentDiff) * Math.Sin(angle * Math.PI / 180F)), Line); } // check if polar or not then draw the circle accordingly if (polarity) { canvas.DrawText(lastChar.ToString().ToUpper() + incr, x - 6, y + 4, PolarLetters); } else { canvas.DrawText(lastChar.ToString().ToUpper() + incr, x - 6, y + 4, NonPolarLetters); } incr += 1; } // determine the x & y coordinates using this formula x = (float)((RADIUS * percentDiff) * Math.Cos(angle * Math.PI / 180F)); y = (float)((RADIUS * percentDiff) * Math.Sin(angle * Math.PI / 180F)); // add x & y coordinates to my global variable HelicalStructure.Add(new KeyValuePair <string, Point>(item.ToString().ToUpper() + incr, new Point(x, y))); if (incr % scaleModifier == 0) { modIncrementer += 1; scaleModifier = scaleModifier + 18; } xModifier = x > 0? 13f * modIncrementer : -13f * modIncrementer; yModifier = y > 0? 13f * modIncrementer : -13f * modIncrementer; if (Math.Abs(x) < 5 && modIncrementer > 0) { yModifier = yModifier > 0 ? (yModifier - .5f) + (6 * modIncrementer) : (yModifier + .5f) - (6 * modIncrementer); xModifier = 0; } x += xModifier; y += yModifier; if (aminoClass.IsAminoAcid(null, item)) { if (polarity = aminoClass.IsPolar(null, item)) { canvas.DrawCircle(x, y, (AMINORADIUS * percentDiff), PolarAminoAcid); } else { canvas.DrawCircle(x, y, (AMINORADIUS * percentDiff), NonPolarAminoAcid); } } else { canvas.DrawCircle(x, y, (AMINORADIUS * percentDiff), InvalidAminoAcid); } angle += 100; if (angle > 360) { angle -= 360; } lastChar = item; } } if (char.IsLetter(lastChar)) { if (polarity) { canvas.DrawText(lastChar.ToString().ToUpper() + incr, x - 6, y + 4, PolarLetters); } else { canvas.DrawText(lastChar.ToString().ToUpper() + incr, x - 6, y + 4, NonPolarLetters); } } }