package DataLoader; //----------------------------------------------------------------------------------------------- import java.io.*; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.*; import java.util.regex.*; import java.util.List; import java.util.Vector; import java.util.Hashtable; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.text.DecimalFormat; import org.iso_relax.verifier.*; //----------------------------------------------------------------------------------------------- public class DataSaverPanel extends WizardPanel implements ActionListener{ //----------------------------------------------------------------------------------------------- protected JTextField baseFileName; protected JTextField directoryPath; protected JCheckBox fileCheck; protected JCheckBox sbeamsCheck; protected JButton fileButton; protected JButton okbutton; protected JButton cancelButton; protected JLabel nameLabel; private String CHOOSE_DIRECTORY = "CHOOSE_DIRECTORY"; private String DIRECTORY_CHECK = "DIRECTORY_CHECK"; private static DecimalFormat twoDigits = new DecimalFormat("00"); private StringBuffer status; private Hashtable condData; //----------------------------------------------------------------------------------------------- public DataSaverPanel(WizardContext wc) { setWizardContext(wc); condData = (Hashtable)wizardContext.getAttribute(WIZARD_HASH_CONDITIONS); setLayout(new BorderLayout()); setBorder(new TitledBorder("Step 5. Save Data and Exit")); status = new StringBuffer(); JPanel instructionPanel = new JPanel(); instructionPanel.add(new JLabel("Method(s) for Saving These Data:")); JPanel filePanel = new JPanel(); fileCheck = new JCheckBox("Save To Directory"); fileCheck.setActionCommand(DIRECTORY_CHECK); fileCheck.addActionListener(this); filePanel.add(fileCheck); directoryPath = new JTextField(30); directoryPath.setEditable(false); filePanel.add(directoryPath); fileButton = new JButton ("Choose Directory..."); fileButton.setActionCommand(CHOOSE_DIRECTORY); fileButton.addActionListener(this); filePanel.add(fileButton); // JPanel sbeamsPanel = new JPanel(); // sbeamsCheck = new JCheckBox("Save to SBEAMS"); // sbeamsPanel.add(sbeamsCheck); // sbeamsPanel.setPreferredSize(filePanel.getPreferredSize()); JPanel savePanel = new JPanel(); savePanel.setLayout(new GridLayout(0,1)); savePanel.add(instructionPanel); savePanel.add(filePanel); // savePanel.add(sbeamsPanel); JPanel outerPanel = new JPanel(); outerPanel.add(savePanel); this.add(outerPanel, BorderLayout.CENTER); }// constructor //----------------------------------------------------------------------------------------------- private void writeFiles(String baseName) { Calendar calendar = new GregorianCalendar(); Date trialTime = new Date(); calendar.setTime(trialTime); String date = new String(calendar.get(Calendar.YEAR)+"-"+ twoDigits.format( (calendar.get(calendar.MONTH)+1) )+"-"+ twoDigits.format( (calendar.get(calendar.DATE)) ) ); Hashtable aliases = new Hashtable(); String lambdaFile = baseName+".lambda"; String ratioFile = baseName+".ratio"; String xmlFile = baseName+".xml"; String[] conditions = (String[])wizardContext.getAttribute(WIZARD_CONDITIONS); int conds = conditions.length; ExperimentCondition ec = (ExperimentCondition)condData.get(conditions[0]); String[] gene = ec.getGenes(); float[] individualRatios = ec.getRatioData(); float[] individualLambdas = ec.getLambdaData(); StringBuffer predicateBuf = new StringBuffer(); StringBuffer constantsBuf = new StringBuffer(); StringBuffer variablesBuf = new StringBuffer(); String exptName =(String)wizardContext.getAttribute(WIZARD_EXPERIMENT); predicateBuf.append(""+"\n"); predicateBuf.append(""+"\n"); predicateBuf.append ("\t"); predicateBuf.append(""+"\n"); predicateBuf.append ("\t"); predicateBuf.append("\n"); predicateBuf.append ("\t"); predicateBuf.append(""+"\n"); String manipulationType = (String)wizardContext.getAttribute(WIZARD_MANIPULATION_TYPE); if (manipulationType != null) { predicateBuf.append ("\t"); predicateBuf.append(""+"\n"); } String manipulatedVariable = (String)wizardContext.getAttribute(WIZARD_MANIPULATED_VARIABLE); if (manipulatedVariable != null) { predicateBuf.append("\t"); predicateBuf.append(""+"\n"); } predicateBuf.append("\t"); predicateBuf.append(""+"\n"); predicateBuf.append("\t\t"+""); // predicateBuf.append("httpIndirect://db.systemsbiology.net:8080/halo/DataFetcher.py/"); predicateBuf.append(exptName); predicateBuf.append(".ratio"+"\n"); predicateBuf.append("\t"+"\n"); predicateBuf.append("\t"); predicateBuf.append(""+"\n"); predicateBuf.append("\t\t"+""); // predicateBuf.append("httpIndirect://db.systemsbiology.net:8080/halo/DataFetcher.py/"); predicateBuf.append(exptName); predicateBuf.append(".lambda"+"\n"); predicateBuf.append("\t"+"\n"); Vector constants = (Vector)wizardContext.getAttribute(WIZARD_CONSTANTS); predicateBuf.append("\t\n"); for (int m=0;m\n"); for (int m=0;m"+"\n"); for (int h=0;h"+"\n"); } variablesBuf.append(""+"\n"); // Write XML TextWriter xmlWriter = new TextWriter(xmlFile); xmlWriter.write(predicateBuf.toString()); xmlWriter.write(constantsBuf.toString()); xmlWriter.write(variablesBuf.toString()); xmlWriter.close(); try{ VerifierFactory factory = new com.sun.msv.verifier.jarv.TheFactoryImpl(); Schema schema = factory.compileSchema("http://db/sbeams/tmp/Microarray/dataLoader/experiment.xsd"); Verifier verifier = schema.newVerifier(); if( verifier.verify(xmlFile) ) status.append("Document is valid\n"); else status.append("Document is NOT valid.\nPlease report this to mjohnson@systemsbiology.org\n"); }catch (Exception e) { e.printStackTrace(); status.append("Document is NOT valid.\nPlease report this to mjohnson@systemsbiology.org\n"); } TextWriter lambdaWriter = new TextWriter(lambdaFile); TextWriter ratioWriter = new TextWriter(ratioFile); StringBuffer lambdaBuffer = new StringBuffer(); StringBuffer ratioBuffer = new StringBuffer(); float[][] ratioData = new float[conds][individualRatios.length]; float[][] lambdaData = new float[conds][individualLambdas.length]; ratioData[0] = individualRatios; lambdaData[0] = individualLambdas; for (int m=0;m