Search in sources :

Example 11 with DataSet

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

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

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

the class TypeColourRenderer method getListCellRendererComponent.

public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
    // will make it do something more sensible
    if (value == null) {
        return new JLabel("null");
    }
    JLabel l = new JLabel(value.toString());
    if (value instanceof HiCDataStore) {
        if (((HiCDataStore) value).isValidHiC()) {
            l.setText("[HiC] " + l.getText());
        }
    }
    if (value instanceof DataSet) {
        l.setForeground(ColourScheme.DATASET_LIST);
        l.setBackground(ColourScheme.DATASET_LIST);
    } else if (value instanceof DataGroup) {
        l.setForeground(ColourScheme.DATAGROUP_LIST);
        l.setBackground(ColourScheme.DATAGROUP_LIST);
    } else {
        // Should only be replicate sets
        l.setForeground(ColourScheme.REPLICATE_SET_LIST);
        l.setBackground(ColourScheme.REPLICATE_SET_LIST);
    }
    if (selected) {
        l.setForeground(Color.WHITE);
        l.setOpaque(true);
    }
    return l;
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) JLabel(javax.swing.JLabel) HiCDataStore(uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)

Example 14 with DataSet

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

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

the class DataSetEditor 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("rename_dataset")) {
        DataSet s = (DataSet) dataSetList.getSelectedValue();
        String dataSetName = null;
        while (true) {
            dataSetName = (String) JOptionPane.showInputDialog(this, "Enter DataSet name", "DataSet Name", JOptionPane.QUESTION_MESSAGE, null, null, s.name());
            // They cancelled
            if (dataSetName == null)
                return;
            if (dataSetName.length() > 0)
                break;
        }
        s.setName(dataSetName);
        dataSetModel.setElementAt(s, dataSetList.getSelectedIndex());
    } else if (c.equals("replace")) {
        Object[] o = dataSetList.getSelectedValues();
        DataSet[] ds = new DataSet[o.length];
        for (int i = 0; i < o.length; i++) {
            ds[i] = (DataSet) o[i];
        }
        String replaceWhat = null;
        while (true) {
            replaceWhat = (String) JOptionPane.showInputDialog(this, "Replace what", "Replace text", JOptionPane.QUESTION_MESSAGE, null, null, "");
            // They cancelled
            if (replaceWhat == null)
                return;
            if (replaceWhat.length() > 0)
                break;
        }
        String replaceWith = (String) JOptionPane.showInputDialog(this, "Replace with", "Replace text", JOptionPane.QUESTION_MESSAGE, null, null, "");
        // They cancelled
        if (replaceWith == null)
            return;
        // catch this so as to produce a nicer error message
        try {
            for (int s = 0; s < ds.length; s++) {
                String oldName = ds[s].name();
                String newName = oldName.replaceAll(replaceWhat, replaceWith);
                ds[s].setName(newName);
            }
            ListDataListener[] l = dataSetModel.getListDataListeners();
            for (int i = 0; i < l.length; i++) {
                l[i].contentsChanged(new ListDataEvent(dataSetModel, ListDataEvent.CONTENTS_CHANGED, 0, ds.length));
            }
        } catch (PatternSyntaxException pse) {
            JOptionPane.showMessageDialog(this, "<html>You used a regex in your search, but it contained a syntax error<br><br>" + pse.getLocalizedMessage(), "Pattern error", JOptionPane.ERROR_MESSAGE);
        }
    } else if (c.equals("reset")) {
        Object[] o = dataSetList.getSelectedValues();
        if (JOptionPane.showConfirmDialog(this, "Reset names to original file names?", "Reset names?", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
            return;
        for (int i = 0; i < o.length; i++) {
            DataSet d = (DataSet) o[i];
            File f = new File(d.fileName());
            d.setName(f.getName());
        }
    } else if (c.equals("select_names")) {
        // We need to collect a list of names we want to keep
        CollectDataSetNamesDialog d = new CollectDataSetNamesDialog();
        String[] names = d.getNames();
        System.err.println("Got a list of " + names.length + " names");
        // They cancelled or didn't enter anything
        if (names.length == 0)
            return;
        IntVector iv = new IntVector();
        INDEX: for (int index = 0; index < dataSetModel.getSize(); index++) {
            for (int n = 0; n < names.length; n++) {
                if (names[n].equals(dataSetModel.elementAt(index).toString())) {
                    // System.err.println("It matches");
                    iv.add(index);
                    continue INDEX;
                }
            }
        }
        dataSetList.setSelectedIndices(iv.toArray());
    } else if (c.equals("close")) {
        setVisible(false);
        dispose();
    } else if (c.equals("delete_dataset")) {
        Object[] o = dataSetList.getSelectedValues();
        if (JOptionPane.showConfirmDialog(this, "Are you sure you want to delete " + o.length + " data sets?", "Really delete?", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
            return;
        DataSet[] ds = new DataSet[o.length];
        for (int i = 0; i < o.length; i++) {
            ds[i] = (DataSet) o[i];
            dataSetModel.removeElement(o[i]);
        }
        collection.removeDataSets(ds);
    } else if (c.equals("close")) {
        setVisible(false);
        dispose();
    }
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) IntVector(uk.ac.babraham.SeqMonk.Utilities.IntVector) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) File(java.io.File) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)36 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)22 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)16 PairedDataSet (uk.ac.babraham.SeqMonk.DataTypes.PairedDataSet)14 File (java.io.File)12 Vector (java.util.Vector)11 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)11 BufferedReader (java.io.BufferedReader)10 FileReader (java.io.FileReader)10 FileInputStream (java.io.FileInputStream)9 InputStreamReader (java.io.InputStreamReader)9 GZIPInputStream (java.util.zip.GZIPInputStream)9 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)8 ChromosomeWithOffset (uk.ac.babraham.SeqMonk.Utilities.ChromosomeWithOffset)7 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)6 JLabel (javax.swing.JLabel)5 ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)5 IOException (java.io.IOException)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3