public void GETEditHappyTest() { int?id = 12; var expected = new CrossType { Id = 12, Name = "bananas" }; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(r => r.GetCrossType(id.Value)).Returns(expected); var controller = new CrossTypesController(mockRepo.Object); var response = controller.Edit(id) as ViewResult; Assert.IsNotNull(response); Assert.IsNotNull(response.Model); Assert.IsNotNull(response.Model as CrossType); var actual = response.Model as CrossType; Assert.AreEqual(expected, actual); }
public void CrossoverWeights(double[] parent1, double[] parent2, out double[] child1, out double[] child2, CrossType type) { int size = parent1.Length; child1 = new double[size]; child2 = new double[size]; switch (type) { case CrossType.ARYTM: arytmCrossover(parent1, parent2, child1, child2); break; case CrossType.ONE_POINT: onePointCrossover(parent1, parent2, child1, child2); break; case CrossType.REGULAR: regularCrossover(parent1, parent2, child1, child2); break; default: break; } }
static void Run(int ind, int ind_max, int ind_inc, int total_it, int stringlenbegin, BreedType breed, CrossType cross, string filename) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename, true)) { GenControl cont = new GenControl(breed,cross); cont.setFile(filename); float average; for (int j = ind; j <= ind_max; j += ind_inc) { average = 0; Console.WriteLine("String Length: " + j); for (int i = 0; i < total_it; i++) { var gener = cont.defaultInitString(j, stringlenbegin, stringlenbegin*2); average += gener; Console.Write(gener + " "); } average /= ((float)total_it); file.WriteLine(j + "," + average); Console.WriteLine(); Console.WriteLine("Average: " + average); Console.WriteLine(); Console.WriteLine(); } } }
public ActionResult Create([Bind(Include = "Id,Name,Value,GenusId")] CrossType crossType) { if (ModelState.IsValid) { m_repo.SaveCrossType(crossType); return(RedirectToAction("IndexByGenus", new { id = crossType.GenusId })); } return(View(crossType)); }
/// <summary> /// genetic Average value /// </summary> /// <param name="gen">another genetic</param> private static Genetic[] Cross(int[,] Gen, int[,] gen) { int pos = rand.Next(0, Width) + rand.Next(0, Height) * Width; Genetic[] result = new Genetic[2] { new Genetic(), new Genetic() }; CrossType t = Global.CrossType; if (Global.CrossType == CrossType.Random) { if (rand.NextDouble() > 0.5) { t = CrossType.Vertical; } else { t = CrossType.Horizontal; } } for (int h = 0; h < Height; h++) { for (int w = 0; w < Width; w++) { int a = h, b = w; if (t == CrossType.Vertical) { a = w; b = h; } if (h * Width + w < pos) { result[0].Gen[a, b] = Gen[a, b]; result[1].Gen[a, b] = gen[a, b]; } else { result[1].Gen[a, b] = Gen[a, b]; result[0].Gen[a, b] = gen[a, b]; } } } return(result); }
// GET: CrossTypes/Details/5 public ActionResult Details(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CrossType crossType = m_repo.GetCrossType(id.Value); if (crossType == null) { return(HttpNotFound()); } return(View(crossType)); }
public void GETDeleteNullTest() { int? id = 12; CrossType expected = null; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(r => r.GetCrossType(id.Value)).Returns(expected); var controller = new CrossTypesController(mockRepo.Object); var response = controller.Retire(null, null) as HttpStatusCodeResult; Assert.IsNotNull(response); Assert.IsTrue(response.StatusCode == 400); }
public void POSTEditHappyTest() { var crossType = new CrossType() { Id = 12, Name = "Banana" }; var mockRepo = new Mock <IPlantBreedingRepo>(); var controller = new CrossTypesController(mockRepo.Object); var response = controller.Edit(crossType) as RedirectToRouteResult; Assert.IsNotNull(response); Assert.IsNotNull(response.RouteValues); Assert.AreEqual("IndexByGenus", response.RouteValues["action"]); }
public void DetailsNullTest() { int? id = 12; CrossType expected = null; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(r => r.GetCrossType(id.Value)).Returns(expected); var controller = new CrossTypesController(mockRepo.Object); var response = controller.Details(id) as HttpNotFoundResult; Assert.IsNotNull(response); Assert.IsTrue(response.StatusCode == 404); }
public ActionResult Retire(int?id, int?genus) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CrossType crossType = m_repo.GetCrossType(id.Value); if (crossType == null) { return(HttpNotFound()); } crossType.Retired = !crossType.Retired; m_repo.SaveCrossType(crossType); return(RedirectToAction("IndexByGenus", new { id = genus })); }
public void GETDeleteHappyTest() { var expected = new CrossType() { Id = 12, Name = "Banana" }; var mockRepo = new Mock <IPlantBreedingRepo>(); var controller = new CrossTypesController(mockRepo.Object); var response1 = controller.Create(expected) as RedirectToRouteResult; controller.Retire(expected.Id, expected.Id); var response2 = controller.Details(expected.Id) as HttpNotFoundResult; Assert.IsNotNull(response1); Assert.IsNotNull(response1.RouteValues); Assert.AreEqual("IndexByGenus", response1.RouteValues["action"]); Assert.IsTrue(response2.StatusCode == 404); }
public void POSTEditWithBadSessionTest() { var crossType = new CrossType() { Id = 12, Name = "Banana" }; var mockRepo = new Mock <IPlantBreedingRepo>(); var controller = new CrossTypesController(mockRepo.Object); controller.ModelState.AddModelError("test", "play them off, keyboard cat"); var response = controller.Edit(crossType) as ViewResult; Assert.IsNotNull(response); Assert.IsNotNull(response.Model); Assert.IsNotNull(response.Model as CrossType); var actual = response.Model as CrossType; Assert.AreEqual(crossType, actual); }
public void POSTDeleteHappyCase() { int?id = 12; var crossType = new CrossType { Id = 12, Name = "bananas" }; var genus = new List <Genus> { new Genus { Id = 3, Name = "Rubus", DefaultPlantsInRep = 3, VirusLabel1 = "RBDV", VirusLabel2 = "ToRSV", VirusLabel3 = "SNSV", Retired = false, ExternalId = null, VirusLabel4 = "BCRV" } }; var mockRepo = new Mock <IPlantBreedingRepo>(); mockRepo.Setup(r => r.GetCrossType(id.Value)).Returns(crossType); mockRepo.Setup(r => r.GetAllGenera()).Returns(genus); var controller = new CrossTypesController(mockRepo.Object); var response = controller.Retire(id, 3) as RedirectToRouteResult; Assert.IsNotNull(response); Assert.IsNotNull(response.RouteValues); Assert.AreEqual("IndexByGenus", response.RouteValues["action"]); }
public GenControl(BreedType _breed, CrossType _cross) { breed = _breed; cross = _cross; targetString = Encoding.ASCII.GetBytes("THE_STRING_MATCH"); }
public void SetCrossType(CrossType cross) { switch (cross) { case CrossType.OnePoint: crossPoints = 1; break; case CrossType.TwoPoint: crossPoints = 2; break; case CrossType.Uniform: crossPoints = 5; break; } }
public override string ToString() { string position = ""; switch (CrossType) { case PsmCrossType.Single: break; case PsmCrossType.Loop: position = "(" + LinkPositions[0].ToString() + "-" + LinkPositions[1].ToString() + ")"; break; default: position = "(" + LinkPositions[0].ToString() + ")"; break; } var sb = new StringBuilder(); sb.Append(FullFilePath + "\t"); sb.Append(ScanNumber + "\t"); sb.Append(PrecursorScanNumber + "\t"); sb.Append(ScanPrecursorMonoisotopicPeakMz + "\t"); sb.Append(ScanPrecursorCharge + "\t"); sb.Append(ScanPrecursorMass + "\t"); sb.Append(CrossType.ToString() + "\t"); if (LinkPositions != null) { if (CrossType == PsmCrossType.Loop) { sb.Append(BaseSequence[LinkPositions[0] - 1] + ";" + BaseSequence[LinkPositions[1] - 1] + "\t"); } else if (CrossType == PsmCrossType.Inter || CrossType == PsmCrossType.Intra) { sb.Append(BaseSequence[LinkPositions[0] - 1] + ";" + BetaPeptide.BaseSequence[BetaPeptide.LinkPositions[0] - 1] + "\t"); } else { // deadend sb.Append(BaseSequence[LinkPositions[0] - 1] + "\t"); } } else { sb.Append("\t"); } sb.Append("\t"); List <PeptideWithSetModifications> pepsWithMods = BestMatchingPeptides.Select(p => p.Peptide).ToList(); var proteinAccessionString = ProteinAccession != null ? ProteinAccession : PsmTsvWriter.Resolve(pepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; sb.Append(proteinAccessionString + "\t"); sb.Append(XlProteinPos + (XlProteinPosLoop.HasValue? "~" + XlProteinPosLoop.Value : null) + "\t"); sb.Append(BaseSequence + "\t"); sb.Append(FullSequence + position + "\t"); sb.Append((PeptideMonisotopicMass.HasValue ? PeptideMonisotopicMass.Value.ToString() : "---")); sb.Append("\t"); sb.Append(Score + "\t"); sb.Append(XlRank[0] + "\t"); if (ChildMatchedFragmentIons == null) { foreach (var mid in MatchedIonDataDictionary(this.MatchedFragmentIons)) { sb.Append(mid.Value); sb.Append("\t"); } } else { StringBuilder[] scanFragmentStringbuilder = new StringBuilder[6]; int i = 0; foreach (var mid in MatchedIonDataDictionary(this.MatchedFragmentIons)) { scanFragmentStringbuilder[i] = new StringBuilder(); scanFragmentStringbuilder[i].Append("{" + ScanNumber + "@" + mid.Value + "}"); i++; } foreach (var childScan in ChildMatchedFragmentIons) { int j = 0; int oneBasedScan = childScan.Key; foreach (var mid in MatchedIonDataDictionary(childScan.Value)) { scanFragmentStringbuilder[j].Append("{" + oneBasedScan + "@" + mid.Value + "}"); j++; } } foreach (var s in scanFragmentStringbuilder) { sb.Append(s.ToString() + "\t"); } } if (BetaPeptide != null) { sb.Append("\t"); List <PeptideWithSetModifications> betaPepsWithMods = BetaPeptide.BestMatchingPeptides.Select(p => p.Peptide).ToList(); var betaProteinAccessionString = BetaPeptide.ProteinAccession != null ? BetaPeptide.ProteinAccession : PsmTsvWriter.Resolve(betaPepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; sb.Append(betaProteinAccessionString + "\t"); sb.Append(BetaPeptide.XlProteinPos + "\t"); sb.Append(BetaPeptide.BaseSequence + "\t"); sb.Append(BetaPeptide.FullSequence + "(" + BetaPeptide.LinkPositions[0].ToString() + ")" + "\t"); sb.Append(BetaPeptide.PeptideMonisotopicMass.ToString() + "\t"); sb.Append(BetaPeptide.Score + "\t"); sb.Append(XlRank[1] + "\t"); if (BetaPeptide.ChildMatchedFragmentIons == null) { foreach (var betamid in MatchedIonDataDictionary(this.BetaPeptide.MatchedFragmentIons)) { sb.Append(betamid.Value); sb.Append("\t"); } } else { StringBuilder[] scanFragmentStringbuilder = new StringBuilder[6]; int i = 0; foreach (var betamid in MatchedIonDataDictionary(this.BetaPeptide.MatchedFragmentIons)) { scanFragmentStringbuilder[i] = new StringBuilder(); scanFragmentStringbuilder[i].Append("{" + ScanNumber + "@" + betamid.Value + "}"); i++; } foreach (var betaChildScan in BetaPeptide.ChildMatchedFragmentIons) { int j = 0; int betaOneBasedScan = betaChildScan.Key; foreach (var betamid in MatchedIonDataDictionary(betaChildScan.Value)) { scanFragmentStringbuilder[j].Append("{" + betaOneBasedScan + "@" + betamid.Value + "}"); j++; } } foreach (var s in scanFragmentStringbuilder) { sb.Append(s.ToString() + "\t"); } } sb.Append("\t"); sb.Append(XLTotalScore + "\t"); // mass of crosslinker sb.Append(((PeptideMonisotopicMass.HasValue) ? (ScanPrecursorMass - BetaPeptide.PeptideMonisotopicMass - PeptideMonisotopicMass.Value).ToString() : "---")); sb.Append("\t"); int alphaNumParentIons = MatchedFragmentIons.Count(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M); int betaNumParentIons = BetaPeptide.MatchedFragmentIons.Count(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M); sb.Append(alphaNumParentIons + ";" + betaNumParentIons + "\t"); sb.Append(alphaNumParentIons + betaNumParentIons + "\t"); sb.Append(((ParentIonMaxIntensityRanks != null) && (ParentIonMaxIntensityRanks.Any()) ? ParentIonMaxIntensityRanks.Min().ToString() : "-")); sb.Append("\t"); } if (BetaPeptide == null) { sb.Append((IsDecoy) ? "D" : (IsContaminant) ? "C" : "T"); sb.Append("\t"); } else { sb.Append((IsDecoy || BetaPeptide.IsDecoy) ? "D" : (IsContaminant || BetaPeptide.IsContaminant) ? "C" : "T"); sb.Append("\t"); } sb.Append(FdrInfo.QValue.ToString()); sb.Append("\t"); return(sb.ToString()); }
public void CrossoverCars(CarSimpleData p1, CarSimpleData p2, out CarSimpleData c1, out CarSimpleData c2, CrossType type) { c1 = new CarSimpleData(); c2 = new CarSimpleData(); double [] c1w; double [] c2w; CrossoverWeights(p1.Weights, p2.Weights, out c1w, out c2w, type); c1.Weights = c1w; c2.Weights = c2w; float newSensorLength = CrossoverFloats(p1.SensorsLength, (float)p1.Fitness, p2.SensorsLength, (float)p2.Fitness); float newAngleBetweenSensors = CrossoverFloats(p1.AngleBetweenSensors, (float)p1.Fitness, p2.AngleBetweenSensors, (float)p2.Fitness); c1.SensorsLength = newSensorLength; c2.SensorsLength = newSensorLength; c1.AngleBetweenSensors = newAngleBetweenSensors; c2.AngleBetweenSensors = newAngleBetweenSensors; }
public override string ToString() { string position = ""; switch (CrossType) { case PsmCrossType.Single: break; case PsmCrossType.Loop: position = "(" + LinkPositions[0].ToString() + "-" + LinkPositions[1].ToString() + ")"; break; default: position = "(" + LinkPositions[0].ToString() + ")"; break; } var sb = new StringBuilder(); sb.Append(FullFilePath + "\t"); sb.Append(ScanNumber + "\t"); sb.Append(PrecursorScanNumber + "\t"); sb.Append(ScanPrecursorMonoisotopicPeakMz + "\t"); sb.Append(ScanPrecursorCharge + "\t"); sb.Append(ScanPrecursorMass + "\t"); sb.Append(CrossType.ToString() + "\t"); if (LinkPositions != null) { if (CrossType == PsmCrossType.Loop) { sb.Append(BaseSequence[LinkPositions[0] - 1] + ";" + BaseSequence[LinkPositions[1] - 1] + "\t"); } else if (CrossType == PsmCrossType.Inter || CrossType == PsmCrossType.Intra) { sb.Append(BaseSequence[LinkPositions[0] - 1] + ";" + BetaPeptide.BaseSequence[BetaPeptide.LinkPositions[0] - 1] + "\t"); } else { // deadend sb.Append(BaseSequence[LinkPositions[0] - 1] + "\t"); } } else { sb.Append("\t"); } sb.Append("\t"); sb.Append(ProteinAccession + "\t"); sb.Append(XlProteinPos + "\t"); sb.Append(BaseSequence + "\t"); sb.Append(FullSequence + position + "\t"); sb.Append((PeptideMonisotopicMass.HasValue ? PeptideMonisotopicMass.Value.ToString() : "---")); sb.Append("\t"); sb.Append(Score + "\t"); sb.Append(XlRank[0] + "\t"); foreach (var mid in MatchedIonDataDictionary(this.MatchedFragmentIons)) { sb.Append(mid.Value); sb.Append("\t"); } StringBuilder childScanFragmentStringbuilder = new StringBuilder(); if (ChildMatchedFragmentIons != null) { foreach (var childScan in ChildMatchedFragmentIons) { int oneBasedScan = childScan.Key; var matchedIonsDict = MatchedIonDataDictionary(childScan.Value); childScanFragmentStringbuilder.Append("{" + oneBasedScan + "|" + matchedIonsDict[PsmTsvHeader.MatchedIonMzRatios] + "}"); } } sb.Append(childScanFragmentStringbuilder.ToString() + "\t"); if (BetaPeptide != null) { sb.Append("\t"); sb.Append(BetaPeptide.ProteinAccession + "\t"); sb.Append(BetaPeptide.XlProteinPos + "\t"); sb.Append(BetaPeptide.BaseSequence + "\t"); sb.Append(BetaPeptide.FullSequence + "(" + BetaPeptide.LinkPositions[0].ToString() + ")" + "\t"); sb.Append(BetaPeptide.PeptideMonisotopicMass.ToString() + "\t"); sb.Append(BetaPeptide.Score + "\t"); sb.Append(XlRank[1] + "\t"); foreach (var betamid in MatchedIonDataDictionary(this.BetaPeptide.MatchedFragmentIons)) { sb.Append(betamid.Value); sb.Append("\t"); } StringBuilder childScanFragmentStringbuilderBeta = new StringBuilder(); if (BetaPeptide.ChildMatchedFragmentIons != null) { foreach (var childScan in BetaPeptide.ChildMatchedFragmentIons) { int oneBasedScan = childScan.Key; var matchedIonsDict = MatchedIonDataDictionary(childScan.Value); childScanFragmentStringbuilderBeta.Append("{" + oneBasedScan + "|" + matchedIonsDict[PsmTsvHeader.MatchedIonMzRatios] + "}"); } } sb.Append(childScanFragmentStringbuilderBeta.ToString() + "\t"); sb.Append("\t"); sb.Append(XLTotalScore + "\t"); // mass of crosslinker sb.Append(((PeptideMonisotopicMass.HasValue) ? (ScanPrecursorMass - BetaPeptide.PeptideMonisotopicMass - PeptideMonisotopicMass.Value).ToString() : "---")); sb.Append("\t"); int alphaNumParentIons = MatchedFragmentIons.Count(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M); int betaNumParentIons = BetaPeptide.MatchedFragmentIons.Count(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M); sb.Append(alphaNumParentIons + ";" + betaNumParentIons + "\t"); sb.Append(alphaNumParentIons + betaNumParentIons + "\t"); sb.Append(((ParentIonMaxIntensityRanks != null) && (ParentIonMaxIntensityRanks.Any()) ? ParentIonMaxIntensityRanks.Min().ToString() : "-")); sb.Append("\t"); } if (BetaPeptide == null) { sb.Append((IsDecoy) ? "D" : (IsContaminant) ? "C" : "T"); sb.Append("\t"); } else { sb.Append((IsDecoy || BetaPeptide.IsDecoy) ? "D" : (IsContaminant || BetaPeptide.IsContaminant) ? "C" : "T"); sb.Append("\t"); } sb.Append(FdrInfo.QValue.ToString()); sb.Append("\t"); return(sb.ToString()); }