Search in sources :

Example 1 with FeatureListViewer

use of uk.ac.babraham.SeqMonk.Displays.FeatureListViewer.FeatureListViewer in project SeqMonk by s-andrews.

the class FindFeaturesByNameDialog method makeFeatureList.

/**
 * Make feature list.
 */
private void makeFeatureList() {
    if (scroll != null) {
        remove(scroll);
        validate();
    }
    Vector<Feature> hits = new Vector<Feature>();
    // Make up a hash of names against which we can check
    HashSet<String> queries = new HashSet<String>();
    String[] inputTerms = search.getText().toLowerCase().split("\n");
    for (int i = 0; i < inputTerms.length; i++) {
        if (inputTerms[i].trim().length() == 0)
            continue;
        queries.add(inputTerms[i].trim());
    }
    String[] types;
    if (featureType.getSelectedItem().equals("all")) {
        types = collection.listAvailableFeatureTypes();
    } else {
        types = new String[] { (String) featureType.getSelectedItem() };
    }
    // Remember the type of feature so we use the same one next time
    FindFeaturesByNameDialog.lastSearchedType = (String) featureType.getSelectedItem();
    for (int j = 0; j < types.length; j++) {
        Feature[] f = collection.getFeaturesForType(types[j]);
        for (int k = 0; k < f.length; k++) {
            if (cancelSearch) {
                spd.progressCancelled();
                cancelSearch = false;
                return;
            }
            spd.progressUpdated("Searching...", (j * f.length) + k, types.length * f.length);
            if (queries.contains(f[k].name().toLowerCase()) || queries.contains(f[k].id().toLowerCase())) {
                hits.add(f[k]);
                continue;
            }
        }
    }
    lastHits = hits.toArray(new Feature[0]);
    setTitle("Find named features [" + lastHits.length + " hits]");
    saveAllHitsAsTrackButton.setEnabled(lastHits.length > 0);
    saveSelectedHitsAsTrackButton.setEnabled(lastHits.length > 0);
    spd.progressComplete("search_features", lastHits);
    if (hits.size() > 0) {
        viewer = new FeatureListViewer(lastHits);
        scroll = new JScrollPane(viewer);
        add(scroll, BorderLayout.CENTER);
        validate();
    } else {
        // So we aren't left with a corrupted table showing from a previous search
        repaint();
        JOptionPane.showMessageDialog(this, "No hits found", "Search results", JOptionPane.INFORMATION_MESSAGE);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature) Vector(java.util.Vector) FeatureListViewer(uk.ac.babraham.SeqMonk.Displays.FeatureListViewer.FeatureListViewer) HashSet(java.util.HashSet)

Example 2 with FeatureListViewer

use of uk.ac.babraham.SeqMonk.Displays.FeatureListViewer.FeatureListViewer in project SeqMonk by s-andrews.

the class FindFeatureDialog method makeFeatureList.

/**
 * Make feature list.
 */
private void makeFeatureList() {
    if (scroll != null) {
        remove(scroll);
        validate();
    }
    Vector<Feature> hits = new Vector<Feature>();
    String query = search.getText().toLowerCase().trim();
    boolean searchAll = false;
    if (((String) searchIn.getSelectedItem()).equals("all")) {
        searchAll = true;
        // Remember this for the next search
        FindFeatureDialog.searchAll = true;
    } else {
        // Remember this for the next search
        FindFeatureDialog.searchAll = false;
    }
    String[] types;
    if (featureType.getSelectedItem().equals("all")) {
        types = collection.listAvailableFeatureTypes();
    } else {
        types = new String[] { (String) featureType.getSelectedItem() };
    }
    // Remember the type of feature so we use the same one next time
    FindFeatureDialog.lastSearchedType = (String) featureType.getSelectedItem();
    for (int j = 0; j < types.length; j++) {
        Feature[] f = collection.getFeaturesForType(types[j]);
        for (int k = 0; k < f.length; k++) {
            if (cancelSearch) {
                spd.progressCancelled();
                cancelSearch = false;
                return;
            }
            spd.progressUpdated("Searching...", (j * f.length) + k, types.length * f.length);
            if (f[k].name().toLowerCase().indexOf(query) >= 0) {
                hits.add(f[k]);
                continue;
            }
            if (searchAll) {
                if (f[k].getAllAnnotation().toLowerCase().indexOf(query) >= 0) {
                    hits.add(f[k]);
                }
            }
        }
    }
    lastHits = hits.toArray(new Feature[0]);
    setTitle("Find features [" + lastHits.length + " hits]");
    saveAllHitsAsTrackButton.setEnabled(lastHits.length > 0);
    saveSelectedHitsAsTrackButton.setEnabled(lastHits.length > 0);
    spd.progressComplete("search_features", lastHits);
    if (hits.size() > 0) {
        viewer = new FeatureListViewer(lastHits);
        scroll = new JScrollPane(viewer);
        add(scroll, BorderLayout.CENTER);
        validate();
    } else {
        // So we aren't left with a corrupted table showing from a previous search
        repaint();
        JOptionPane.showMessageDialog(this, "No hits found", "Search results", JOptionPane.INFORMATION_MESSAGE);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature) Vector(java.util.Vector) FeatureListViewer(uk.ac.babraham.SeqMonk.Displays.FeatureListViewer.FeatureListViewer)

Aggregations

Vector (java.util.Vector)2 JScrollPane (javax.swing.JScrollPane)2 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)2 FeatureListViewer (uk.ac.babraham.SeqMonk.Displays.FeatureListViewer.FeatureListViewer)2 HashSet (java.util.HashSet)1