*/
package jalview.api;
-import jalview.io.DataSourceType;
-
import java.util.List;
+import jalview.io.DataSourceType;
+
/**
* prototype abstract controller for a Jalview alignment view
*
boolean markHighlightedColumns(boolean invert, boolean extendCurrent,
boolean toggle);
+ /**
+ * copies each distinct highlighted region on the current view as a new
+ * sequence on the clipboard
+ *
+ * @return
+ */
+ boolean copyHighlightedRegionsToClipboard();
+
}
*/
package jalview.controller;
+import java.awt.Color;
+import java.util.BitSet;
+import java.util.List;
+
import jalview.analysis.AlignmentSorter;
import jalview.api.AlignViewControllerGuiI;
import jalview.api.AlignViewControllerI;
import jalview.commands.OrderCommand;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.gui.Desktop;
import jalview.io.DataSourceType;
import jalview.io.FeaturesFile;
import jalview.schemes.ColourSchemeI;
import jalview.util.MessageManager;
-import java.awt.Color;
-import java.util.BitSet;
-import java.util.List;
-
public class AlignViewController implements AlignViewControllerI
{
AlignViewportI viewport = null;
return false;
}
+ @Override
+ public boolean copyHighlightedRegionsToClipboard()
+ {
+ if (!viewport.hasSearchResults())
+ {
+ // do nothing if no selection exists
+ return false;
+ }
+
+ SearchResultsI searchResults = viewport.getSearchResults();
+ if (searchResults.isEmpty())
+ {
+ return false; // shouldn't happen
+ }
+ List<SequenceI> seqs = searchResults.getMatchingSubSequences();
+
+ // TODO: pass in hiddenColumns according to intersection of searchResults
+ // and visible columns. Currently this isn't done, since each contig becomes
+ // a single subsequence
+ Desktop.jalviewClipboard = new Object[] {
+ seqs.toArray(new SequenceI[0]),
+ alignPanel.getAlignment().getDataset(), null };
+ avcg.setStatus(MessageManager.formatMessage(
+ "label.copied_sequences_to_clipboard", seqs.size()));
+ // Technically we should return false, since view has not changed
+ return false;
+ }
}
{
matches.addAll(toAdd.getResults());
}
+
+ @Override
+ public List<SequenceI> getMatchingSubSequences()
+ {
+ List<SequenceI> seqs = new ArrayList<>();
+
+ /*
+ * assemble dataset sequences, and template new sequence features,
+ * for the amend features dialog
+ */
+ for (SearchResultMatchI match : matches)
+ {
+ SequenceI seq = match.getSequence();
+ while (seq.getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ // getSubSequence is index-base0, findIndex returns index-base1
+ seqs.add(seq.getSubSequence(seq.findIndex(match.getStart()) - 1,
+ seq.findIndex(match.getEnd())));
+ }
+ return seqs;
+ }
}
* @return number of bits set
*/
int markColumns(SequenceCollectionI sqcol, BitSet bs);
+
+ /**
+ * Return sub-sequences corresponding to distinct contiguous ranges in the
+ * matching set
+ *
+ * @return list of sequence objects
+ */
+ List<SequenceI> getMatchingSubSequences();
}
\ No newline at end of file
{
return; // shouldn't happen
}
- List<SequenceI> seqs = new ArrayList<>();
-
- String searchString = searchBox.getUserInput();
- String desc = "Search Results";
-
- /*
- * assemble dataset sequences, and template new sequence features,
- * for the amend features dialog
- */
- for (SearchResultMatchI match : searchResults.getResults())
- {
- SequenceI seq = match.getSequence();
- while (seq.getDatasetSequence() != null)
- {
- seq = seq.getDatasetSequence();
- }
- seqs.add(seq.getSubSequence(seq.findIndex(match.getStart()),
- seq.findIndex(match.getEnd()) + 1));
- }
- Desktop.jalviewClipboard = new Object[] {
- seqs.toArray(new SequenceI[0]), ap.av.getAlignment().getDataset(),
- ap.av.getAlignment().getHiddenColumns() };
+ // assume viewport controller has same searchResults as we do...
+ ap.alignFrame.avc.copyHighlightedRegionsToClipboard();
}
/**
import static org.testng.AssertJUnit.assertTrue;
import java.util.BitSet;
+import java.util.List;
import org.junit.Assert;
import org.testng.annotations.BeforeClass;
sr.addResult(cds2, 7, 9); // start-end overlap
assertTrue(sr.involvesSequence(cds2));
}
+
+ /**
+ * Test extraction of Sequence objects for matched ranges on a sequence
+ */
+ @Test(groups = { "Functional" })
+ public void testGetSequences()
+ {
+ SequenceI seq1 = new Sequence("", "abcdefghijklm");
+ SequenceI seq2 = new Sequence("", "nopqrstuvwxyz");
+ seq2.setStart(23);
+ seq2.setEnd(35);
+ List<SequenceI> seqres = null;
+
+ SearchResultsI sr = new SearchResults();
+ seqres = sr.getMatchingSubSequences();
+ assertEquals(0, seqres.size());
+
+ sr.addResult(seq1, 3, 5);
+ seqres = sr.getMatchingSubSequences();
+
+ assertEquals(1, seqres.size());
+ assertEquals("cde", seqres.get(0).getSequenceAsString());
+ assertEquals(3, seqres.get(0).getStart());
+ assertEquals(seq1, seqres.get(0).getDatasetSequence());
+
+ sr.addResult(seq1, 3, 6);
+ seqres = sr.getMatchingSubSequences();
+
+ assertEquals(2, seqres.size());
+ assertEquals("cdef", seqres.get(1).getSequenceAsString());
+ assertEquals(3, seqres.get(1).getStart());
+
+ // this is a quirk - match on 26-29 yields subsequence 27-30
+ sr.addResult(seq2, 26, 29);
+ seqres = sr.getMatchingSubSequences();
+ assertEquals(3, seqres.size());
+ assertEquals("qrst", seqres.get(2).getSequenceAsString());
+ assertEquals(26, seqres.get(2).getStart());
+ }
+
}