Changeset 6460


Ignore:
Timestamp:
Nov 1, 2021, 12:03:36 PM (15 months ago)
Author:
Nicklas Nordborg
Message:

References #1347: Updates to registration of specimen handled by external lab

Added support for plate coordinates in "A:1" format.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/4.33-stable/src/net/sf/basedb/reggie/plugins/cmd/PlateWellValidator.java

    r6207 r6460  
    66import net.sf.basedb.core.DbControl;
    77import net.sf.basedb.core.data.PlateCoordinate;
     8import net.sf.basedb.util.Coordinate;
    89
    910/**
    1011  Validator for plate well coordinates that are expected to
    1112  be strings in the format "row:column", where 'row' and 'column'
    12   are 1-based integer values up to a specified max number of
    13   rows/columns. If the coordinates are valid they are converted
    14   to 0-bases and returned as a PlateCoordinate instance.
     13  are either A1B1-style or 1-based integer values up to a specified
     14  max number of rows/columns. If the coordinates are valid they are
     15  converted to 0-bases and returned as a PlateCoordinate instance.
    1516 
    1617  @since 4.32
     
    3031  public static final PlateWellValidator QIACUBE = new PlateWellValidator(6, 2);
    3132
    32   private final Pattern pattern;
     33  private final Pattern a1b1Pattern;
     34  private final Pattern numericPattern;
    3335  private final int maxRows;
    3436  private final int maxCols;
     
    3638  public PlateWellValidator(int maxRows, int maxCols)
    3739  {
    38     this.pattern = Pattern.compile("(\\d+)\\:(\\d+)");
     40    this.a1b1Pattern = Pattern.compile("([A-Z]+)\\:(\\d+)");
     41    this.numericPattern = Pattern.compile("(\\d+)\\:(\\d+)");
    3942    this.maxRows = maxRows;
    4043    this.maxCols = maxCols;
     
    4447  public PlateCoordinate isValid(DbControl dc, String value, JsonSection section, String entryKey)
    4548  {
    46     Matcher m = pattern.matcher(value);
    47     if (!m.matches())
     49    Matcher mA1B1 = a1b1Pattern.matcher(value);
     50    int row;
     51    int col;
     52    boolean useA1B1;
     53    if (!mA1B1.matches())
    4854    {
    49       section.addErrorMessage("Invalid plate well in JSON: "+entryKey+"="+value);
    50       return null;
     55      Matcher mNumeric = numericPattern.matcher(value);
     56      if (!mNumeric.matches())
     57      {
     58        section.addErrorMessage("Invalid plate well in JSON: "+entryKey+"="+value);
     59        return null;
     60      }
     61      row = Integer.parseInt(mNumeric.group(1));
     62      col = Integer.parseInt(mNumeric.group(2));
     63      useA1B1 = false;
    5164    }
    52     int row = Integer.parseInt(m.group(1));
    53     int col = Integer.parseInt(m.group(2));
     65    else
     66    {
     67      row = Coordinate.alphaToNumeric(mA1B1.group(1));
     68      col = Integer.parseInt(mA1B1.group(2));
     69      useA1B1 = true;
     70    }   
     71
    5472    boolean valid = true;
    5573    if (row < 1 || row > maxRows)
    5674    {
    57       section.addErrorMessage("Row coordinate "+(row<1?"<1" : ">"+maxRows)+" in JSON: "+entryKey+"="+value);
     75      if (useA1B1)
     76      {
     77        section.addErrorMessage("Row coordinate "+(row<1?"<A" : ">"+Coordinate.numericToAlpha(maxRows))+" in JSON: "+entryKey+"="+value);
     78      }
     79      else
     80      {
     81        section.addErrorMessage("Row coordinate "+(row<1?"<1" : ">"+maxRows)+" in JSON: "+entryKey+"="+value);
     82      }
    5883      valid = false;
    5984    }
Note: See TracChangeset for help on using the changeset viewer.