Merge branch 'develop' into trialMerge
[jalview.git] / test / jalview / util / MappingUtilsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertSame;
26 import static org.testng.AssertJUnit.assertTrue;
27
28 import jalview.api.AlignViewportI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.commands.EditCommand.Edit;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.ColumnSelection;
36 import jalview.datamodel.SearchResultMatchI;
37 import jalview.datamodel.SearchResultsI;
38 import jalview.datamodel.Sequence;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.gui.AlignViewport;
42 import jalview.io.DataSourceType;
43 import jalview.io.FileFormat;
44 import jalview.io.FileFormatI;
45 import jalview.io.FormatAdapter;
46
47 import java.awt.Color;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.List;
52
53 import org.testng.annotations.Test;
54
55 public class MappingUtilsTest
56 {
57   private AlignViewportI dnaView;
58
59   private AlignViewportI proteinView;
60
61   /**
62    * Simple test of mapping with no intron involved.
63    */
64   @Test(groups = { "Functional" })
65   public void testBuildSearchResults()
66   {
67     final Sequence seq1 = new Sequence("Seq1/5-10", "C-G-TA-GC");
68     seq1.createDatasetSequence();
69
70     final Sequence aseq1 = new Sequence("Seq1/12-13", "-P-R");
71     aseq1.createDatasetSequence();
72
73     /*
74      * Map dna bases 5-10 to protein residues 12-13
75      */
76     AlignedCodonFrame acf = new AlignedCodonFrame();
77     MapList map = new MapList(new int[] { 5, 10 }, new int[] { 12, 13 }, 3,
78             1);
79     acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
80     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
81     { acf });
82
83     /*
84      * Check protein residue 12 maps to codon 5-7, 13 to codon 8-10
85      */
86     SearchResultsI sr = MappingUtils.buildSearchResults(aseq1, 12, acfList);
87     assertEquals(1, sr.getResults().size());
88     SearchResultMatchI m = sr.getResults().get(0);
89     assertEquals(seq1.getDatasetSequence(), m.getSequence());
90     assertEquals(5, m.getStart());
91     assertEquals(7, m.getEnd());
92     sr = MappingUtils.buildSearchResults(aseq1, 13, acfList);
93     assertEquals(1, sr.getResults().size());
94     m = sr.getResults().get(0);
95     assertEquals(seq1.getDatasetSequence(), m.getSequence());
96     assertEquals(8, m.getStart());
97     assertEquals(10, m.getEnd());
98
99     /*
100      * Check inverse mappings, from codons 5-7, 8-10 to protein 12, 13
101      */
102     for (int i = 5; i < 11; i++)
103     {
104       sr = MappingUtils.buildSearchResults(seq1, i, acfList);
105       assertEquals(1, sr.getResults().size());
106       m = sr.getResults().get(0);
107       assertEquals(aseq1.getDatasetSequence(), m.getSequence());
108       int residue = i > 7 ? 13 : 12;
109       assertEquals(residue, m.getStart());
110       assertEquals(residue, m.getEnd());
111     }
112   }
113
114   /**
115    * Simple test of mapping with introns involved.
116    */
117   @Test(groups = { "Functional" })
118   public void testBuildSearchResults_withIntron()
119   {
120     final Sequence seq1 = new Sequence("Seq1/5-17", "c-G-tAGa-GcAgCtt");
121     seq1.createDatasetSequence();
122
123     final Sequence aseq1 = new Sequence("Seq1/8-9", "-E-D");
124     aseq1.createDatasetSequence();
125
126     /*
127      * Map dna bases [6, 8, 9], [11, 13, 115] to protein residues 8 and 9
128      */
129     AlignedCodonFrame acf = new AlignedCodonFrame();
130     MapList map = new MapList(new int[] { 6, 6, 8, 9, 11, 11, 13, 13, 15,
131         15 }, new int[] { 8, 9 }, 3, 1);
132     acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
133     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
134     { acf });
135
136     /*
137      * Check protein residue 8 maps to [6, 8, 9]
138      */
139     SearchResultsI sr = MappingUtils.buildSearchResults(aseq1, 8, acfList);
140     assertEquals(2, sr.getResults().size());
141     SearchResultMatchI m = sr.getResults().get(0);
142     assertEquals(seq1.getDatasetSequence(), m.getSequence());
143     assertEquals(6, m.getStart());
144     assertEquals(6, m.getEnd());
145     m = sr.getResults().get(1);
146     assertEquals(seq1.getDatasetSequence(), m.getSequence());
147     assertEquals(8, m.getStart());
148     assertEquals(9, m.getEnd());
149
150     /*
151      * Check protein residue 9 maps to [11, 13, 15]
152      */
153     sr = MappingUtils.buildSearchResults(aseq1, 9, acfList);
154     assertEquals(3, sr.getResults().size());
155     m = sr.getResults().get(0);
156     assertEquals(seq1.getDatasetSequence(), m.getSequence());
157     assertEquals(11, m.getStart());
158     assertEquals(11, m.getEnd());
159     m = sr.getResults().get(1);
160     assertEquals(seq1.getDatasetSequence(), m.getSequence());
161     assertEquals(13, m.getStart());
162     assertEquals(13, m.getEnd());
163     m = sr.getResults().get(2);
164     assertEquals(seq1.getDatasetSequence(), m.getSequence());
165     assertEquals(15, m.getStart());
166     assertEquals(15, m.getEnd());
167
168     /*
169      * Check inverse mappings, from codons to protein
170      */
171     for (int i = 5; i < 18; i++)
172     {
173       sr = MappingUtils.buildSearchResults(seq1, i, acfList);
174       int residue = (i == 6 || i == 8 || i == 9) ? 8 : (i == 11 || i == 13
175               || i == 15 ? 9 : 0);
176       if (residue == 0)
177       {
178         assertEquals(0, sr.getResults().size());
179         continue;
180       }
181       assertEquals(1, sr.getResults().size());
182       m = sr.getResults().get(0);
183       assertEquals(aseq1.getDatasetSequence(), m.getSequence());
184       assertEquals(residue, m.getStart());
185       assertEquals(residue, m.getEnd());
186     }
187   }
188
189   /**
190    * Test mapping a sequence group made of entire sequences.
191    * 
192    * @throws IOException
193    */
194   @Test(groups = { "Functional" })
195   public void testMapSequenceGroup_sequences() throws IOException
196   {
197     /*
198      * Set up dna and protein Seq1/2/3 with mappings (held on the protein
199      * viewport).
200      */
201     AlignmentI cdna = loadAlignment(">Seq1\nACG\n>Seq2\nTGA\n>Seq3\nTAC\n",
202             FileFormat.Fasta);
203     cdna.setDataset(null);
204     AlignmentI protein = loadAlignment(">Seq1\nK\n>Seq2\nL\n>Seq3\nQ\n",
205             FileFormat.Fasta);
206     protein.setDataset(null);
207     AlignedCodonFrame acf = new AlignedCodonFrame();
208     MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 3, 1);
209     for (int seq = 0; seq < 3; seq++)
210     {
211       acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
212               .getSequenceAt(seq).getDatasetSequence(), map);
213     }
214     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
215     { acf });
216
217     AlignViewportI dnaView = new AlignViewport(cdna);
218     AlignViewportI proteinView = new AlignViewport(protein);
219     protein.setCodonFrames(acfList);
220
221     /*
222      * Select Seq1 and Seq3 in the protein (startRes=endRes=0)
223      */
224     SequenceGroup sg = new SequenceGroup();
225     sg.setColourText(true);
226     sg.setIdColour(Color.GREEN);
227     sg.setOutlineColour(Color.LIGHT_GRAY);
228     sg.addSequence(protein.getSequenceAt(0), false);
229     sg.addSequence(protein.getSequenceAt(2), false);
230
231     /*
232      * Verify the mapped sequence group in dna
233      */
234     SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg,
235             proteinView, dnaView);
236     assertTrue(mappedGroup.getColourText());
237     assertSame(sg.getIdColour(), mappedGroup.getIdColour());
238     assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour());
239     assertEquals(2, mappedGroup.getSequences().size());
240     assertSame(cdna.getSequenceAt(0), mappedGroup.getSequences().get(0));
241     assertSame(cdna.getSequenceAt(2), mappedGroup.getSequences().get(1));
242     assertEquals(0, mappedGroup.getStartRes());
243     assertEquals(2, mappedGroup.getEndRes());
244
245     /*
246      * Verify mapping sequence group from dna to protein
247      */
248     sg.clear();
249     sg.addSequence(cdna.getSequenceAt(1), false);
250     sg.addSequence(cdna.getSequenceAt(0), false);
251     sg.setStartRes(0);
252     sg.setEndRes(2);
253     mappedGroup = MappingUtils.mapSequenceGroup(sg, dnaView, proteinView);
254     assertTrue(mappedGroup.getColourText());
255     assertSame(sg.getIdColour(), mappedGroup.getIdColour());
256     assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour());
257     assertEquals(2, mappedGroup.getSequences().size());
258     assertSame(protein.getSequenceAt(1), mappedGroup.getSequences().get(0));
259     assertSame(protein.getSequenceAt(0), mappedGroup.getSequences().get(1));
260     assertEquals(0, mappedGroup.getStartRes());
261     assertEquals(0, mappedGroup.getEndRes());
262   }
263
264   /**
265    * Helper method to load an alignment and ensure dataset sequences are set up.
266    * 
267    * @param data
268    * @param format
269    *          TODO
270    * @return
271    * @throws IOException
272    */
273   protected AlignmentI loadAlignment(final String data, FileFormatI format)
274           throws IOException
275   {
276     AlignmentI a = new FormatAdapter().readFile(data,
277             DataSourceType.PASTE, format);
278     a.setDataset(null);
279     return a;
280   }
281
282   /**
283    * Test mapping a column selection in protein to its dna equivalent
284    * 
285    * @throws IOException
286    */
287   @Test(groups = { "Functional" })
288   public void testMapColumnSelection_proteinToDna() throws IOException
289   {
290     setupMappedAlignments();
291
292     ColumnSelection colsel = new ColumnSelection();
293
294     /*
295      * Column 0 in protein picks up Seq2/L, Seq3/G which map to cols 0-4 and 0-3
296      * in dna respectively, overall 0-4
297      */
298     colsel.addElement(0);
299     ColumnSelection cs = MappingUtils.mapColumnSelection(colsel,
300             proteinView, dnaView);
301     assertEquals("[0, 1, 2, 3, 4]", cs.getSelected().toString());
302
303     /*
304      * Column 1 in protein picks up Seq1/K which maps to cols 0-3 in dna
305      */
306     colsel.clear();
307     colsel.addElement(1);
308     cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView);
309     assertEquals("[0, 1, 2, 3]", cs.getSelected().toString());
310
311     /*
312      * Column 2 in protein picks up gaps only - no mapping
313      */
314     colsel.clear();
315     colsel.addElement(2);
316     cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView);
317     assertEquals("[]", cs.getSelected().toString());
318
319     /*
320      * Column 3 in protein picks up Seq1/P, Seq2/Q, Seq3/S which map to columns
321      * 6-9, 6-10, 5-8 respectively, overall to 5-10
322      */
323     colsel.clear();
324     colsel.addElement(3);
325     cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView);
326     assertEquals("[5, 6, 7, 8, 9, 10]", cs.getSelected().toString());
327
328     /*
329      * Combine selection of columns 1 and 3 to get a discontiguous mapped
330      * selection
331      */
332     colsel.clear();
333     colsel.addElement(1);
334     colsel.addElement(3);
335     cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView);
336     assertEquals("[0, 1, 2, 3, 5, 6, 7, 8, 9, 10]", cs.getSelected()
337             .toString());
338   }
339
340   /**
341    * Set up mappings for tests from 3 dna to 3 protein sequences. Sequences have
342    * offset start positions for a more general test case.
343    * 
344    * @throws IOException
345    */
346   protected void setupMappedAlignments() throws IOException
347   {
348     /*
349      * Map (upper-case = coding):
350      * Seq1/10-18 AC-GctGtC-T to Seq1/40 -K-P
351      * Seq2/20-27 Tc-GA-G-T-T to Seq2/20-27 L--Q
352      * Seq3/30-38 TtTT-AaCGg- to Seq3/60-61\nG--S
353      */
354     AlignmentI cdna = loadAlignment(">Seq1/10-18\nAC-GctGtC-T\n"
355             + ">Seq2/20-27\nTc-GA-G-T-Tc\n" + ">Seq3/30-38\nTtTT-AaCGg-\n",
356             FileFormat.Fasta);
357     cdna.setDataset(null);
358     AlignmentI protein = loadAlignment(
359             ">Seq1/40-41\n-K-P\n>Seq2/50-51\nL--Q\n>Seq3/60-61\nG--S\n",
360             FileFormat.Fasta);
361     protein.setDataset(null);
362
363     // map first dna to first protein seq
364     AlignedCodonFrame acf = new AlignedCodonFrame();
365     MapList map = new MapList(new int[] { 10, 12, 15, 15, 17, 18 },
366             new int[] { 40, 41 }, 3, 1);
367     acf.addMap(cdna.getSequenceAt(0).getDatasetSequence(), protein
368             .getSequenceAt(0).getDatasetSequence(), map);
369
370     // map second dna to second protein seq
371     map = new MapList(new int[] { 20, 20, 22, 23, 24, 26 }, new int[] { 50,
372         51 }, 3, 1);
373     acf.addMap(cdna.getSequenceAt(1).getDatasetSequence(), protein
374             .getSequenceAt(1).getDatasetSequence(), map);
375
376     // map third dna to third protein seq
377     map = new MapList(new int[] { 30, 30, 32, 34, 36, 37 }, new int[] { 60,
378         61 }, 3, 1);
379     acf.addMap(cdna.getSequenceAt(2).getDatasetSequence(), protein
380             .getSequenceAt(2).getDatasetSequence(), map);
381     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
382     { acf });
383
384     dnaView = new AlignViewport(cdna);
385     proteinView = new AlignViewport(protein);
386     protein.setCodonFrames(acfList);
387   }
388
389   /**
390    * Test mapping a column selection in dna to its protein equivalent
391    * 
392    * @throws IOException
393    */
394   @Test(groups = { "Functional" })
395   public void testMapColumnSelection_dnaToProtein() throws IOException
396   {
397     setupMappedAlignments();
398
399     ColumnSelection colsel = new ColumnSelection();
400
401     /*
402      * Column 0 in dna picks up first bases which map to residue 1, columns 0-1
403      * in protein.
404      */
405     colsel.addElement(0);
406     ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, dnaView,
407             proteinView);
408     assertEquals("[0, 1]", cs.getSelected().toString());
409
410     /*
411      * Columns 3-5 in dna map to the first residues in protein Seq1, Seq2, and
412      * the first two in Seq3. Overall to columns 0, 1, 3 (col2 is all gaps).
413      */
414     colsel.addElement(3);
415     colsel.addElement(4);
416     colsel.addElement(5);
417     cs = MappingUtils.mapColumnSelection(colsel, dnaView, proteinView);
418     assertEquals("[0, 1, 3]", cs.getSelected().toString());
419   }
420
421   @Test(groups = { "Functional" })
422   public void testMapColumnSelection_null() throws IOException
423   {
424     setupMappedAlignments();
425     ColumnSelection cs = MappingUtils.mapColumnSelection(null, dnaView,
426             proteinView);
427     assertTrue("mapped selection not empty", cs.getSelected().isEmpty());
428   }
429
430   /**
431    * Tests for the method that converts a series of [start, end] ranges to
432    * single positions
433    */
434   @Test(groups = { "Functional" })
435   public void testFlattenRanges()
436   {
437     assertEquals("[1, 2, 3, 4]",
438             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4 })));
439     assertEquals(
440             "[1, 2, 3, 4]",
441             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 2, 3,
442                 4 })));
443     assertEquals(
444             "[1, 2, 3, 4]",
445             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 1, 2,
446                 2, 3, 3, 4, 4 })));
447     assertEquals(
448             "[1, 2, 3, 4, 7, 8, 9, 12]",
449             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
450                 9, 12, 12 })));
451     // trailing unpaired start position is ignored:
452     assertEquals(
453             "[1, 2, 3, 4, 7, 8, 9, 12]",
454             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
455                 9, 12, 12, 15 })));
456   }
457
458   /**
459    * Test mapping a sequence group made of entire columns.
460    * 
461    * @throws IOException
462    */
463   @Test(groups = { "Functional" })
464   public void testMapSequenceGroup_columns() throws IOException
465   {
466     /*
467      * Set up dna and protein Seq1/2/3 with mappings (held on the protein
468      * viewport).
469      */
470     AlignmentI cdna = loadAlignment(
471             ">Seq1\nACGGCA\n>Seq2\nTGACAG\n>Seq3\nTACGTA\n",
472             FileFormat.Fasta);
473     cdna.setDataset(null);
474     AlignmentI protein = loadAlignment(">Seq1\nKA\n>Seq2\nLQ\n>Seq3\nQV\n",
475             FileFormat.Fasta);
476     protein.setDataset(null);
477     AlignedCodonFrame acf = new AlignedCodonFrame();
478     MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1);
479     for (int seq = 0; seq < 3; seq++)
480     {
481       acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
482               .getSequenceAt(seq).getDatasetSequence(), map);
483     }
484     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
485     { acf });
486
487     AlignViewportI dnaView = new AlignViewport(cdna);
488     AlignViewportI proteinView = new AlignViewport(protein);
489     protein.setCodonFrames(acfList);
490
491     /*
492      * Select all sequences, column 2 in the protein
493      */
494     SequenceGroup sg = new SequenceGroup();
495     sg.setColourText(true);
496     sg.setIdColour(Color.GREEN);
497     sg.setOutlineColour(Color.LIGHT_GRAY);
498     sg.addSequence(protein.getSequenceAt(0), false);
499     sg.addSequence(protein.getSequenceAt(1), false);
500     sg.addSequence(protein.getSequenceAt(2), false);
501     sg.setStartRes(1);
502     sg.setEndRes(1);
503
504     /*
505      * Verify the mapped sequence group in dna
506      */
507     SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg,
508             proteinView, dnaView);
509     assertTrue(mappedGroup.getColourText());
510     assertSame(sg.getIdColour(), mappedGroup.getIdColour());
511     assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour());
512     assertEquals(3, mappedGroup.getSequences().size());
513     assertSame(cdna.getSequenceAt(0), mappedGroup.getSequences().get(0));
514     assertSame(cdna.getSequenceAt(1), mappedGroup.getSequences().get(1));
515     assertSame(cdna.getSequenceAt(2), mappedGroup.getSequences().get(2));
516     assertEquals(3, mappedGroup.getStartRes());
517     assertEquals(5, mappedGroup.getEndRes());
518
519     /*
520      * Verify mapping sequence group from dna to protein
521      */
522     sg.clear();
523     sg.addSequence(cdna.getSequenceAt(0), false);
524     sg.addSequence(cdna.getSequenceAt(1), false);
525     sg.addSequence(cdna.getSequenceAt(2), false);
526     // select columns 2 and 3 in DNA which span protein columns 0 and 1
527     sg.setStartRes(2);
528     sg.setEndRes(3);
529     mappedGroup = MappingUtils.mapSequenceGroup(sg, dnaView, proteinView);
530     assertTrue(mappedGroup.getColourText());
531     assertSame(sg.getIdColour(), mappedGroup.getIdColour());
532     assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour());
533     assertEquals(3, mappedGroup.getSequences().size());
534     assertSame(protein.getSequenceAt(0), mappedGroup.getSequences().get(0));
535     assertSame(protein.getSequenceAt(1), mappedGroup.getSequences().get(1));
536     assertSame(protein.getSequenceAt(2), mappedGroup.getSequences().get(2));
537     assertEquals(0, mappedGroup.getStartRes());
538     assertEquals(1, mappedGroup.getEndRes());
539   }
540
541   /**
542    * Test mapping a sequence group made of a sequences/columns region.
543    * 
544    * @throws IOException
545    */
546   @Test(groups = { "Functional" })
547   public void testMapSequenceGroup_region() throws IOException
548   {
549     /*
550      * Set up gapped dna and protein Seq1/2/3 with mappings (held on the protein
551      * viewport).
552      */
553     AlignmentI cdna = loadAlignment(
554             ">Seq1\nA-CG-GC--AT-CA\n>Seq2\n-TG-AC-AG-T-AT\n>Seq3\n-T--ACG-TAAT-G\n",
555             FileFormat.Fasta);
556     cdna.setDataset(null);
557     AlignmentI protein = loadAlignment(
558             ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", FileFormat.Fasta);
559     protein.setDataset(null);
560     AlignedCodonFrame acf = new AlignedCodonFrame();
561     MapList map = new MapList(new int[] { 1, 9 }, new int[] { 1, 3 }, 3, 1);
562     for (int seq = 0; seq < 3; seq++)
563     {
564       acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
565               .getSequenceAt(seq).getDatasetSequence(), map);
566     }
567     List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
568     { acf });
569
570     AlignViewportI dnaView = new AlignViewport(cdna);
571     AlignViewportI proteinView = new AlignViewport(protein);
572     protein.setCodonFrames(acfList);
573
574     /*
575      * Select Seq1 and Seq2 in the protein, column 1 (K/-). Expect mapped
576      * sequence group to cover Seq1, columns 0-3 (ACG). Because the selection
577      * only includes a gap in Seq2 there is no mappable selection region in the
578      * corresponding DNA.
579      */
580     SequenceGroup sg = new SequenceGroup();
581     sg.setColourText(true);
582     sg.setIdColour(Color.GREEN);
583     sg.setOutlineColour(Color.LIGHT_GRAY);
584     sg.addSequence(protein.getSequenceAt(0), false);
585     sg.addSequence(protein.getSequenceAt(1), false);
586     sg.setStartRes(1);
587     sg.setEndRes(1);
588
589     /*
590      * Verify the mapped sequence group in dna
591      */
592     SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg,
593             proteinView, dnaView);
594     assertTrue(mappedGroup.getColourText());
595     assertSame(sg.getIdColour(), mappedGroup.getIdColour());
596     assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour());
597     assertEquals(1, mappedGroup.getSequences().size());
598     assertSame(cdna.getSequenceAt(0), mappedGroup.getSequences().get(0));
599     // Seq2 in protein has a gap in column 1 - ignored
600     // Seq1 has K which should map to columns 0-3 in Seq1
601     assertEquals(0, mappedGroup.getStartRes());
602     assertEquals(3, mappedGroup.getEndRes());
603
604     /*
605      * Now select cols 2-4 in protein. These cover Seq1:AS Seq2:LQ Seq3:VM which
606      * extend over DNA columns 3-12, 1-7, 6-13 respectively, or 1-13 overall.
607      */
608     sg.setStartRes(2);
609     sg.setEndRes(4);
610     mappedGroup = MappingUtils.mapSequenceGroup(sg, proteinView, dnaView);
611     assertEquals(1, mappedGroup.getStartRes());
612     assertEquals(13, mappedGroup.getEndRes());
613
614     /*
615      * Verify mapping sequence group from dna to protein
616      */
617     sg.clear();
618     sg.addSequence(cdna.getSequenceAt(0), false);
619
620     // select columns 4,5 - includes Seq1:codon2 (A) only
621     sg.setStartRes(4);
622     sg.setEndRes(5);
623     mappedGroup = MappingUtils.mapSequenceGroup(sg, dnaView, proteinView);
624     assertEquals(2, mappedGroup.getStartRes());
625     assertEquals(2, mappedGroup.getEndRes());
626
627     // add Seq2 to dna selection cols 4-5 include codons 1 and 2 (LQ)
628     sg.addSequence(cdna.getSequenceAt(1), false);
629     mappedGroup = MappingUtils.mapSequenceGroup(sg, dnaView, proteinView);
630     assertEquals(2, mappedGroup.getStartRes());
631     assertEquals(4, mappedGroup.getEndRes());
632
633     // add Seq3 to dna selection cols 4-5 include codon 1 (Q)
634     sg.addSequence(cdna.getSequenceAt(2), false);
635     mappedGroup = MappingUtils.mapSequenceGroup(sg, dnaView, proteinView);
636     assertEquals(0, mappedGroup.getStartRes());
637     assertEquals(4, mappedGroup.getEndRes());
638   }
639
640   @Test(groups = { "Functional" })
641   public void testFindMappingsForSequence()
642   {
643     SequenceI seq1 = new Sequence("Seq1", "ABC");
644     SequenceI seq2 = new Sequence("Seq2", "ABC");
645     SequenceI seq3 = new Sequence("Seq3", "ABC");
646     SequenceI seq4 = new Sequence("Seq4", "ABC");
647     seq1.createDatasetSequence();
648     seq2.createDatasetSequence();
649     seq3.createDatasetSequence();
650     seq4.createDatasetSequence();
651
652     /*
653      * Create mappings from seq1 to seq2, seq2 to seq1, seq3 to seq1
654      */
655     AlignedCodonFrame acf1 = new AlignedCodonFrame();
656     MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1);
657     acf1.addMap(seq1.getDatasetSequence(), seq2.getDatasetSequence(), map);
658     AlignedCodonFrame acf2 = new AlignedCodonFrame();
659     acf2.addMap(seq2.getDatasetSequence(), seq1.getDatasetSequence(), map);
660     AlignedCodonFrame acf3 = new AlignedCodonFrame();
661     acf3.addMap(seq3.getDatasetSequence(), seq1.getDatasetSequence(), map);
662
663     List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
664     mappings.add(acf1);
665     mappings.add(acf2);
666     mappings.add(acf3);
667
668     /*
669      * Seq1 has three mappings
670      */
671     List<AlignedCodonFrame> result = MappingUtils.findMappingsForSequence(
672             seq1, mappings);
673     assertEquals(3, result.size());
674     assertTrue(result.contains(acf1));
675     assertTrue(result.contains(acf2));
676     assertTrue(result.contains(acf3));
677
678     /*
679      * Seq2 has two mappings
680      */
681     result = MappingUtils.findMappingsForSequence(seq2, mappings);
682     assertEquals(2, result.size());
683     assertTrue(result.contains(acf1));
684     assertTrue(result.contains(acf2));
685
686     /*
687      * Seq3 has one mapping
688      */
689     result = MappingUtils.findMappingsForSequence(seq3, mappings);
690     assertEquals(1, result.size());
691     assertTrue(result.contains(acf3));
692
693     /*
694      * Seq4 has no mappings
695      */
696     result = MappingUtils.findMappingsForSequence(seq4, mappings);
697     assertEquals(0, result.size());
698
699     result = MappingUtils.findMappingsForSequence(null, mappings);
700     assertEquals(0, result.size());
701
702     result = MappingUtils.findMappingsForSequence(seq1, null);
703     assertEquals(0, result.size());
704
705     result = MappingUtils.findMappingsForSequence(null, null);
706     assertEquals(0, result.size());
707   }
708
709   /**
710    * just like the one above, but this time, we provide a set of sequences to
711    * subselect the mapping search
712    */
713   @Test(groups = { "Functional" })
714   public void testFindMappingsForSequenceAndOthers()
715   {
716     SequenceI seq1 = new Sequence("Seq1", "ABC");
717     SequenceI seq2 = new Sequence("Seq2", "ABC");
718     SequenceI seq3 = new Sequence("Seq3", "ABC");
719     SequenceI seq4 = new Sequence("Seq4", "ABC");
720     seq1.createDatasetSequence();
721     seq2.createDatasetSequence();
722     seq3.createDatasetSequence();
723     seq4.createDatasetSequence();
724
725     /*
726      * Create mappings from seq1 to seq2, seq2 to seq1, seq3 to seq1, seq3 to seq4
727      */
728     AlignedCodonFrame acf1 = new AlignedCodonFrame();
729     MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1);
730     acf1.addMap(seq1.getDatasetSequence(), seq2.getDatasetSequence(), map);
731     AlignedCodonFrame acf2 = new AlignedCodonFrame();
732     acf2.addMap(seq2.getDatasetSequence(), seq1.getDatasetSequence(), map);
733     AlignedCodonFrame acf3 = new AlignedCodonFrame();
734     acf3.addMap(seq3.getDatasetSequence(), seq1.getDatasetSequence(), map);
735     AlignedCodonFrame acf4 = new AlignedCodonFrame();
736     acf4.addMap(seq3.getDatasetSequence(), seq4.getDatasetSequence(), map);
737
738     List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
739     mappings.add(acf1);
740     mappings.add(acf2);
741     mappings.add(acf3);
742     mappings.add(acf4);
743
744     /*
745      * test for null args
746      */
747     List<AlignedCodonFrame> result = MappingUtils
748             .findMappingsForSequenceAndOthers(null, mappings,
749                     Arrays.asList(new SequenceI[] { seq1, seq2 }));
750     assertTrue(result.isEmpty());
751
752     result = MappingUtils.findMappingsForSequenceAndOthers(seq1, null,
753             Arrays.asList(new SequenceI[] { seq1, seq2 }));
754     assertTrue(result.isEmpty());
755
756     /*
757      * Seq1 has three mappings, but filter argument will only accept
758      * those to seq2
759      */
760     result = MappingUtils.findMappingsForSequenceAndOthers(
761             seq1,
762             mappings,
763             Arrays.asList(new SequenceI[] { seq1, seq2,
764                 seq1.getDatasetSequence() }));
765     assertEquals(2, result.size());
766     assertTrue(result.contains(acf1));
767     assertTrue(result.contains(acf2));
768     assertFalse("Did not expect to find mapping acf3 - subselect failed",
769             result.contains(acf3));
770     assertFalse(
771             "Did not expect to find mapping acf4 - doesn't involve sequence",
772             result.contains(acf4));
773
774     /*
775      * and verify the no filter case
776      */
777     result = MappingUtils.findMappingsForSequenceAndOthers(seq1, mappings,
778             null);
779     assertEquals(3, result.size());
780     assertTrue(result.contains(acf1));
781     assertTrue(result.contains(acf2));
782     assertTrue(result.contains(acf3));
783   }
784
785   @Test(groups = { "Functional" })
786   public void testMapEditCommand()
787   {
788     SequenceI dna = new Sequence("Seq1", "---ACG---GCATCA", 8, 16);
789     SequenceI protein = new Sequence("Seq2", "-T-AS", 5, 7);
790     dna.createDatasetSequence();
791     protein.createDatasetSequence();
792     AlignedCodonFrame acf = new AlignedCodonFrame();
793     MapList map = new MapList(new int[] { 8, 16 }, new int[] { 5, 7 }, 3, 1);
794     acf.addMap(dna.getDatasetSequence(), protein.getDatasetSequence(), map);
795     List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
796     mappings.add(acf);
797
798     AlignmentI prot = new Alignment(new SequenceI[] { protein });
799     prot.setCodonFrames(mappings);
800     AlignmentI nuc = new Alignment(new SequenceI[] { dna });
801
802     /*
803      * construct and perform the edit command to turn "-T-AS" in to "-T-A--S"
804      * i.e. insert two gaps at column 4
805      */
806     EditCommand ec = new EditCommand();
807     final Edit edit = ec.new Edit(Action.INSERT_GAP,
808             new SequenceI[] { protein }, 4, 2, '-');
809     ec.appendEdit(edit, prot, true, null);
810
811     /*
812      * the mapped edit command should be to insert 6 gaps before base 4 in the
813      * nucleotide sequence, which corresponds to aligned column 12 in the dna
814      */
815     EditCommand mappedEdit = MappingUtils.mapEditCommand(ec, false, nuc,
816             '-', mappings);
817     assertEquals(1, mappedEdit.getEdits().size());
818     Edit e = mappedEdit.getEdits().get(0);
819     assertEquals(1, e.getSequences().length);
820     assertEquals(dna, e.getSequences()[0]);
821     assertEquals(12, e.getPosition());
822     assertEquals(6, e.getNumber());
823   }
824
825   /**
826    * Tests for the method that converts a series of [start, end] ranges to
827    * single positions, where the mapping is to a reverse strand i.e. start is
828    * greater than end point mapped to
829    */
830   @Test(groups = { "Functional" })
831   public void testFlattenRanges_reverseStrand()
832   {
833     assertEquals("[4, 3, 2, 1]",
834             Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 1 })));
835     assertEquals(
836             "[4, 3, 2, 1]",
837             Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 3, 2,
838                 1 })));
839     assertEquals(
840             "[4, 3, 2, 1]",
841             Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 4, 3,
842                 3, 2, 2, 1, 1 })));
843     assertEquals(
844             "[12, 9, 8, 7, 4, 3, 2, 1]",
845             Arrays.toString(MappingUtils.flattenRanges(new int[] { 12, 12,
846                 9, 7, 4, 1 })));
847     // forwards and backwards anyone?
848     assertEquals(
849             "[4, 5, 6, 3, 2, 1]",
850             Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 6, 3,
851                 1 })));
852     // backwards and forwards
853     assertEquals(
854             "[3, 2, 1, 4, 5, 6]",
855             Arrays.toString(MappingUtils.flattenRanges(new int[] { 3, 1, 4,
856                 6 })));
857     // trailing unpaired start position is ignored:
858     assertEquals(
859             "[12, 9, 8, 7, 4, 3, 2]",
860             Arrays.toString(MappingUtils.flattenRanges(new int[] { 12, 12,
861                 9, 7, 4, 2, 1 })));
862   }
863
864   /**
865    * Test mapping a column selection including hidden columns
866    * 
867    * @throws IOException
868    */
869   @Test(groups = { "Functional" })
870   public void testMapColumnSelection_hiddenColumns() throws IOException
871   {
872     setupMappedAlignments();
873
874     ColumnSelection proteinSelection = new ColumnSelection();
875
876     /*
877      * Column 0 in protein picks up Seq2/L, Seq3/G which map to cols 0-4 and 0-3
878      * in dna respectively, overall 0-4
879      */
880     proteinSelection.hideColumns(0);
881     ColumnSelection dnaSelection = MappingUtils.mapColumnSelection(
882             proteinSelection, proteinView, dnaView);
883     assertEquals("[]", dnaSelection.getSelected().toString());
884     List<int[]> hidden = dnaSelection.getHiddenColumns();
885     assertEquals(1, hidden.size());
886     assertEquals("[0, 4]", Arrays.toString(hidden.get(0)));
887
888     /*
889      * Column 1 in protein picks up Seq1/K which maps to cols 0-3 in dna
890      */
891     proteinSelection.revealAllHiddenColumns();
892     // the unhidden columns are now marked selected!
893     assertEquals("[0]", proteinSelection.getSelected().toString());
894     // deselect these or hideColumns will be expanded to include 0
895     proteinSelection.clear();
896     proteinSelection.hideColumns(1);
897     dnaSelection = MappingUtils.mapColumnSelection(proteinSelection,
898             proteinView, dnaView);
899     hidden = dnaSelection.getHiddenColumns();
900     assertEquals(1, hidden.size());
901     assertEquals("[0, 3]", Arrays.toString(hidden.get(0)));
902
903     /*
904      * Column 2 in protein picks up gaps only - no mapping
905      */
906     proteinSelection.revealAllHiddenColumns();
907     proteinSelection.clear();
908     proteinSelection.hideColumns(2);
909     dnaSelection = MappingUtils.mapColumnSelection(proteinSelection,
910             proteinView, dnaView);
911     assertTrue(dnaSelection.getHiddenColumns().isEmpty());
912
913     /*
914      * Column 3 in protein picks up Seq1/P, Seq2/Q, Seq3/S which map to columns
915      * 6-9, 6-10, 5-8 respectively, overall to 5-10
916      */
917     proteinSelection.revealAllHiddenColumns();
918     proteinSelection.clear();
919     proteinSelection.hideColumns(3); // 5-10 hidden in dna
920     proteinSelection.addElement(1); // 0-3 selected in dna
921     dnaSelection = MappingUtils.mapColumnSelection(proteinSelection,
922             proteinView, dnaView);
923     assertEquals("[0, 1, 2, 3]", dnaSelection.getSelected().toString());
924     hidden = dnaSelection.getHiddenColumns();
925     assertEquals(1, hidden.size());
926     assertEquals("[5, 10]", Arrays.toString(hidden.get(0)));
927
928     /*
929      * Combine hiding columns 1 and 3 to get discontiguous hidden columns
930      */
931     proteinSelection.revealAllHiddenColumns();
932     proteinSelection.clear();
933     proteinSelection.hideColumns(1);
934     proteinSelection.hideColumns(3);
935     dnaSelection = MappingUtils.mapColumnSelection(proteinSelection,
936             proteinView, dnaView);
937     hidden = dnaSelection.getHiddenColumns();
938     assertEquals(2, hidden.size());
939     assertEquals("[0, 3]", Arrays.toString(hidden.get(0)));
940     assertEquals("[5, 10]", Arrays.toString(hidden.get(1)));
941   }
942
943   @Test(groups = { "Functional" })
944   public void testGetLength()
945   {
946     assertEquals(0, MappingUtils.getLength(null));
947
948     /*
949      * [start, end] ranges
950      */
951     List<int[]> ranges = new ArrayList<int[]>();
952     assertEquals(0, MappingUtils.getLength(ranges));
953     ranges.add(new int[] { 1, 1 });
954     assertEquals(1, MappingUtils.getLength(ranges));
955     ranges.add(new int[] { 2, 10 });
956     assertEquals(10, MappingUtils.getLength(ranges));
957     ranges.add(new int[] { 20, 10 });
958     assertEquals(21, MappingUtils.getLength(ranges));
959
960     /*
961      * [start, end, start, end...] ranges
962      */
963     ranges.clear();
964     ranges.add(new int[] { 1, 5, 8, 4 });
965     ranges.add(new int[] { 8, 2 });
966     ranges.add(new int[] { 12, 12 });
967     assertEquals(18, MappingUtils.getLength(ranges));
968   }
969
970   @Test(groups = { "Functional" })
971   public void testContains()
972   {
973     assertFalse(MappingUtils.contains(null, 1));
974     List<int[]> ranges = new ArrayList<int[]>();
975     assertFalse(MappingUtils.contains(ranges, 1));
976
977     ranges.add(new int[] { 1, 4 });
978     ranges.add(new int[] { 6, 6 });
979     ranges.add(new int[] { 8, 10 });
980     ranges.add(new int[] { 30, 20 });
981     ranges.add(new int[] { -16, -44 });
982
983     assertFalse(MappingUtils.contains(ranges, 0));
984     assertTrue(MappingUtils.contains(ranges, 1));
985     assertTrue(MappingUtils.contains(ranges, 2));
986     assertTrue(MappingUtils.contains(ranges, 3));
987     assertTrue(MappingUtils.contains(ranges, 4));
988     assertFalse(MappingUtils.contains(ranges, 5));
989
990     assertTrue(MappingUtils.contains(ranges, 6));
991     assertFalse(MappingUtils.contains(ranges, 7));
992
993     assertTrue(MappingUtils.contains(ranges, 8));
994     assertTrue(MappingUtils.contains(ranges, 9));
995     assertTrue(MappingUtils.contains(ranges, 10));
996
997     assertFalse(MappingUtils.contains(ranges, 31));
998     assertTrue(MappingUtils.contains(ranges, 30));
999     assertTrue(MappingUtils.contains(ranges, 29));
1000     assertTrue(MappingUtils.contains(ranges, 20));
1001     assertFalse(MappingUtils.contains(ranges, 19));
1002
1003     assertFalse(MappingUtils.contains(ranges, -15));
1004     assertTrue(MappingUtils.contains(ranges, -16));
1005     assertTrue(MappingUtils.contains(ranges, -44));
1006     assertFalse(MappingUtils.contains(ranges, -45));
1007   }
1008
1009   /**
1010    * Test the method that drops positions from the start of a mapped range
1011    */
1012   @Test(groups = "Functional")
1013   public void testRemoveStartPositions()
1014   {
1015     int[] ranges = new int[] { 1, 10 };
1016     int[] adjusted = MappingUtils.removeStartPositions(0, ranges);
1017     assertEquals("[1, 10]", Arrays.toString(adjusted));
1018
1019     adjusted = MappingUtils.removeStartPositions(1, ranges);
1020     assertEquals("[2, 10]", Arrays.toString(adjusted));
1021     assertEquals("[1, 10]", Arrays.toString(ranges));
1022
1023     ranges = adjusted;
1024     adjusted = MappingUtils.removeStartPositions(1, ranges);
1025     assertEquals("[3, 10]", Arrays.toString(adjusted));
1026     assertEquals("[2, 10]", Arrays.toString(ranges));
1027
1028     ranges = new int[] { 2, 3, 10, 12 };
1029     adjusted = MappingUtils.removeStartPositions(1, ranges);
1030     assertEquals("[3, 3, 10, 12]", Arrays.toString(adjusted));
1031     assertEquals("[2, 3, 10, 12]", Arrays.toString(ranges));
1032
1033     ranges = new int[] { 2, 2, 8, 12 };
1034     adjusted = MappingUtils.removeStartPositions(1, ranges);
1035     assertEquals("[8, 12]", Arrays.toString(adjusted));
1036     assertEquals("[2, 2, 8, 12]", Arrays.toString(ranges));
1037
1038     ranges = new int[] { 2, 2, 8, 12 };
1039     adjusted = MappingUtils.removeStartPositions(2, ranges);
1040     assertEquals("[9, 12]", Arrays.toString(adjusted));
1041     assertEquals("[2, 2, 8, 12]", Arrays.toString(ranges));
1042
1043     ranges = new int[] { 2, 2, 4, 4, 9, 12 };
1044     adjusted = MappingUtils.removeStartPositions(1, ranges);
1045     assertEquals("[4, 4, 9, 12]", Arrays.toString(adjusted));
1046     assertEquals("[2, 2, 4, 4, 9, 12]", Arrays.toString(ranges));
1047
1048     ranges = new int[] { 2, 2, 4, 4, 9, 12 };
1049     adjusted = MappingUtils.removeStartPositions(2, ranges);
1050     assertEquals("[9, 12]", Arrays.toString(adjusted));
1051     assertEquals("[2, 2, 4, 4, 9, 12]", Arrays.toString(ranges));
1052
1053     ranges = new int[] { 2, 3, 9, 12 };
1054     adjusted = MappingUtils.removeStartPositions(3, ranges);
1055     assertEquals("[10, 12]", Arrays.toString(adjusted));
1056     assertEquals("[2, 3, 9, 12]", Arrays.toString(ranges));
1057   }
1058
1059   /**
1060    * Test the method that drops positions from the start of a mapped range, on
1061    * the reverse strand
1062    */
1063   @Test(groups = "Functional")
1064   public void testRemoveStartPositions_reverseStrand()
1065   {
1066     int[] ranges = new int[] { 10, 1 };
1067     int[] adjusted = MappingUtils.removeStartPositions(0, ranges);
1068     assertEquals("[10, 1]", Arrays.toString(adjusted));
1069     assertEquals("[10, 1]", Arrays.toString(ranges));
1070
1071     ranges = adjusted;
1072     adjusted = MappingUtils.removeStartPositions(1, ranges);
1073     assertEquals("[9, 1]", Arrays.toString(adjusted));
1074     assertEquals("[10, 1]", Arrays.toString(ranges));
1075
1076     ranges = adjusted;
1077     adjusted = MappingUtils.removeStartPositions(1, ranges);
1078     assertEquals("[8, 1]", Arrays.toString(adjusted));
1079     assertEquals("[9, 1]", Arrays.toString(ranges));
1080
1081     ranges = new int[] { 12, 11, 9, 6 };
1082     adjusted = MappingUtils.removeStartPositions(1, ranges);
1083     assertEquals("[11, 11, 9, 6]", Arrays.toString(adjusted));
1084     assertEquals("[12, 11, 9, 6]", Arrays.toString(ranges));
1085
1086     ranges = new int[] { 12, 12, 8, 4 };
1087     adjusted = MappingUtils.removeStartPositions(1, ranges);
1088     assertEquals("[8, 4]", Arrays.toString(adjusted));
1089     assertEquals("[12, 12, 8, 4]", Arrays.toString(ranges));
1090
1091     ranges = new int[] { 12, 12, 8, 4 };
1092     adjusted = MappingUtils.removeStartPositions(2, ranges);
1093     assertEquals("[7, 4]", Arrays.toString(adjusted));
1094     assertEquals("[12, 12, 8, 4]", Arrays.toString(ranges));
1095
1096     ranges = new int[] { 12, 12, 10, 10, 8, 4 };
1097     adjusted = MappingUtils.removeStartPositions(1, ranges);
1098     assertEquals("[10, 10, 8, 4]", Arrays.toString(adjusted));
1099     assertEquals("[12, 12, 10, 10, 8, 4]", Arrays.toString(ranges));
1100
1101     ranges = new int[] { 12, 12, 10, 10, 8, 4 };
1102     adjusted = MappingUtils.removeStartPositions(2, ranges);
1103     assertEquals("[8, 4]", Arrays.toString(adjusted));
1104     assertEquals("[12, 12, 10, 10, 8, 4]", Arrays.toString(ranges));
1105
1106     ranges = new int[] { 12, 11, 8, 4 };
1107     adjusted = MappingUtils.removeStartPositions(3, ranges);
1108     assertEquals("[7, 4]", Arrays.toString(adjusted));
1109     assertEquals("[12, 11, 8, 4]", Arrays.toString(ranges));
1110   }
1111
1112 }