Search in sources :

Example 71 with ProbeList

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

the class CombineFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    ProbeList newList;
    if (combineType == OR && firstList.parent() == secondList.parent()) {
        newList = new ProbeList(firstList.parent(), "", "", null);
    } else {
        newList = new ProbeList(firstList, "", "", null);
    }
    Probe[] firstListProbes = firstList.getAllProbes();
    Probe[] secondListProbes = secondList.getAllProbes();
    int l1 = 0;
    int l2 = 0;
    while (true) {
        if (l1 >= firstListProbes.length) {
            // All of the remaining l2 probes are unique to l2
            if (combineType == OR) {
                for (int i = l2; i < secondListProbes.length; i++) {
                    newList.addProbe(secondListProbes[i], null);
                }
            }
            break;
        }
        if (l2 >= secondListProbes.length) {
            // All of the remaining l1 probes are unique to l1
            if (combineType == OR || combineType == BUTNOT) {
                for (int i = l1; i < firstListProbes.length; i++) {
                    newList.addProbe(firstListProbes[i], null);
                }
            }
            break;
        }
        progressUpdated(l1 + l2, firstListProbes.length + secondListProbes.length);
        if (firstListProbes[l1] == secondListProbes[l2]) {
            // This probe is common to both lists
            if (combineType == AND || combineType == OR) {
                newList.addProbe(firstListProbes[l1], null);
            }
            ++l1;
            ++l2;
        } else if (firstListProbes[l1].compareTo(secondListProbes[l2]) > 0) {
            // We can make a decision about the lower value (l2)
            if (combineType == OR) {
                newList.addProbe(secondListProbes[l2], null);
            }
            l2++;
        } else {
            // We can make a decision about the lower value (l1)
            if (combineType == OR || combineType == BUTNOT) {
                newList.addProbe(firstListProbes[l1], null);
            }
            l1++;
        }
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 72 with ProbeList

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

the class CorrelationClusterFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    // System.out.println("Data store size="+stores.length+" lower="+lowerLimit+" upper="+upperLimit+" type="+limitType+" chosen="+chosenNumber);
    Probe[] probes = startingList.getAllProbes();
    ProbeList newList = new ProbeList(startingList, "Correlation Cluster", "", null);
    Vector<CorrelationCluster> clusters = new Vector<CorrelationCluster>();
    for (int p = 0; p < probes.length; p++) {
        progressUpdated(p, probes.length);
        if (cancel) {
            progressCancelled();
            return;
        }
        Enumeration<CorrelationCluster> cc = clusters.elements();
        double maxR = 0;
        CorrelationCluster bestCluster = null;
        while (cc.hasMoreElements()) {
            CorrelationCluster cluster = cc.nextElement();
            double r = cluster.minRValue(probes[p], minCorrelation);
            if (r > minCorrelation && r > maxR) {
                maxR = r;
                bestCluster = cluster;
            }
        }
        if (bestCluster != null) {
            bestCluster.addProbe(probes[p]);
        } else {
            // If we get here we need to make a new cluster
            clusters.add(new CorrelationCluster(stores, probes[p]));
        }
    }
    // Now we need to go through the clusters making a list for each one
    // and putting the full set of passed probes in the main list.
    CorrelationCluster[] allClusters = clusters.toArray(new CorrelationCluster[0]);
    Arrays.sort(allClusters);
    for (int c = 0; c < allClusters.length; c++) {
        if (allClusters[c].size() >= minSize) {
            Probe[] clusterProbes = allClusters[c].getProbes();
            ProbeList clusterList = new ProbeList(newList, "Group" + (c + 1), "Correlated Probes", null);
            for (int p = 0; p < clusterProbes.length; p++) {
                newList.addProbe(clusterProbes[p], null);
                clusterList.addProbe(clusterProbes[p], null);
            }
        }
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 73 with ProbeList

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

the class CollateListsFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    // System.out.println("Data store size="+stores.length+" lower="+lowerLimit+" upper="+upperLimit+" type="+limitType+" chosen="+chosenNumber);
    HashMap<Probe, Integer> probeCounts = new HashMap<Probe, Integer>();
    ProbeList newList = new ProbeList(collection.probeSet(), "Filtered Probes", "", "Number of lists");
    for (int l = 0; l < lists.length; l++) {
        progressUpdated(l, lists.length);
        Probe[] probes = lists[l].getAllProbes();
        for (int p = 0; p < probes.length; p++) {
            if (cancel) {
                cancel = false;
                progressCancelled();
                return;
            }
            if (probeCounts.containsKey(probes[p])) {
                probeCounts.put(probes[p], probeCounts.get(probes[p]) + 1);
            } else {
                probeCounts.put(probes[p], 1);
            }
        }
    }
    // Now we can step through the set of probes we've seen and figure out if
    // we want to keep them.
    Iterator<Probe> pi = probeCounts.keySet().iterator();
    while (pi.hasNext()) {
        Probe p = pi.next();
        // probe to the probe set.
        switch(limitType) {
            case EXACTLY:
                if (probeCounts.get(p) == chosenNumber)
                    newList.addProbe(p, (float) probeCounts.get(p));
                break;
            case AT_LEAST:
                if (probeCounts.get(p) >= chosenNumber)
                    newList.addProbe(p, (float) probeCounts.get(p));
                break;
            case NO_MORE_THAN:
                if (probeCounts.get(p) <= chosenNumber)
                    newList.addProbe(p, (float) probeCounts.get(p));
                break;
        }
    }
    newList.setName("Combined Lists");
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) HashMap(java.util.HashMap) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 74 with ProbeList

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

the class CorrelationFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    // System.out.println("Data store size="+stores.length+" lower="+lowerLimit+" upper="+upperLimit+" type="+limitType+" chosen="+chosenNumber);
    Probe[] probes = startingList.getAllProbes();
    ProbeList newList = new ProbeList(startingList, "Filtered Probes", "", "R-value");
    double[] referenceProfile = null;
    try {
        referenceProfile = getReferneceProfile();
    } catch (SeqMonkException ex) {
        progressExceptionReceived(ex);
    }
    double[] currentProfile = new double[stores.length];
    for (int p = 0; p < probes.length; p++) {
        progressUpdated(p, probes.length);
        if (cancel) {
            cancel = false;
            progressCancelled();
            return;
        }
        try {
            for (int s = 0; s < stores.length; s++) {
                currentProfile[s] = stores[s].getValueForProbe(probes[p]);
            }
            float r = PearsonCorrelation.calculateCorrelation(referenceProfile, currentProfile);
            if (correlationCutoff > 0) {
                if (r >= correlationCutoff) {
                    newList.addProbe(probes[p], r);
                }
            } else {
                if (r <= correlationCutoff) {
                    newList.addProbe(probes[p], r);
                }
            }
        } catch (SeqMonkException ex) {
            continue;
        }
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 75 with ProbeList

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

the class DeduplicationFilter method generateProbeList.

protected void generateProbeList() {
    ProbeList newList = new ProbeList(startingList, "", "", startingList.getValueName());
    Probe[] probes = startingList.getAllProbes();
    boolean useNames = optionsPanel.filterOnNames();
    // Find out what we're using to select the best hit
    boolean discardDuplicates = optionsPanel.discardDuplicates();
    boolean useHighest = optionsPanel.selectHighest();
    boolean useLength = optionsPanel.selectLength();
    // For the name filtering we need to keep track of the longest probe
    // with each suffix.
    HashMap<String, Probe> probePrefixes = null;
    HashSet<String> duplicatedProbePrefixes = new HashSet<String>();
    // For overlap filtering we need to keep track of the last valid
    // probe to test against when looking for overlaps.
    Probe lastValidProbe = null;
    // For the discard option we'll also need to keep track of whether
    // the last valid probe was overlapped so we can throw it away when
    // we get to it.
    boolean lastValidWasOverlapped = false;
    if (useNames) {
        probePrefixes = new HashMap<String, Probe>();
    } else {
        // If we're sorting by overlap then we need the probes to
        // come in position order.
        Arrays.sort(probes);
    }
    for (int p = 0; p < probes.length; p++) {
        if (p % 10000 == 0)
            progressUpdated(p, probes.length);
        if (cancel) {
            cancel = false;
            progressCancelled();
            return;
        }
        if (useNames) {
            String prefix = probes[p].name().replaceFirst(optionsPanel.regexPattern(), "");
            if (probePrefixes.containsKey(prefix)) {
                if (discardDuplicates) {
                    // We don't need to do anything other than record that this happened since
                    // we're going to be throwing all of the probes away anyhow
                    duplicatedProbePrefixes.add(prefix);
                } else if (useLength) {
                    if (useHighest) {
                        if (probes[p].length() > probePrefixes.get(prefix).length()) {
                            probePrefixes.put(prefix, probes[p]);
                        }
                    } else {
                        if (probes[p].length() < probePrefixes.get(prefix).length()) {
                            probePrefixes.put(prefix, probes[p]);
                        }
                    }
                } else {
                    if (useHighest) {
                        if (startingList.getValueForProbe(probes[p]) > startingList.getValueForProbe(probePrefixes.get(prefix))) {
                            probePrefixes.put(prefix, probes[p]);
                        }
                    } else {
                        if (startingList.getValueForProbe(probes[p]) < startingList.getValueForProbe(probePrefixes.get(prefix))) {
                            probePrefixes.put(prefix, probes[p]);
                        }
                    }
                }
            } else {
                probePrefixes.put(prefix, probes[p]);
            }
        } else {
            if (lastValidProbe == null) {
                lastValidProbe = probes[p];
                lastValidWasOverlapped = false;
            } else {
                if (lastValidProbe.chromosome() == probes[p].chromosome()) {
                    int overlap = (Math.min(lastValidProbe.end(), probes[p].end()) - Math.max(lastValidProbe.start(), probes[p].start())) + 1;
                    if (overlap > 0) {
                        double percentOverlap = (overlap * 100d) / (Math.min(lastValidProbe.length(), probes[p].length()));
                        if (percentOverlap > optionsPanel.percentOverlap()) {
                            // This is a valid overlap
                            lastValidWasOverlapped = true;
                            if (useLength) {
                                if (useHighest) {
                                    if (probes[p].length() > lastValidProbe.length()) {
                                        lastValidProbe = probes[p];
                                    }
                                } else {
                                    if (probes[p].length() < lastValidProbe.length()) {
                                        lastValidProbe = probes[p];
                                    }
                                }
                            } else {
                                if (useHighest) {
                                    if (startingList.getValueForProbe(probes[p]) > startingList.getValueForProbe(lastValidProbe)) {
                                        lastValidProbe = probes[p];
                                    }
                                } else {
                                    if (startingList.getValueForProbe(probes[p]) < startingList.getValueForProbe(lastValidProbe)) {
                                        lastValidProbe = probes[p];
                                    }
                                }
                            }
                            continue;
                        }
                    }
                }
                // last probe was overlapped.
                if (!(discardDuplicates & lastValidWasOverlapped)) {
                    newList.addProbe(lastValidProbe, startingList.getValueForProbe(lastValidProbe));
                }
                lastValidProbe = probes[p];
                lastValidWasOverlapped = false;
            }
        }
    }
    // Add the last stored probe
    if (lastValidProbe != null) {
        newList.addProbe(lastValidProbe, startingList.getValueForProbe(lastValidProbe));
    }
    if (useNames) {
        Iterator<String> it = probePrefixes.keySet().iterator();
        while (it.hasNext()) {
            String prefix = it.next();
            if (discardDuplicates && duplicatedProbePrefixes.contains(prefix)) {
                continue;
            }
            Probe p = probePrefixes.get(prefix);
            newList.addProbe(p, startingList.getValueForProbe(p));
        }
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) HashSet(java.util.HashSet)

Aggregations

ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)79 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)54 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)32 Vector (java.util.Vector)16 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)15 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)12 HashSet (java.util.HashSet)10 JLabel (javax.swing.JLabel)8 ProbeTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.ProbeTTestValue)8 GridBagConstraints (java.awt.GridBagConstraints)7 GridBagLayout (java.awt.GridBagLayout)7 File (java.io.File)7 JComboBox (javax.swing.JComboBox)7 JPanel (javax.swing.JPanel)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 PrintWriter (java.io.PrintWriter)6 JCheckBox (javax.swing.JCheckBox)6 ProgressRecordDialog (uk.ac.babraham.SeqMonk.Dialogs.ProgressRecordDialog)6 RProgressListener (uk.ac.babraham.SeqMonk.R.RProgressListener)6