/** * * C O P Y R I G H T N O T I C E * Copyright (c) 2001 by: * * The MicroArray Gene Expression Database group (MGED) * * Rosetta Inpharmatics * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * * @author $Author: rhubley $ * @version $Revision: 1.6 $ * */ package org.biomage.tools.generate_dtd; import java.util.Vector; import org.biomage.tools.generate_classes.CreateClassFile; import org.biomage.tools.generate_classes.CreateFile; import org.biomage.tools.helpers.StringOutputHelpers; import org.biomage.tools.generate_classes.XMIParseHelpers; import org.w3c.dom.*; /** * Description: * Class that is resposible for transforming the class list passed in. * Modifies the BioAssayData classes to better capture the data in XML. */ public class TransformBioAssayData implements WriteDTDFile.CreateClassTransformer { /** * Description: * Transform the BioAssayData class for producing modified DTD for its * associations and attributes. * * NOTE: The transformation modifies the list itself * * Modified 7/14/02 to change the transform so that the dimensions were * note moved (MAGE issue 11) --mm * *

* @param createFileList: the list of CreateFiles to transform. *

*/ public void transform( Vector createFileList ) throws Exception { // There are four create class files to find CreateClassFile bioAssayData = null; CreateClassFile bioDataCube = null; CreateClassFile bioDataTuples = null; CreateClassFile bioAssayDatum = null; for (int i = createFileList.size() - 1; -1 < i; i--) { CreateFile createFile = (CreateFile) createFileList.get(i); if ( "BioAssayData".equals(createFile.getClassFileName()) && CreateFile.UML_CLASS == createFile.getFileType() ) { StringOutputHelpers.writeOutput("Transform found BioAssayData class.", 3); bioAssayData = (CreateClassFile) createFile; } else if ( "BioDataCube".equals(createFile.getClassFileName()) ) { StringOutputHelpers.writeOutput("Transform found bioDataCube class.", 3); bioDataCube = (CreateClassFile) createFile; } else if ( "BioDataTuples".equals(createFile.getClassFileName()) ) { StringOutputHelpers.writeOutput("Transform found BioDataTuples class.", 3); bioDataTuples = (CreateClassFile) createFile; } else if ( "BioAssayDatum".equals(createFile.getClassFileName()) ) { StringOutputHelpers.writeOutput("Transform found BioAssayDatum class.", 3); bioAssayDatum = (CreateClassFile) createFile; createFileList.remove(i); } else if ( "HasBioAssayDatum".equals(createFile.getClassFileName()) ) { StringOutputHelpers.writeOutput("Transform found HasBioAssayDatum class.", 3); createFileList.remove(i); } } if (null == bioAssayData || null == bioDataCube || null == bioDataTuples || null == bioAssayDatum) { // throw new Exception("TransformBioAssayData.transform(): Did not find expected CreateFiles to transform."); StringOutputHelpers.writeOutput("TransformBioAssayData.transform(): Did not find expected CreateFiles to transform.", 3); return; } // Obtain and remove the dimension associations from the BioAssayData int BIOASSAY_DIM = 0; int DESIGNELEMENT_DIM = 1; int QUANTITATIONTYPE_DIM = 2; Vector assns = bioAssayData.getAssociationInfo(); // Go backwards to avoid having remove() disturb the iteration for (int i = assns.size() - 1; -1 < i; i--) { CreateFile.AssociationAttrInformation assn = (CreateFile.AssociationAttrInformation) assns.get(i); if ("BioAssayDimension".equals(assn.getOriginalType())) { assn.makeOptional(); } else if ("DesignElementDimension".equals(assn.getOriginalType())) { assn.makeOptional(); } else if ("QuantitationTypeDimension".equals(assn.getOriginalType())) { assn.makeOptional(); } } // remove the attribute, which is the data cube that is captured in these new elements Vector attrs = bioDataCube.getAttrInfo(); if ( null == attrs || 2 != attrs.size() || (!"cube".equals(((CreateFile.AttrInformation) attrs.get(0)).getName()) && !"order".equals(((CreateFile.AttrInformation) attrs.get(1)).getName()))) { throw new Exception("TransformBioAssayData.transform(): bioDataCube has unexpected attributes."); } attrs.remove(0); // Create the new classes for the Cube String comment = "Transformed class to associate whitespaced delimited data to the BioAssayDataCube"; CreateClassFile dataInternal = new CreateClassFile("DataInternal", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); comment = "Transformed class to associate external data to the BioAssayDataCube"; CreateClassFile dataExternal = new CreateClassFile("DataExternal", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); // add them to the cube comment = "Transformed class to associate white spaced delimited data to the BioAssayDataCube"; bioDataCube.addAssociation("dataInternal", "private", "dataInternal", comment, 1, 1, 1, 1, XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus comment = "Transformed class to associate external data to the BioAssayDataCube"; dataInternal.addRoleName("dataInternal", 1, XMIParseHelpers.COMPOSITE); bioDataCube.addAssociation("dataExternal", "private", "DataExternal", comment, 1, 1, 1, 1, XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus dataExternal.addRoleName("dataExternal", 1, XMIParseHelpers.COMPOSITE); // Finish off the Internal data comment = "The tab delimited data."; dataInternal.addAssociation("#PCDATA", "private", "#PCDATA", comment, 1, 1, 1, 1, XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus // Finish off the External Data comment = "The format of the external file, whitespace delimited, tab delimited, netcdf, etc..."; dataExternal.addAttribute("dataFormat", "private", "String", comment, "whitespace", true); comment = "Location for documentation on the data format"; dataExternal.addAttribute("dataFormatInfoURI", "private", "String", comment, null, false); comment = "The name and location of the file containing the external data"; dataExternal.addAttribute("filenameURI", "private", "String", comment, null, true); // Move the dimension associations out of the BioAssayData and into the Tuples assns = bioDataTuples.getAssociationInfo(); if ( null == assns || 1 != assns.size() || !"BioAssayDatum".equals(((CreateFile.AssociationAttrInformation) assns.get(0)).getOriginalType()) ) { throw new Exception("TransformBioAssayData.transform(): BioDataTuples has unexpected associations."); } assns.remove(0); // From BioAssayDatum, get the tuple associations to hand off to the new classes // Obtain and remove the dimension associations from the BioAssayData assns = bioAssayDatum.getAssociationInfo(); CreateFile.AssociationAttrInformation dims[] = new CreateFile.AssociationAttrInformation[3]; for (int i = assns.size() - 1; -1 < i; i--) { CreateFile.AssociationAttrInformation assn = (CreateFile.AssociationAttrInformation) assns.get(i); if ("BioAssay".equals(assn.getOriginalType())) { dims[BIOASSAY_DIM] = assn; } else if ("DesignElement".equals(assn.getOriginalType())) { dims[DESIGNELEMENT_DIM] = assn; } else if ("QuantitationType".equals(assn.getOriginalType())) { dims[QUANTITATIONTYPE_DIM] = assn; } } // create the new classes for the BioDataTuples comment = "Transformed container to hold a value. QuantitationType will " + "determine the type of this value."; CreateClassFile datum = new CreateClassFile("Datum", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); comment = "Value for the BioAssay, DesignElement and QuantitationType specified by the " + "parent tuple elements."; datum.addAttribute("value", "private", "any", comment, null, true); comment = "Transformed container to specify a Quantitation Type and the value for that Type."; CreateClassFile qtTuple = new CreateClassFile("QuantitationTypeTuple", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); qtTuple.addAssociation(dims[QUANTITATIONTYPE_DIM], new Integer(1), 1, 1, 1, 1, // these are bogus true, true); // these are bogus comment = "The value to associate with the Quantitation Type."; qtTuple.addAssociation("datum", "private", "Datum", comment, 1, 1, 1, 1, // these are bogus XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus datum.addRoleName("datum", 1, XMIParseHelpers.COMPOSITE); comment = "Transformed container to specify a DesignElement and QuantitationTypes for that Element."; CreateClassFile deTuple = new CreateClassFile("DesignElementTuple", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); deTuple.addAssociation(dims[DESIGNELEMENT_DIM], new Integer(1), 1, 1, 1, 1, // these are bogus true, true); // these are bogus comment = "A QuantitationType and the value associated with it"; deTuple.addAssociation("quantitationTypeTuples", "private", "QuantitationTypeTuple", comment, 1, -1, 0, 0, // these are bogus XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus qtTuple.addRoleName("quantitationTypeTuples", -1, XMIParseHelpers.COMPOSITE); comment = "Transformed container to specify a BioAssay and the Design Elements and their data for " + "that BioAssay."; CreateClassFile baTuple = new CreateClassFile("BioAssayTuple", "BioAssayData", comment, XMIParseHelpers.COMPOSITE); baTuple.addAssociation(dims[BIOASSAY_DIM], new Integer(1), 1, 1, 1, 1, true, true); // these are bogus comment = "DesignElement with the QuantitationTypes and their values for this BioAssay"; baTuple.addAssociation("designElementTuples", "private", "DesignElementTuple", comment, 1, -1, 0, 0, // these are bogus XMIParseHelpers.COMPOSITE, false, new Integer(2), false, false, true, true); // these are bogus deTuple.addRoleName("designElementTuples", -1, XMIParseHelpers.COMPOSITE); comment = "Each BioAssayTuple contains the the Data for a BioAssay."; bioDataTuples.addAssociation("bioAssayTuples", "private", "BioAssayTuple", comment, 0, -1, 0, 0, // these are bogus XMIParseHelpers.COMPOSITE, false, new Integer(4), false, false, true, true); // these are bogus baTuple.addRoleName("bioAssayTuples", -1, XMIParseHelpers.COMPOSITE); createFileList.add(dataInternal); createFileList.add(dataExternal); createFileList.add(baTuple); createFileList.add(deTuple); createFileList.add(qtTuple); createFileList.add(datum); } }