@Test public void testDStereochemistryDOnCarbohydratePrefix() throws ComponentGenerationException, StructureBuildingException{ Element prefix = new TokenEl(STEREOCHEMISTRY_EL); prefix.addAttribute(new Attribute(TYPE_ATR, CARBOHYDRATECONFIGURATIONPREFIX_TYPE_VAL)); prefix.addAttribute(new Attribute(VALUE_ATR, "l/r")); ComponentProcessor.applyDlStereochemistryToCarbohydrateConfigurationalPrefix(prefix, "d"); assertEquals("l/r", prefix.getAttributeValue(VALUE_ATR)); }
static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } }
ComponentProcessor { static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } } }
ComponentProcessor { static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } } ComponentProcessor(BuildState state, SuffixApplier suffixApplier); }
ComponentProcessor { static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } } ComponentProcessor(BuildState state, SuffixApplier suffixApplier);  }
ComponentProcessor { static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } } ComponentProcessor(BuildState state, SuffixApplier suffixApplier);   }