/* Copyright (c) 2009 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.. */ /* * digestMultiple.java * * Created on Aug 7, 2010, 4:20:42 PM */ package org.clothocad.tool.bglbrickdigester; import java.awt.Font; import java.util.ArrayList; import java.util.HashMap; import java.util.prefs.Preferences; import java.util.regex.Pattern; import javax.swing.AbstractListModel; import javax.swing.JOptionPane; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import org.clothocore.api.core.Collector; import org.clothocore.api.data.Collection; import org.clothocore.api.data.ObjBase; import org.clothocore.api.data.ObjLink; import org.clothocore.api.data.ObjType; import org.clothocore.api.data.Plasmid; import org.clothocore.api.dnd.ObjBaseObserver; import org.clothocore.api.dnd.RefreshEvent; import org.clothocore.util.basic.ObjBasePopup; /** * * @author J. Christopher Anderson */ public class digestMultiple extends javax.swing.JFrame { /** Creates new form digestMultiple */ public digestMultiple(Collection coll) { super("BglBrick Digest: " + coll.getName()); _coll = coll; _prefs = Preferences.userNodeForPackage(digestMultiple.class); initComponents(); leftyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); rightyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); setVisible(true); ObjBaseObserver obr = new ObjBaseObserver() { @Override public void update(ObjBase passed, RefreshEvent evt) { if(passed==null) { dispose(); } final ArrayList<Plasmid> links = (ArrayList<Plasmid>) _coll.getAll(ObjType.PLASMID); AbstractListModel model = new AbstractListModel() { @Override public int getSize() { return links.size(); } @Override public Object getElementAt(int i) { return links.toArray()[i]; } }; leftyList.setModel(model); rightyList.setModel(model); } }; xhoi.setSelected(true); reportArea.setFont(reportFont); _coll.isRepresentedBy(obr, getContentPane()); new ObjBasePopup(getContentPane(), _coll); obr.update(_coll, null); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); leftyPanel = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); leftyList = new javax.swing.JList(); jScrollPane1 = new javax.swing.JScrollPane(); reportArea = new javax.swing.JTextArea(); clearButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); AddButton = new javax.swing.JButton(); xhoi = new javax.swing.JRadioButton(); alwni = new javax.swing.JRadioButton(); bgli = new javax.swing.JRadioButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); rightyPanel = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); rightyList = new javax.swing.JList(); psti = new javax.swing.JRadioButton(); ecori = new javax.swing.JRadioButton(); defaultSetter = new javax.swing.JButton(); blankButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setResizable(false); leftyPanel.setBackground(new java.awt.Color(255, 204, 204)); leftyPanel.setLayout(new java.awt.BorderLayout()); leftyList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Loading..." }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane2.setViewportView(leftyList); leftyPanel.add(jScrollPane2, java.awt.BorderLayout.CENTER); reportArea.setColumns(20); reportArea.setRows(5); jScrollPane1.setViewportView(reportArea); clearButton.setText("Clear All"); clearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); AddButton.setText("Add"); AddButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AddButtonActionPerformed(evt); } }); buttonGroup1.add(xhoi); xhoi.setText("XhoI"); buttonGroup1.add(alwni); alwni.setText("AlwNI"); buttonGroup1.add(bgli); bgli.setText("BglI"); jLabel1.setText("Lefty Plasmid"); jLabel2.setText("Righty Plasmid"); rightyPanel.setBackground(new java.awt.Color(255, 204, 204)); rightyPanel.setLayout(new java.awt.BorderLayout()); rightyList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Loading..." }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane3.setViewportView(rightyList); rightyPanel.add(jScrollPane3, java.awt.BorderLayout.CENTER); buttonGroup1.add(psti); psti.setText("PstI"); ecori.setText("EcoRI"); defaultSetter.setText("Default"); defaultSetter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { defaultSetterActionPerformed(evt); } }); blankButton.setText("Blank"); blankButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { blankButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(defaultSetter) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(blankButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 132, Short.MAX_VALUE) .addComponent(clearButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(xhoi) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(ecori) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(alwni) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(bgli) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(psti) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE) .addComponent(AddButton)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(leftyPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(13, 13, 13) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(rightyPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(11, 11, 11) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(leftyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE) .addComponent(rightyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(AddButton) .addComponent(xhoi) .addComponent(psti) .addComponent(bgli) .addComponent(alwni) .addComponent(ecori)) .addGap(9, 9, 9) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clearButton) .addComponent(cancelButton) .addComponent(defaultSetter) .addComponent(blankButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed dispose(); }//GEN-LAST:event_cancelButtonActionPerformed private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed reportArea.setText(""); }//GEN-LAST:event_clearButtonActionPerformed private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed Plasmid lplas = (Plasmid) leftyList.getSelectedValue(); Plasmid rplas = (Plasmid) rightyList.getSelectedValue(); if(lplas==null || rplas==null) { return; } String secondEnzyme = ""; if(psti.isSelected()) { secondEnzyme = "PstI"; } else if(alwni.isSelected()) { secondEnzyme = "AlwNI"; } else if(bgli.isSelected()) { secondEnzyme = "BglI"; } else if(xhoi.isSelected()) { secondEnzyme = "XhoI"; } else if(ecori.isSelected()) { secondEnzyme = "EcoRI"; } runDigest(new digItem(lplas, "BamHI", secondEnzyme)); runDigest(new digItem(rplas, "BglII", secondEnzyme)); }//GEN-LAST:event_AddButtonActionPerformed private void blankButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blankButtonActionPerformed connect._connect.launch(new Collection()); }//GEN-LAST:event_blankButtonActionPerformed private void defaultSetterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultSetterActionPerformed //Throw up a dialog and get user to select the collection stored as 'chosen' ArrayList<ObjLink> allColl = Collector.getAllLinksOf(ObjType.COLLECTION); Object[] allNames = allColl.toArray(); ObjLink link = (ObjLink) JOptionPane.showInputDialog(null, "Choose one", "Collection", JOptionPane.INFORMATION_MESSAGE, null, allNames, allNames[0]); if(link!=null) { Collection chosen = Collector.getCollection(link.uuid); _prefs.put("DefaultCollection", chosen.getUUID()); } }//GEN-LAST:event_defaultSetterActionPerformed public void runDigest(final digItem item) { String rawseq = item.plasmid.getSeq().getSeq(); String first8 = rawseq.substring(0,8); String seq = rawseq + first8; String enz1seq = enzyToSeq.get(item.enzyme1); String enz2seq = enzyToSeq.get(item.enzyme2); if(enz1seq==null || enz2seq==null || seq==null) { return; } //Figure out where the cuts are String errorMsg=""; Pattern p = Pattern.compile(enz1seq); String[] result = p.split(seq); if(result.length==0) { errorMsg += item.enzyme1 + " doesn't cut\t"; } if(result.length>2) { errorMsg += item.enzyme1 + " has multiple cuts\t"; } int firstIndex = result[0].length(); p = Pattern.compile(enz2seq); result = p.split(seq); if(result.length==0) { errorMsg += item.enzyme2 + " doesn't cut\t"; } if(result.length>2) { errorMsg += item.enzyme2 + " has multiple cuts\t"; } int secondIndex = result[0].length(); if(!errorMsg.equals("")) { //Put a line in the report final String err = errorMsg; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { reportArea.append(item.plasmid.getName()); reportArea.append("\t" + item.enzyme1); reportArea.append("/" + item.enzyme2); reportArea.append("\t" + err); reportArea.append("\n" ); } }); return; } firstIndex += enzyToOffset.get(item.enzyme1); secondIndex += enzyToOffset.get(item.enzyme2); final int frag1 = Math.abs(secondIndex - firstIndex); System.out.println(frag1); final int frag2 = rawseq.length() - frag1; System.out.println(frag2); //Put a line in the report SwingUtilities.invokeLater(new Runnable() { @Override public void run() { reportArea.append(item.plasmid.getName()); reportArea.append("\t" + item.enzyme1); reportArea.append("/" + item.enzyme2); reportArea.append("\t" + frag1); reportArea.append("+" + frag2); reportArea.append("\tKeep:"); reportArea.append("\t" + frag2); reportArea.append("\n" ); } }); } public class digItem { public digItem(Plasmid p, String e1, String e2) { plasmid = p; enzyme1 = e1; enzyme2 = e2; } public Plasmid plasmid; public String enzyme1; public String enzyme2; } /**----------------- variables -----------------*/ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton AddButton; private javax.swing.JRadioButton alwni; private javax.swing.JRadioButton bgli; private javax.swing.JButton blankButton; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton cancelButton; private javax.swing.JButton clearButton; private javax.swing.JButton defaultSetter; private javax.swing.JRadioButton ecori; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JList leftyList; private javax.swing.JPanel leftyPanel; private javax.swing.JRadioButton psti; private javax.swing.JTextArea reportArea; private javax.swing.JList rightyList; private javax.swing.JPanel rightyPanel; private javax.swing.JRadioButton xhoi; // End of variables declaration//GEN-END:variables private Collection _coll; private ArrayList<digItem> digestions = new ArrayList<digItem>(); private static Font reportFont = new java.awt.Font("Courier New", Font.PLAIN, 10); private static HashMap<String, String> enzyToSeq = new HashMap<String, String>(); private static HashMap<String, Integer> enzyToOffset = new HashMap<String, Integer>(); static Preferences _prefs; //prefs static { enzyToSeq.put("BamHI", "GGATCC"); enzyToSeq.put("BglII", "AGATCT"); enzyToSeq.put("EcoRI", "GAATTC"); enzyToSeq.put("XhoI", "CTCGAG"); enzyToSeq.put("AlwNI", "CAG...CTG"); enzyToSeq.put("BglI", "GCC.....GGC"); enzyToSeq.put("PstI", "CTGCAG"); enzyToOffset.put("BamHI", 1); enzyToOffset.put("BglII", 1); enzyToOffset.put("EcoRI", 1); enzyToOffset.put("XhoI", 1); enzyToOffset.put("AlwNI", 6); enzyToOffset.put("BglI", 7); enzyToOffset.put("PstI", 1); } }