Search in sources :

Example 26 with DataSet

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

the class VisibleStoresParser method processNormalDataStore.

private DataSet processNormalDataStore(DataStore store) {
    int extendBy = prefs.extendReads();
    boolean reverse = prefs.reverseReads();
    boolean removeStrand = prefs.removeStrandInfo();
    DataSet newData = new DataSet(store.name() + "_reimport", "Reimported from " + store.name(), prefs.removeDuplicates());
    // Now process the data
    Chromosome[] chrs = dataCollection().genome().getAllChromosomes();
    for (int c = 0; c < chrs.length; c++) {
        progressUpdated("Processing " + store.name() + " chr " + chrs[c].name(), c, chrs.length);
        ReadsWithCounts reads = store.getReadsForChromosome(chrs[c]);
        Feature[] features = null;
        if (filterByFeature) {
            features = collection.genome().annotationCollection().getFeaturesForType(chrs[c], featureType);
            Arrays.sort(features);
        }
        int currentFeaturePostion = 0;
        for (int r = 0; r < reads.reads.length; r++) {
            for (int ct = 0; ct < reads.counts[r]; ct++) {
                long thisRead = reads.reads[r];
                if (cancel) {
                    progressCancelled();
                    return null;
                }
                if (downsample && downsampleProbabilty < 1) {
                    if (Math.random() > downsampleProbabilty) {
                        continue;
                    }
                }
                long read;
                int start = SequenceRead.start(thisRead);
                int end = SequenceRead.end(thisRead);
                int strand = SequenceRead.strand(thisRead);
                if (filterByStrand) {
                    if (strand == Location.FORWARD && !keepForward)
                        continue;
                    if (strand == Location.REVERSE && !keepReverse)
                        continue;
                    if (strand == Location.UNKNOWN && !keepUnknown)
                        continue;
                }
                if (filterByLength) {
                    int length = SequenceRead.length(thisRead);
                    if (minLength != null && length < minLength)
                        continue;
                    if (maxLength != null && length > maxLength)
                        continue;
                }
                if (strand == Location.FORWARD) {
                    start += forwardOffset;
                    end += forwardOffset;
                }
                if (strand == Location.REVERSE) {
                    start -= reverseOffset;
                    end -= reverseOffset;
                }
                if (filterByFeature && features.length == 0 && !excludeFeature)
                    continue;
                if (filterByFeature && features.length > 0) {
                    // See if we're comparing against the right feature
                    while (SequenceRead.start(thisRead) > features[currentFeaturePostion].location().end() && currentFeaturePostion < (features.length - 1)) {
                        currentFeaturePostion++;
                    }
                    // Test to see if we overlap
                    if (SequenceRead.overlaps(thisRead, features[currentFeaturePostion].location().packedPosition())) {
                        if (excludeFeature)
                            continue;
                    } else {
                        if (!excludeFeature)
                            continue;
                    }
                }
                if (reverse) {
                    if (strand == Location.FORWARD) {
                        strand = Location.REVERSE;
                    } else if (strand == Location.REVERSE) {
                        strand = Location.FORWARD;
                    }
                }
                if (removeStrand) {
                    strand = Location.UNKNOWN;
                }
                if (extractCentres) {
                    int centre = start + ((end - start) / 2);
                    start = centre - centreExtractContext;
                    end = centre + centreExtractContext;
                }
                if (extendBy != 0) {
                    // We now allow negative extensions to shorten reads
                    if (strand == Location.FORWARD || strand == Location.UNKNOWN) {
                        end += extendBy;
                        if (end < start)
                            end = start;
                    } else if (strand == Location.REVERSE) {
                        start -= extendBy;
                        if (start > end)
                            start = end;
                    }
                }
                // We don't allow reads before the start of the chromosome
                if (start < 1) {
                    int overrun = (0 - start) + 1;
                    progressWarningReceived(new SeqMonkException("Reading position " + start + " was " + overrun + "bp before the start of chr" + chrs[c].name() + " (" + chrs[c].length() + ")"));
                    continue;
                }
                // We also don't allow readings which are beyond the end of the chromosome
                if (end > chrs[c].length()) {
                    int overrun = end - chrs[c].length();
                    progressWarningReceived(new SeqMonkException("Reading position " + end + " was " + overrun + "bp beyond the end of chr" + chrs[c].name() + " (" + chrs[c].length() + ")"));
                    continue;
                }
                // We can now make the new reading
                try {
                    read = SequenceRead.packPosition(start, end, strand);
                    if (!prefs.isHiC()) {
                        // HiC additions are deferred until we know the other end is OK too.
                        newData.addData(chrs[c], read);
                    }
                } catch (SeqMonkException e) {
                    progressWarningReceived(e);
                    continue;
                }
            }
        }
    }
    return newData;
}
Also used : DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) PairedDataSet(uk.ac.babraham.SeqMonk.DataTypes.PairedDataSet) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) ReadsWithCounts(uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)

Example 27 with DataSet

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

the class DataViewer method mousePressed.

/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
public void mousePressed(MouseEvent me) {
    JTree tree = (JTree) me.getSource();
    tree.setSelectionRow(tree.getRowForLocation(me.getX(), me.getY()));
    // Check if they right-clicked
    if ((me.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
        // I'm not sure if this is a timing issue, but we can get the selection path being null
        if (tree.getSelectionPath() == null)
            return;
        Object clickedItem = tree.getSelectionPath().getLastPathComponent();
        if (clickedItem instanceof DataSet) {
            new DataPopupMenu((DataSet) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof DataGroup) {
            new GroupPopupMenu((DataGroup) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof ReplicateSet) {
            new ReplicatePopupMenu((ReplicateSet) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof ProbeList) {
            new ProbePopupMenu((ProbeList) clickedItem).show(probeSetTree, me.getX(), me.getY());
        } else if (clickedItem instanceof AnnotationSet) {
            new AnnotationPopupMenu((AnnotationSet) clickedItem).show(dataTree, me.getX(), me.getY());
        }
    } else // Check if they double clicked
    if (me.getClickCount() == 2) {
        // I'm not sure if this is a timing issue, but we can get the selection path being null
        if (tree.getSelectionPath() == null)
            return;
        Object clickedItem = tree.getSelectionPath().getLastPathComponent();
        if (clickedItem instanceof DataSet) {
            new DataPopupMenu((DataSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof DataGroup) {
            new GroupPopupMenu((DataGroup) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof ReplicateSet) {
            new ReplicatePopupMenu((ReplicateSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof ProbeList) {
            new ProbePopupMenu((ProbeList) clickedItem).actionPerformed(new ActionEvent(this, 0, "view"));
        } else if (clickedItem instanceof AnnotationSet) {
            new AnnotationPopupMenu((AnnotationSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        }
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) AnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet) CoreAnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet) JTree(javax.swing.JTree)

Example 28 with DataSet

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

the class GroupEditor 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[] addObj = availableList.getSelectedValues();
        DataStore[] adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableModel.removeElements(adds);
        availableList.setSelectedIndices(new int[0]);
        usedList.setSelectedIndices(new int[0]);
        Object[] o = usedModel.getStores();
        DataSet[] s = new DataSet[o.length];
        for (int i = 0; i < s.length; i++) {
            s[i] = (DataSet) o[i];
        }
        DataGroup r = (DataGroup) groupList.getSelectedValue();
        r.setDataSets(s);
    } else if (c.equals("select_named")) {
        new NameGatherer();
    } else if (c.equals("remove")) {
        Object[] addObj = usedList.getSelectedValues();
        DataStore[] adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.removeElements(adds);
        availableModel.addElements(adds);
        availableList.setSelectedIndices(new int[0]);
        usedList.setSelectedIndices(new int[0]);
        Object[] o = usedModel.getStores();
        DataSet[] s = new DataSet[o.length];
        for (int i = 0; i < s.length; i++) {
            s[i] = (DataSet) o[i];
        }
        DataGroup r = (DataGroup) groupList.getSelectedValue();
        r.setDataSets(s);
    } else if (c.equals("new_set")) {
        String setName = null;
        while (true) {
            setName = (String) JOptionPane.showInputDialog(this, "Enter group name", "Group Name", JOptionPane.QUESTION_MESSAGE, null, null, "New Data Group");
            if (setName == null)
                // They cancelled
                return;
            if (setName.length() == 0)
                // Try again
                continue;
            break;
        }
        DataGroup s = new DataGroup(setName, new DataSet[0]);
        application.dataCollection().addDataGroup(s);
        groupModel.addElements(new DataStore[] { s });
    } else if (c.equals("rename_set")) {
        DataGroup s = (DataGroup) groupList.getSelectedValue();
        String setName = null;
        while (true) {
            setName = (String) JOptionPane.showInputDialog(this, "Enter group name", "Set Name", JOptionPane.QUESTION_MESSAGE, null, null, s.name());
            // They cancelled
            if (setName == null)
                return;
            if (setName.length() > 0)
                break;
        }
        s.setName(setName);
        groupModel.setElementAt(s, groupList.getSelectedIndex());
    } else if (c.equals("delete_set")) {
        Object[] o = groupList.getSelectedValues();
        DataGroup[] dataGroups = new DataGroup[o.length];
        for (int i = 0; i < o.length; i++) {
            dataGroups[i] = (DataGroup) o[i];
        }
        groupModel.removeElements(dataGroups);
        application.dataCollection().removeDataGroups(dataGroups);
    } else if (c.equals("close")) {
        setVisible(false);
        dispose();
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore)

Example 29 with DataSet

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

the class GroupEditor method valueChanged.

/* (non-Javadoc)
	 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
	 */
public void valueChanged(ListSelectionEvent ae) {
    // Check for a new set being selected
    if (ae.getSource() == groupList) {
        // Move all samples back to the available list
        DataStore[] o = usedModel.getStores();
        availableModel.addElements(o);
        usedModel.removeAllElements();
        if (groupList.getSelectedValues().length == 1) {
            renameButton.setEnabled(true);
            deleteButton.setEnabled(true);
            DataGroup s = (DataGroup) groupList.getSelectedValue();
            DataSet[] st = s.dataSets();
            usedModel.addElements(st);
            availableModel.removeElements(st);
        } else if (groupList.getSelectedValues().length > 1) {
            deleteButton.setEnabled(true);
        } else {
            deleteButton.setEnabled(false);
        }
    }
    // Check to see if we can add anything...
    if (availableList.getSelectedIndices().length > 0 && groupList.getSelectedIndices().length == 1) {
        addButton.setEnabled(true);
    } else {
        addButton.setEnabled(false);
    }
    // Or remove anything
    if (usedList.getSelectedIndices().length > 0 && groupList.getSelectedIndices().length == 1) {
        removeButton.setEnabled(true);
    } else {
        removeButton.setEnabled(false);
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore)

Example 30 with DataSet

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

the class DataTrackSelector 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[] addObj = availableGroupList.getSelectedValues();
        DataStore[] adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableGroupModel.removeElements(adds);
        usedList.setSelectedIndices(new int[0]);
        availableGroupList.setSelectedIndices(new int[0]);
        addObj = availableSetList.getSelectedValues();
        adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableSetModel.removeElements(adds);
        availableSetList.setSelectedIndices(new int[0]);
        addObj = availableReplicateList.getSelectedValues();
        adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableReplicatesModel.removeElements(adds);
        availableReplicateList.setSelectedIndices(new int[0]);
    } else if (c.equals("remove")) {
        Object[] removeObj = usedList.getSelectedValues();
        DataStore[] removes = new DataStore[removeObj.length];
        for (int i = 0; i < removes.length; i++) {
            removes[i] = (DataStore) removeObj[i];
        }
        usedModel.removeElements(removes);
        usedList.setSelectedIndices(new int[0]);
        Vector<DataStore> removeSets = new Vector<DataStore>();
        Vector<DataStore> removeGroups = new Vector<DataStore>();
        Vector<DataStore> removeReps = new Vector<DataStore>();
        for (int i = 0; i < removes.length; i++) {
            if (removes[i] instanceof DataSet) {
                removeSets.add(removes[i]);
            } else if (removes[i] instanceof ReplicateSet) {
                removeReps.add(removes[i]);
            } else if (removes[i] instanceof DataGroup) {
                removeGroups.add(removes[i]);
            } else {
                throw new IllegalStateException("Unknown type of removed store " + removes[i]);
            }
        }
        availableSetModel.addElements(removeSets.toArray(new DataStore[0]));
        availableGroupModel.addElements(removeGroups.toArray(new DataStore[0]));
        availableReplicatesModel.addElements(removeReps.toArray(new DataStore[0]));
        availableSetList.setSelectedIndices(new int[0]);
        availableGroupList.setSelectedIndices(new int[0]);
        availableReplicateList.setSelectedIndices(new int[0]);
    } else if (c.equals("up")) {
        // Collect the list of selected indices
        int[] s = usedList.getSelectedIndices();
        Arrays.sort(s);
        // Get the set of objects associated with the selected indices
        DataStore[] current = new DataStore[s.length];
        for (int i = 0; i < s.length; i++) {
            current[i] = usedModel.elementAt(s[i]);
        }
        // Get the object above, which is going to move below
        DataStore above = usedModel.elementAt(s[0] - 1);
        // Move all the selected indices up one
        for (int i = 0; i < s.length; i++) {
            usedModel.setElementAt(current[i], s[i] - 1);
        }
        // Move the above object below the selected ones
        usedModel.setElementAt(above, s[s.length - 1]);
        // Decrease the set of selected indices and select them again
        for (int i = 0; i < s.length; i++) {
            s[i]--;
        }
        usedList.setSelectedIndices(s);
    } else if (c.equals("down")) {
        // Collect the list of selected indices
        int[] s = usedList.getSelectedIndices();
        Arrays.sort(s);
        // Get the set of objects associated with the selected indices
        DataStore[] current = new DataStore[s.length];
        for (int i = 0; i < s.length; i++) {
            current[i] = usedModel.elementAt(s[i]);
        }
        // Get the object below, which is going to move below
        DataStore below = usedModel.elementAt(s[s.length - 1] + 1);
        // Move all the selected indices down one
        for (int i = 0; i < s.length; i++) {
            usedModel.setElementAt(current[i], s[i] + 1);
        }
        // Move the below object above the selected ones
        usedModel.setElementAt(below, s[0]);
        // Increase the set of selected indices and select them again
        for (int i = 0; i < s.length; i++) {
            s[i]++;
        }
        usedList.setSelectedIndices(s);
    } else if (c.equals("cancel")) {
        setVisible(false);
        dispose();
    } else if (c.equals("ok")) {
        DataStore[] s = usedModel.getStores();
        application.setDrawnDataStores(s);
        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)

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