/** * Parses the given mztab string and sets the various properties accordingly. Properties that are * already set and not defined in the passed string are not altered. The only exception to this * rule is the unit id: once the unit id was set unmarshalling properties assigned to a different * unit causes a parsing exception to be thrown. * * @param mzTabString * @throws MzTabParsingException Thrown on any parsing error. */ public void unmarshall(String mzTabString) throws MzTabParsingException { // parse the string line by line String[] lines = mzTabString.split("\r?\n"); for (String line : lines) { // ignore empty and non-metadata lines if (line.trim().length() < 1 || !"MTD".equals(line.substring(0, 3))) { continue; } // parse the line Matcher matcher = MZTAB_LINE_PATTERN.matcher(line); // throw a parsing exception if the line couldn't be parsed if (!matcher.find()) { throw new MzTabParsingException("Invalid meta-data line encountered: <" + line + ">"); } // get the various fields String theUnitId = matcher.group(2).trim(); String subId = matcher.group(3); String field = matcher.group(4); String value = matcher.group(5); TableObject.checkUnitId(theUnitId); if (subId != null) { subId = subId.trim(); } if (field != null) { field = field.trim(); } if (value != null) { value = value.trim(); } // check that the unitId didn't change - if it wasn't set yet, set it if (this.unitId == null) { this.unitId = theUnitId; } else if (!this.unitId.equals(theUnitId)) { throw new MzTabParsingException( "Metadata line passed to Unit object (id = " + this.unitId + ") with a different UNIT_ID (" + theUnitId + ")"); } // parse the field parseField(subId, field, value); } }
public void setUnitId(String unitId) throws MzTabParsingException { TableObject.checkUnitId(unitId); this.unitId = unitId; }