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);
}
}
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();
}
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;
}
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);
}
}
}
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();
}
}
Aggregations