public IActionResult Get(int id) { SortingScheme sortingScheme = _context.SortingScheme.FirstOrDefault(x => x.SchemeID == id); if (sortingScheme == null) { return(NotFound()); } return(new ObjectResult(sortingScheme)); }
public IActionResult Post([FromBody] SortingScheme sortingScheme) { if (sortingScheme == null) { return(BadRequest()); } _context.SortingScheme.Add(sortingScheme); _context.SaveChanges(); return(Ok(sortingScheme)); }
private static double getValue(Peptide p, SortingScheme s) { switch (s) { case SortingScheme.MASS: return(ARBITRARILY_LARGE_MASS - p.getMass()); case SortingScheme.RT_START: return(p.getRetentionTime().getRetentionTimePeak()); case SortingScheme.RT_END: return(p.getRetentionTime().getRetentionTimePeak()); default: return(Double.NaN); } }
/* * A recursive implementation of binary search Returns the index of a peptide * within the mass tolerance of the query mass */ private static int findPosition(List <Peptide> list, Peptide p, SortingScheme s, int high, int low) { // Not found if (high < low) { return(-1); } // Search peptide at the middle of the list int mid = (high + low) / 2; Peptide midPep = list[mid]; double midValue = getValue(midPep, s); double targetValue = getValue(p, s); if (midPep == p) { return(mid); } else { if (midValue > targetValue) { // Search the bottom half of the list return(findPosition(list, p, s, mid - 1, low)); } else if (midValue < targetValue) { // Search the top half of the list return(findPosition(list, p, s, high, mid + 1)); } else { return(-1); } } }
/* * input: List<Peptide> list which is a list of peptides you want to * search, Peptide p the peptide you are looking for, SortingScheme s how the * original list is sorted by to find where Peptide p belongs output: the index * of peptide p or -1 if not found */ public static int findPosition(List <Peptide> list, Peptide p, SortingScheme s) { return(findPosition(list, p, s, list.Count - 1, 0)); }
/* * A recursive implementation of binary search Returns the index of a peptide * within the mass tolerance of the query mass */ private static int findPositionToAdd(List <Peptide> list, Peptide p, SortingScheme s, int high, int low) { // System.out.println(p); // System.out.println(s); // System.out.println("hi: " + high + "\tlo: " + low); // System.out.println(list.Count); // // if (list.Count > 1 && s.Equals(SortingScheme.MASS)) { // System.out.println("asdf"); // System.out.println(getValue(p, s)); // } // // Not found double targetValue = getValue(p, s); if (high <= low) { if (list.Count == 0) { return(0); } if (targetValue > getValue(list[low], s)) { return(low + 1); } else { return(low); } } // Search peptide at the middle of the list int mid = (high + low) / 2; Peptide midPep = list[mid]; double midValue = getValue(midPep, s); // System.out.println("mid: " + midValue + "\ttarget: " + targetValue); ////commented this out because this should already be checked in a previous step //if (midPep == p) //{ // // prevents adding the same peptide to the list // return -1; //} //else //{ //} if (midValue > targetValue) { // Search the bottom half of the list return(findPositionToAdd(list, p, s, mid - 1, low)); } else if (midValue < targetValue) { // Search the top half of the list return(findPositionToAdd(list, p, s, high, mid + 1)); } else { return(mid); // if RT, needs a tie breaker... // TODO this is a problem if RToffset is too high or too low, so we need to // check the peak value instead } }