Search in sources :

Example 21 with DataStore

use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.

the class ReplicateSetEditor method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
public void actionPerformed(ActionEvent ae) {
    String c = ae.getActionCommand();
    if (c.equals("add")) {
        Object[] addObjs = availableList.getSelectedValues();
        DataStore[] adds = new DataStore[addObjs.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObjs[i];
        }
        usedModel.addElements(adds);
        availableModel.removeElements(adds);
        usedList.setSelectedIndices(new int[0]);
        availableList.setSelectedIndices(new int[0]);
        DataStore[] s = usedModel.getStores();
        ReplicateSet r = (ReplicateSet) replicateSetList.getSelectedValue();
        r.setDataStores(s);
    } else if (c.equals("select_named")) {
        new NameGatherer();
    } else if (c.equals("remove")) {
        Object[] addObjs = usedList.getSelectedValues();
        DataStore[] adds = new DataStore[addObjs.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObjs[i];
        }
        usedModel.removeElements(adds);
        availableModel.addElements(adds);
        usedList.setSelectedIndices(new int[0]);
        availableList.setSelectedIndices(new int[0]);
        DataStore[] s = usedModel.getStores();
        ReplicateSet r = (ReplicateSet) replicateSetList.getSelectedValue();
        r.setDataStores(s);
    } else if (c.equals("new_set")) {
        String setName = null;
        while (true) {
            setName = (String) JOptionPane.showInputDialog(this, "Enter set name", "Group Name", JOptionPane.QUESTION_MESSAGE, null, null, "New replicate set");
            if (setName == null)
                // They cancelled
                return;
            if (setName.length() == 0)
                // Try again
                continue;
            break;
        }
        ReplicateSet s = new ReplicateSet(setName, new DataStore[0]);
        application.dataCollection().addReplicateSet(s);
        replicateSetModel.addElements(new DataStore[] { s });
    } else if (c.equals("rename_set")) {
        ReplicateSet s = (ReplicateSet) replicateSetList.getSelectedValue();
        String setName = null;
        while (true) {
            setName = (String) JOptionPane.showInputDialog(this, "Enter set name", "Set Name", JOptionPane.QUESTION_MESSAGE, null, null, s.name());
            // They cancelled
            if (setName == null)
                return;
            if (setName.length() > 0)
                break;
        }
        s.setName(setName);
        replicateSetModel.setElementAt(s, replicateSetList.getSelectedIndex());
    } else if (c.equals("delete_set")) {
        Object[] o = replicateSetList.getSelectedValues();
        ReplicateSet[] repSets = new ReplicateSet[o.length];
        for (int i = 0; i < o.length; i++) {
            repSets[i] = (ReplicateSet) o[i];
        }
        replicateSetModel.removeElements(repSets);
        application.dataCollection().removeReplicateSets(repSets);
    } else if (c.equals("close")) {
        setVisible(false);
        dispose();
    }
}
Also used : DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)

Example 22 with DataStore

use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.

the class DataStoreTreeDialog method progressComplete.

public void progressComplete(String command, Object result) {
    getContentPane().setLayout(new BorderLayout());
    clusterPanel = new DataStoreClusterPanel((ClusterPair) result, stores, listName);
    getContentPane().add(clusterPanel, BorderLayout.CENTER);
    rValueSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000, 0);
    rValueSlider.setPaintTicks(true);
    getContentPane().add(rValueSlider, BorderLayout.NORTH);
    rValueSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            clusterPanel.setRProportion(rValueSlider.getValue() / 1000f);
        }
    });
    JPanel buttonPanel = new JPanel();
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
        }
    });
    buttonPanel.add(closeButton);
    JButton saveImageButton = new JButton("Save Image");
    saveImageButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ImageSaver.saveImage(clusterPanel);
        }
    });
    buttonPanel.add(saveImageButton);
    JButton createRepSetsButton = new JButton("Split data stores");
    createRepSetsButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            for (int s = 0; s < stores.length; s++) {
                if (stores[s] instanceof ReplicateSet) {
                    JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "One of the stores you plotted is already a replicate set so you can't make a new set with it in.", "Can't split stores", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            // TODO: Ask for min count per store
            DataStore[][] splitStores = clusterPanel.getSplitStores(2);
            for (int s = 0; s < splitStores.length; s++) {
                SeqMonkApplication.getInstance().dataCollection().addReplicateSet(new ReplicateSet("Cluster Group " + (s + 1), splitStores[s]));
            }
            JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "Created " + splitStores.length + " new replicate sets", "Splitting Complete", JOptionPane.INFORMATION_MESSAGE);
        }
    });
    buttonPanel.add(createRepSetsButton);
    JButton reorderStoresButton = new JButton("Reorder stores");
    reorderStoresButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            DataStore[] orderedStores = clusterPanel.getOrderedStores();
            SeqMonkApplication.getInstance().setDrawnDataStores(orderedStores);
        }
    });
    buttonPanel.add(reorderStoresButton);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    setSize(800, 800);
    setLocationRelativeTo(SeqMonkApplication.getInstance());
    setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) JButton(javax.swing.JButton) ClusterPair(uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 23 with DataStore

use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.

the class AutoSplitDataDialog method createGroups.

private void createGroups() {
    String[] names = groupNamesArea.getText().split("\\n");
    int[] counts = new int[names.length];
    DataSet[] dataSets = application.dataCollection().getAllDataSets();
    DataGroup[] dataGroups = application.dataCollection().getAllDataGroups();
    boolean makeReplicateSets = groupsOrSetsBox.getSelectedItem().equals("Replicate Sets");
    boolean caseInsensitive = caseInsensitiveBox.isSelected();
    if (!includeGroupsBox.isSelected()) {
        dataGroups = new DataGroup[0];
    }
    boolean[] setsFound = new boolean[dataSets.length];
    boolean[] groupsFound = new boolean[dataGroups.length];
    for (int n = 0; n < names.length; n++) {
        if (names[n].trim().length() == 0)
            continue;
        names[n] = names[n].trim();
        String[] patterns = names[n].split("\\|");
        if (makeReplicateSets) {
            Vector<DataStore> stores = new Vector<DataStore>();
            DATASET: for (int i = 0; i < dataSets.length; i++) {
                // Only add to the first match we make
                if (setsFound[i])
                    continue;
                for (int p = 0; p < patterns.length; p++) {
                    if (caseInsensitive) {
                        if (!dataSets[i].name().toLowerCase().contains(patterns[p].toLowerCase())) {
                            continue DATASET;
                        }
                    } else {
                        if (!dataSets[i].name().contains(patterns[p])) {
                            continue DATASET;
                        }
                    }
                }
                stores.add(dataSets[i]);
                setsFound[i] = true;
            }
            DATAGROUP: for (int i = 0; i < dataGroups.length; i++) {
                // Only add to the first match we make
                if (groupsFound[i])
                    continue;
                for (int p = 0; p < patterns.length; p++) {
                    if (!dataGroups[i].name().contains(patterns[p])) {
                        continue DATAGROUP;
                    }
                }
                stores.add(dataGroups[i]);
                groupsFound[i] = true;
            }
            counts[n] = stores.size();
            if (stores.size() > 0) {
                application.dataCollection().addReplicateSet(new ReplicateSet(names[n], stores.toArray(new DataStore[0])));
            }
        } else {
            Vector<DataSet> sets = new Vector<DataSet>();
            DATASET: for (int i = 0; i < dataSets.length; i++) {
                for (int p = 0; p < patterns.length; p++) {
                    if (!dataSets[i].name().contains(patterns[p])) {
                        continue DATASET;
                    }
                }
                sets.add(dataSets[i]);
            }
            counts[n] = sets.size();
            if (sets.size() > 0) {
                application.dataCollection().addDataGroup(new DataGroup(names[n], sets.toArray(new DataSet[0])));
            }
        }
    }
    StringBuffer sb = new StringBuffer();
    sb.append("<html>");
    for (int i = 0; i < names.length; i++) {
        sb.append("For name ");
        sb.append(names[i]);
        sb.append(" found ");
        sb.append(counts[i]);
        sb.append(" hits<br>");
    }
    sb.append("</html>");
    JOptionPane.showMessageDialog(this, sb.toString(), "Group creation complete", JOptionPane.INFORMATION_MESSAGE);
// It's actually better not to close after this but let them close it themselves.
// setVisible(false);
// dispose();
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) Vector(java.util.Vector)

Example 24 with DataStore

use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.

the class SubsetNormalisationQuantitation method getOptionsPanel.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Quantitation.Quantitation#getOptionsPanel(uk.ac.babraham.SeqMonk.SeqMonkApplication)
	 */
public JPanel getOptionsPanel() {
    if (optionPanel != null) {
        // We've done this already
        return optionPanel;
    }
    optionPanel = new JPanel();
    optionPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.weightx = 0.5;
    gbc.weighty = 0.1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionPanel.add(new JLabel("Method of correction"), gbc);
    gbc.gridx = 2;
    correctionActions = new JComboBox(new String[] { "Add", "Multiply" });
    optionPanel.add(correctionActions, gbc);
    gbc.gridx = 1;
    gbc.gridy++;
    optionPanel.add(new JLabel("Summation Method"), gbc);
    gbc.gridx = 2;
    summationActions = new JComboBox(new String[] { "Mean", "Sum" });
    optionPanel.add(summationActions, gbc);
    gbc.gridx = 1;
    gbc.gridy++;
    optionPanel.add(new JLabel("Target Value"), gbc);
    gbc.gridx = 2;
    targetActions = new JComboBox(new String[] { "Largest", "1" });
    optionPanel.add(targetActions, gbc);
    Vector<DataStore> quantitatedStores = new Vector<DataStore>();
    DataSet[] sets = application.dataCollection().getAllDataSets();
    for (int s = 0; s < sets.length; s++) {
        if (sets[s].isQuantitated()) {
            quantitatedStores.add(sets[s]);
        }
    }
    DataGroup[] groups = application.dataCollection().getAllDataGroups();
    for (int g = 0; g < groups.length; g++) {
        if (groups[g].isQuantitated()) {
            quantitatedStores.add(groups[g]);
        }
    }
    data = quantitatedStores.toArray(new DataStore[0]);
    gbc.gridx = 1;
    gbc.gridy++;
    optionPanel.add(new JLabel("Calculate from probe list"), gbc);
    ProbeList[] currentLists = application.dataCollection().probeSet().getAllProbeLists();
    calculateFromProbeList = new JComboBox(currentLists);
    calculateFromProbeList.setPrototypeDisplayValue("No longer than this please");
    for (int i = 0; i < currentLists.length; i++) {
        if (currentLists[i] == application.dataCollection().probeSet().getActiveList()) {
            calculateFromProbeList.setSelectedIndex(i);
        }
    }
    gbc.gridx++;
    optionPanel.add(calculateFromProbeList, gbc);
    return optionPanel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) JLabel(javax.swing.JLabel) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) Vector(java.util.Vector)

Example 25 with DataStore

use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.

the class ManualCorrectionQuantitation method getOptionsPanel.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Quantitation.Quantitation#getOptionsPanel(uk.ac.babraham.SeqMonk.SeqMonkApplication)
	 */
public JPanel getOptionsPanel() {
    if (optionPanel != null) {
        // We've done this already
        return optionPanel;
    }
    optionPanel = new JPanel();
    optionPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.weightx = 0.5;
    gbc.weighty = 0.1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionPanel.add(new JLabel("Method of correction"), gbc);
    gbc.gridx = 2;
    correctionActions = new JComboBox(new String[] { "Add", "Subtract", "Multiply", "Divide" });
    optionPanel.add(correctionActions, gbc);
    Vector<DataStore> quantitatedStores = new Vector<DataStore>();
    DataSet[] sets = application.dataCollection().getAllDataSets();
    for (int s = 0; s < sets.length; s++) {
        if (sets[s].isQuantitated()) {
            quantitatedStores.add(sets[s]);
        }
    }
    DataGroup[] groups = application.dataCollection().getAllDataGroups();
    for (int g = 0; g < groups.length; g++) {
        if (groups[g].isQuantitated()) {
            quantitatedStores.add(groups[g]);
        }
    }
    data = quantitatedStores.toArray(new DataStore[0]);
    correctionFactors = new JTextField[data.length];
    // Now we work our way through the sets
    JPanel correctionPanel = new JPanel();
    correctionPanel.setLayout(new GridBagLayout());
    GridBagConstraints cbc = new GridBagConstraints();
    cbc.gridx = 1;
    cbc.gridy = 1;
    cbc.weightx = 0.5;
    cbc.weighty = 0.5;
    cbc.insets = new Insets(1, 3, 1, 3);
    cbc.fill = GridBagConstraints.HORIZONTAL;
    for (int d = 0; d < data.length; d++) {
        cbc.gridx = 1;
        cbc.gridy++;
        correctionPanel.add(new JLabel(data[d].name()), cbc);
        cbc.gridx = 2;
        correctionFactors[d] = new JTextField();
        if (storedCorrections.containsKey(data[d].name())) {
            correctionFactors[d].setText("" + storedCorrections.get(data[d].name()));
        }
        correctionFactors[d].addKeyListener(new NumberKeyListener(true, true));
        correctionPanel.add(correctionFactors[d], cbc);
    }
    gbc.gridx = 1;
    gbc.gridy++;
    gbc.gridwidth = 2;
    optionPanel.add(new JLabel("Correction factors", JLabel.CENTER), gbc);
    gbc.gridy++;
    gbc.weighty = 0.9;
    gbc.fill = GridBagConstraints.BOTH;
    optionPanel.add(new JScrollPane(correctionPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), gbc);
    gbc.gridx = 1;
    gbc.gridy++;
    gbc.gridwidth = 2;
    gbc.weighty = 0.001;
    gbc.fill = GridBagConstraints.NONE;
    JButton loadFromFileButton = new JButton("Load from file");
    loadFromFileButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getDataLocation());
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileFilter(new TxtFileFilter());
            int result = chooser.showOpenDialog(optionPanel);
            if (result == JFileChooser.CANCEL_OPTION)
                return;
            File file = chooser.getSelectedFile();
            SeqMonkPreferences.getInstance().setLastUsedDataLocation(file);
            try {
                BufferedReader br = new BufferedReader(new FileReader(file));
                String line;
                while ((line = br.readLine()) != null) {
                    line.trim();
                    if (line.startsWith("#"))
                        continue;
                    String[] sections = line.split("\t");
                    if (sections.length < 2)
                        continue;
                    if (sections[1].length() == 0)
                        continue;
                    // See if we can find a dataset with the name of this section
                    for (int d = 0; d < data.length; d++) {
                        if (data[d].name().equals(sections[0])) {
                            // We try setting the value to whatever is stored for this
                            try {
                                Double.parseDouble(sections[1]);
                                correctionFactors[d].setText(sections[1]);
                            } catch (NumberFormatException nfe) {
                                JOptionPane.showMessageDialog(optionPanel, "Skipping " + sections[0] + " as " + sections[1] + " isn't a number", "Correction import error", JOptionPane.WARNING_MESSAGE);
                            }
                        }
                    }
                }
                br.close();
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(optionPanel, "Failed to read input file:" + ioe.getMessage(), "Correction import error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
    });
    optionPanel.add(loadFromFileButton, gbc);
    return optionPanel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) TxtFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter) JTextField(javax.swing.JTextField) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) FileReader(java.io.FileReader) Vector(java.util.Vector) JScrollPane(javax.swing.JScrollPane) DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) BufferedReader(java.io.BufferedReader) NumberKeyListener(uk.ac.babraham.SeqMonk.Utilities.NumberKeyListener) File(java.io.File)

Aggregations

DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)46 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)21 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)19 Vector (java.util.Vector)15 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)15 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)11 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)11 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)11 JPanel (javax.swing.JPanel)10 ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)10 GridBagConstraints (java.awt.GridBagConstraints)9 JLabel (javax.swing.JLabel)9 GridBagLayout (java.awt.GridBagLayout)8 File (java.io.File)8 ActionEvent (java.awt.event.ActionEvent)7 BufferedReader (java.io.BufferedReader)7 FileReader (java.io.FileReader)7 JComboBox (javax.swing.JComboBox)7 JScrollPane (javax.swing.JScrollPane)7 HiCDataStore (uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)7