Search in sources :

Example 6 with ReplicateSet

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

the class DataTreeRenderer method getTreeCellRendererComponent.

/* (non-Javadoc)
	 * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
	 */
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if (value instanceof DataSet) {
        JLabel label = new JLabel(value.toString(), dataSetIcon, JLabel.LEFT);
        if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
            label.setText("[HiC] " + label.getText());
        }
        if (selected) {
            label.setOpaque(true);
            label.setBackground(Color.LIGHT_GRAY);
        }
        return label;
    } else if (value instanceof DataGroup) {
        JLabel label = new JLabel(value.toString(), dataGroupIcon, JLabel.LEFT);
        if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
            label.setText("[HiC] " + label.getText());
        }
        if (selected) {
            label.setOpaque(true);
            label.setBackground(Color.LIGHT_GRAY);
        }
        return label;
    } else if (value instanceof ReplicateSet) {
        JLabel label = new JLabel(value.toString(), replicateSetIcon, JLabel.LEFT);
        if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
            label.setText("[HiC] " + label.getText());
        }
        if (selected) {
            label.setOpaque(true);
            label.setBackground(Color.LIGHT_GRAY);
        }
        return label;
    } else if (value instanceof ProbeList) {
        JLabel label = new JLabel(value.toString(), probeListIcon, JLabel.LEFT);
        if (selected) {
            label.setOpaque(true);
            label.setBackground(Color.LIGHT_GRAY);
        }
        return label;
    } else if (value instanceof AnnotationSet) {
        JLabel label = new JLabel(value.toString(), annotationSetIcon, JLabel.LEFT);
        if (selected) {
            label.setOpaque(true);
            label.setBackground(Color.LIGHT_GRAY);
        }
        return label;
    } else {
        return super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) JLabel(javax.swing.JLabel) HiCDataStore(uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore) AnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet)

Example 7 with ReplicateSet

use of uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet 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 8 with ReplicateSet

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

the class SeqMonkDataWriter method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    try {
        // Generate a temp file in the same directory as the final
        // destination
        tempFile = File.createTempFile("seqmonk", ".temp", file.getParentFile());
        BufferedOutputStream bos;
        if (SeqMonkPreferences.getInstance().compressOutput()) {
            bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(tempFile), 2048));
        } else {
            bos = new BufferedOutputStream(new FileOutputStream(tempFile));
        }
        PrintStream p = new PrintStream(bos);
        printDataVersion(p);
        printAssembly(p);
        DataSet[] dataSets = data.getAllDataSets();
        DataGroup[] dataGroups = data.getAllDataGroups();
        ReplicateSet[] replicateSets = data.getAllReplicateSets();
        if (!printDataSets(dataSets, p)) {
            // They cancelled
            return;
        }
        printDataGroups(dataSets, dataGroups, p);
        printReplicateSets(dataSets, dataGroups, replicateSets, p);
        AnnotationSet[] annotationSets = data.genome().annotationCollection().anotationSets();
        for (int a = 0; a < annotationSets.length; a++) {
            if (annotationSets[a] instanceof CoreAnnotationSet)
                continue;
            if (!printAnnotationSet(annotationSets[a], p)) {
                // They cancelled
                return;
            }
        }
        Probe[] probes = null;
        if (data.probeSet() != null) {
            probes = data.probeSet().getAllProbes();
        }
        if (probes != null) {
            if (!printProbeSet(data.probeSet(), probes, dataSets, dataGroups, p)) {
                // They cancelled
                return;
            }
        }
        if (visibleStores != null) {
            printVisibleDataStores(dataSets, dataGroups, replicateSets, p);
        }
        if (probes != null) {
            if (!printProbeLists(probes, p)) {
                // They cancelled
                return;
            }
        }
        if (defaultFeatureTracks != null) {
            printDisplayPreferences(p);
        }
        p.close();
        // We can now overwrite the original file
        if (file.exists()) {
            if (!file.delete()) {
                throw new IOException("Couldn't delete old project file when making new one");
            }
        }
        if (!tempFile.renameTo(file)) {
            throw new IOException("Failed to rename temporary file");
        }
        Enumeration<ProgressListener> e = listeners.elements();
        while (e.hasMoreElements()) {
            e.nextElement().progressComplete("data_written", null);
        }
    } catch (Exception ex) {
        Enumeration<ProgressListener> e = listeners.elements();
        while (e.hasMoreElements()) {
            e.nextElement().progressExceptionReceived(ex);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) Enumeration(java.util.Enumeration) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) PairedDataSet(uk.ac.babraham.SeqMonk.DataTypes.PairedDataSet) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) AnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet) CoreAnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet) IOException(java.io.IOException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) IOException(java.io.IOException) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) CoreAnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet) ProgressListener(uk.ac.babraham.SeqMonk.DataTypes.ProgressListener) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with ReplicateSet

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

the class RelativeQuantitation 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.01;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    optionPanel.add(new JLabel("Reference"), gbc);
    gbc.gridx = 2;
    optionPanel.add(new JLabel("Data Stores"), gbc);
    gbc.gridy++;
    gbc.gridx = 1;
    gbc.weighty = 0.99;
    gbc.fill = GridBagConstraints.BOTH;
    DefaultListModel dataModel = new DefaultListModel();
    DataStore[] stores = application.dataCollection().getAllDataStores();
    Vector<DataStore> quantitatedStores = new Vector<DataStore>();
    for (int i = 0; i < stores.length; i++) {
        if (stores[i].isQuantitated()) {
            dataModel.addElement(stores[i]);
            if (!(stores[i] instanceof ReplicateSet)) {
                quantitatedStores.add(stores[i]);
            }
        }
    }
    data = quantitatedStores.toArray(new DataStore[0]);
    referenceList = new JList(dataModel);
    // only allow one to be selected
    referenceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    referenceList.setCellRenderer(new TypeColourRenderer());
    referenceList.addListSelectionListener(this);
    optionPanel.add(new JScrollPane(referenceList), gbc);
    gbc.gridx = 2;
    tableModel = new ReferencePairingTableModel();
    JTable refTable = new JTable(tableModel);
    optionPanel.add(new JScrollPane(refTable), gbc);
    gbc.gridx = 1;
    gbc.gridy++;
    gbc.weighty = 0.01;
    gbc.fill = GridBagConstraints.NONE;
    JButton applyToSelectionButton = new JButton("Apply to Selected");
    applyToSelectionButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object value = referenceList.getSelectedValue();
            // if (value == null) return;
            tableModel.setReference((DataStore) value);
        }
    });
    optionPanel.add(applyToSelectionButton, gbc);
    gbc.gridx = 2;
    JButton selectAllButton = new JButton("Apply to All");
    selectAllButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            tableModel.selectAll();
            Object value = referenceList.getSelectedValue();
            tableModel.setReference((DataStore) value);
        }
    });
    // applyToSelectionButton.addActionListener(this);
    optionPanel.add(selectAllButton, gbc);
    // define relative quantitation method
    gbc.gridx = 1;
    gbc.gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    optionPanel.add(new JLabel("Reference method"), gbc);
    gbc.gridx = 2;
    diffTypeBox = new JComboBox(new String[] { "Minus", "Log Divide", "Divide" });
    // default : divide
    diffTypeBox.setSelectedIndex(2);
    optionPanel.add(diffTypeBox, gbc);
    return optionPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultListModel(javax.swing.DefaultListModel) TypeColourRenderer(uk.ac.babraham.SeqMonk.Dialogs.Renderers.TypeColourRenderer) ActionListener(java.awt.event.ActionListener) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) JTable(javax.swing.JTable) Vector(java.util.Vector) JList(javax.swing.JList)

Example 10 with ReplicateSet

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

the class SeqMonkParser method parseReplicates.

/**
 * Parses the list of replicate sets.
 *
 * @param sections The tab split values from the initial replicates line
 * @throws SeqMonkException
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void parseReplicates(String[] sections) throws SeqMonkException, IOException {
    if (sections.length != 2) {
        throw new SeqMonkException("Data Groups line didn't contain 2 sections");
    }
    if (!sections[0].equals("Replicate Sets")) {
        throw new SeqMonkException("Couldn't find expected replicates line");
    }
    int n = Integer.parseInt(sections[1]);
    for (int i = 0; i < n; i++) {
        String[] replicateLine = br.readLine().split("\\t");
        DataStore[] groupMembers = new DataStore[replicateLine.length - 1];
        for (int j = 1; j < replicateLine.length; j++) {
            if (replicateLine[j].startsWith("g")) {
                replicateLine[j] = replicateLine[j].substring(1);
                groupMembers[j - 1] = application.dataCollection().getDataGroup(Integer.parseInt(replicateLine[j]));
            } else if (replicateLine[j].startsWith("s")) {
                replicateLine[j] = replicateLine[j].substring(1);
                groupMembers[j - 1] = application.dataCollection().getDataSet(Integer.parseInt(replicateLine[j]));
            } else {
                throw new SeqMonkException("Replicate member id " + replicateLine[j] + " didn't start with g or s");
            }
            if (groupMembers[j - 1] == null) {
                throw new SeqMonkException("Couldn't find replicate member from position " + replicateLine[j]);
            }
        }
        ReplicateSet r = new ReplicateSet(replicateLine[0], groupMembers);
        application.dataCollection().addReplicateSet(r);
    }
}
Also used : DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException)

Aggregations

ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)15 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)10 Vector (java.util.Vector)5 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)5 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)5 ActionEvent (java.awt.event.ActionEvent)4 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)4 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 AnnotationSet (uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet)3 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)3 BorderLayout (java.awt.BorderLayout)2 GridBagConstraints (java.awt.GridBagConstraints)2 ActionListener (java.awt.event.ActionListener)2 Hashtable (java.util.Hashtable)2 JButton (javax.swing.JButton)2 JList (javax.swing.JList)2 JScrollPane (javax.swing.JScrollPane)2 CoreAnnotationSet (uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet)2 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)2