Search in sources :

Example 1 with ReactionCanvasDisplaySpec

use of cbit.vcell.model.ReactionCanvasDisplaySpec in project vcell by virtualcell.

the class ITextWriter method writeReactions.

// each reaction has its own table, ordered by the structures.
protected void writeReactions(Chapter physioChapter, Model model) throws DocumentException {
    if (model == null) {
        return;
    }
    Paragraph reactionParagraph = new Paragraph();
    reactionParagraph.add(new Chunk("Structures and Reactions Diagram").setLocalDestination(model.getName()));
    Section reactionDiagramSection = physioChapter.addSection(reactionParagraph, physioChapter.numberDepth() + 1);
    try {
        addImage(reactionDiagramSection, encodeJPEG(generateDocReactionsImage(model, null)));
    } catch (Exception e) {
        e.printStackTrace();
        throw new DocumentException(e.getClass().getName() + ": " + e.getMessage());
    }
    for (int i = 0; i < model.getNumStructures(); i++) {
        ReactionStep[] reactionSteps = model.getReactionSteps();
        ReactionStep rs = null;
        Table modifierTable = null;
        Table reactionTable = null;
        boolean firstTime = true;
        Section reactStructSection = null;
        for (int j = 0; j < reactionSteps.length; j++) {
            if (reactionSteps[j].getStructure() == model.getStructure(i)) {
                // can also use structureName1.equals(structureName2)
                if (firstTime) {
                    Paragraph linkParagraph = new Paragraph();
                    linkParagraph.add(new Chunk("Reaction(s) in " + model.getStructure(i).getName()).setLocalDestination(model.getStructure(i).getName()));
                    reactStructSection = physioChapter.addSection(linkParagraph, physioChapter.numberDepth() + 1);
                    firstTime = false;
                }
                rs = reactionSteps[j];
                String type;
                if (rs instanceof SimpleReaction) {
                    type = "Reaction";
                } else {
                    type = "Flux";
                }
                // write Reaction equation as a table
                // Get the image arrow cell depending on type of reactionStep : MassAction => double arrow, otherwise, forward arrow
                boolean bReversible = false;
                if (rs.getKinetics() instanceof MassActionKinetics) {
                    bReversible = true;
                }
                Cell arrowImageCell = getReactionArrowImageCell(bReversible);
                // Get reactants and products strings
                ReactionCanvas rc = new ReactionCanvas();
                rc.setReactionStep(rs);
                ReactionCanvasDisplaySpec rcdSpec = rc.getReactionCanvasDisplaySpec();
                String reactants = rcdSpec.getLeftText();
                String products = rcdSpec.getRightText();
                // Create table and add cells for reactants, arrow(s) images, products
                int[] widths = { 8, 1, 8 };
                reactionTable = getTable(3, 100, 0, 2, 2);
                // Add reactants as cell
                Cell tableCell = createCell(reactants, getBold());
                tableCell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
                tableCell.setBorderColor(Color.white);
                reactionTable.addCell(tableCell);
                // add arrow(s) image as cell
                if (arrowImageCell != null) {
                    arrowImageCell.setHorizontalAlignment(Cell.ALIGN_CENTER);
                    arrowImageCell.setBorderColor(Color.white);
                    reactionTable.addCell(arrowImageCell);
                }
                // add products as cell
                tableCell = createCell(products, getBold());
                tableCell.setBorderColor(Color.white);
                reactionTable.addCell(tableCell);
                // reactionTable.setBorderColor(Color.white);
                reactionTable.setWidths(widths);
                // Identify modifiers,
                ReactionParticipant[] rpArr = rs.getReactionParticipants();
                Vector<ReactionParticipant> modifiersVector = new Vector<ReactionParticipant>();
                for (int k = 0; k < rpArr.length; k += 1) {
                    if (rpArr[k] instanceof Catalyst) {
                        modifiersVector.add(rpArr[k]);
                    }
                }
                // Write the modifiers in a separate table, if present
                if (modifiersVector.size() > 0) {
                    modifierTable = getTable(1, 50, 0, 1, 1);
                    modifierTable.addCell(createCell("Modifiers List", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
                    StringBuffer modifierNames = new StringBuffer();
                    for (int k = 0; k < modifiersVector.size(); k++) {
                        modifierNames.append(((Catalyst) modifiersVector.elementAt(k)).getName() + "\n");
                    }
                    modifierTable.addCell(createCell(modifierNames.toString().trim(), getFont()));
                    modifiersVector.removeAllElements();
                }
                Section reactionSection = reactStructSection.addSection(type + " " + rs.getName(), reactStructSection.numberDepth() + 1);
                // Annotation
                VCMetaData vcMetaData = rs.getModel().getVcMetaData();
                if (vcMetaData.getFreeTextAnnotation(rs) != null) {
                    Table annotTable = getTable(1, 100, 1, 3, 3);
                    annotTable.addCell(createCell("Reaction Annotation", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
                    annotTable.addCell(createCell(vcMetaData.getFreeTextAnnotation(rs), getFont()));
                    reactionSection.add(annotTable);
                // reactionSection.add(new Paragraph("\""+rs.getAnnotation()+"\""));
                }
                // reaction table
                if (reactionTable != null) {
                    reactionSection.add(reactionTable);
                    // re-set reactionTable
                    reactionTable = null;
                }
                if (modifierTable != null) {
                    reactionSection.add(modifierTable);
                    modifierTable = null;
                }
                // Write kinetics parameters, etc. in a table
                writeKineticsParams(reactionSection, rs);
            }
        }
    }
}
Also used : Table(com.lowagie.text.Table) SimpleReaction(cbit.vcell.model.SimpleReaction) ReactionCanvasDisplaySpec(cbit.vcell.model.ReactionCanvasDisplaySpec) ReactionCanvas(cbit.vcell.model.ReactionCanvas) Chunk(com.lowagie.text.Chunk) Section(com.lowagie.text.Section) DocumentException(com.lowagie.text.DocumentException) ExpressionException(cbit.vcell.parser.ExpressionException) Paragraph(com.lowagie.text.Paragraph) VCMetaData(cbit.vcell.biomodel.meta.VCMetaData) DocumentException(com.lowagie.text.DocumentException) ReactionStep(cbit.vcell.model.ReactionStep) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Cell(com.lowagie.text.Cell) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Vector(java.util.Vector) Catalyst(cbit.vcell.model.Catalyst)

Aggregations

VCMetaData (cbit.vcell.biomodel.meta.VCMetaData)1 Catalyst (cbit.vcell.model.Catalyst)1 MassActionKinetics (cbit.vcell.model.MassActionKinetics)1 ReactionCanvas (cbit.vcell.model.ReactionCanvas)1 ReactionCanvasDisplaySpec (cbit.vcell.model.ReactionCanvasDisplaySpec)1 ReactionParticipant (cbit.vcell.model.ReactionParticipant)1 ReactionStep (cbit.vcell.model.ReactionStep)1 SimpleReaction (cbit.vcell.model.SimpleReaction)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Cell (com.lowagie.text.Cell)1 Chunk (com.lowagie.text.Chunk)1 DocumentException (com.lowagie.text.DocumentException)1 Paragraph (com.lowagie.text.Paragraph)1 Section (com.lowagie.text.Section)1 Table (com.lowagie.text.Table)1 Vector (java.util.Vector)1