+
+ /**
+ * compute a deletion map for the current view according to the given
+ * gap/match map
+ *
+ * @param gapMap
+ * (as returned from SequenceI.gapMap())
+ * @return int[] {intersection of visible regions with gapMap)
+ */
+ public int[] getVisibleContigMapFor(int[] gapMap)
+ {
+ int[] delMap = null;
+ int[] viscontigs = getVisibleContigs();
+ int spos = 0;
+ int i = 0;
+ if (viscontigs != null)
+ {
+ // viscontigs maps from a subset of the gapMap to the gapMap, so it will
+ // always be equal to or shorter than gapMap
+ delMap = new int[gapMap.length];
+ for (int contig = 0; contig < viscontigs.length; contig += 2)
+ {
+
+ while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])
+ {
+ spos++;
+ }
+ while (spos < gapMap.length
+ && gapMap[spos] <= viscontigs[contig + 1])
+ {
+ delMap[i++] = spos++;
+ }
+ }
+ int tmap[] = new int[i];
+ System.arraycopy(delMap, 0, tmap, 0, i);
+ delMap = tmap;
+ }
+ return delMap;
+ }
+
+ /**
+ * apply the getSeq(gc) method to each sequence cigar, and return the array of
+ * edited sequences, optionally with hidden regions removed.
+ *
+ * @param gc
+ * gap character to use for insertions
+ * @param delete
+ * remove hidden regions from sequences. Note: currently implemented
+ * in a memory inefficient way - space needed is 2*result set for
+ * deletion
+ *
+ * @return SequenceI[]
+ */
+ public SequenceI[] getEditedSequences(char gc, boolean delete)
+ {
+ SeqCigar[] msf = getSequences();
+ SequenceI[] aln = new SequenceI[msf.length];
+ for (int i = 0, j = msf.length; i < j; i++)
+ {
+ aln[i] = msf[i].getSeq(gc);
+ }
+ if (delete)
+ {
+ String[] sqs = getSequenceStrings(gc);
+ for (int i = 0; i < sqs.length; i++)
+ {
+ aln[i].setSequence(sqs[i]);
+ sqs[i] = null;
+ }
+ }
+ return aln;
+ }
+
+ public static void summariseAlignmentView(AlignmentView view,
+ PrintStream os)
+ {
+ os.print("View has " + view.sequences.length + " of which ");
+ if (view.selected == null)
+ {
+ os.print("None");
+ }
+ else
+ {
+ os.print(" " + view.selected.size());
+ }
+ os.println(" are selected.");
+ os.print("View is " + view.getWidth() + " columns wide");
+ int viswid = 0;
+ int[] contigs = view.getContigs();
+ if (contigs != null)
+ {
+ viswid = view.width;
+ for (int i = 0; i < contigs.length; i += 3)
+ {
+ viswid += contigs[i + 2];
+ }
+ os.println("with " + viswid + " visible columns spread over "
+ + contigs.length / 3 + " regions.");
+ }
+ else
+ {
+ viswid = view.width;
+ os.println(".");
+ }
+ if (view.scGroups != null)
+ {
+ os.println("There are " + view.scGroups.size()
+ + " groups defined on the view.");
+ for (int g = 0; g < view.scGroups.size(); g++)
+ {
+ ScGroup sgr = view.scGroups.get(g);
+ os.println("Group " + g + ": Name = " + sgr.sg.getName()
+ + " Contains " + sgr.seqs.size() + " Seqs.");
+ os.println("This group runs from " + sgr.sg.getStartRes() + " to "
+ + sgr.sg.getEndRes());
+ for (int s = 0; s < sgr.seqs.size(); s++)
+ {
+ // JBPnote this should be a unit test for ScGroup
+ if (!sgr.seqs.get(s).isMemberOf(sgr))
+ {
+ os.println("** WARNING: sequence " + sgr.seqs.get(s).toString()
+ + " is not marked as member of group.");
+ }
+ }
+ }
+ AlignmentI visal = view.getVisibleAlignment('-');
+ if (visal != null)
+ {
+ os.println("Vis. alignment is " + visal.getWidth()
+ + " wide and has " + visal.getHeight() + " seqs.");
+ if (visal.getGroups() != null && visal.getGroups().size() > 0)
+ {
+
+ int i = 1;
+ for (SequenceGroup sg : visal.getGroups())
+ {
+ os.println("Group " + (i++) + " begins at column "
+ + sg.getStartRes() + " and ends at " + sg.getEndRes());
+ }
+ }
+ }
+ }
+ }
+
+ public static void testSelectionViews(AlignmentI alignment,
+ HiddenColumns hidden, SequenceGroup selection)
+ {
+ System.out.println("Testing standard view creation:\n");
+ AlignmentView view = null;
+ try
+ {
+ System.out.println(
+ "View with no hidden columns, no limit to selection, no groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, false, false,
+ false);
+ summariseAlignmentView(view, System.out);
+
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View with no hidden columns, no limit to selection, and all groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, false, false,
+ true);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection marked but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View with no hidden columns, limited to selection and no groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, false, true,
+ false);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection restricted but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View with no hidden columns, limited to selection, and all groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, false, true,
+ true);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection restricted and groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View *with* hidden columns, no limit to selection, no groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, true, false,
+ false);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View *with* hidden columns, no limit to selection, and all groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, true, false,
+ true);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection marked but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View *with* hidden columns, limited to selection and no groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, true, true,
+ false);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection restricted but no groups marked.");
+ }
+ try
+ {
+ System.out.println(
+ "View *with* hidden columns, limited to selection, and all groups to be collected:");
+ view = new AlignmentView(alignment, hidden, selection, true, true,
+ true);
+ summariseAlignmentView(view, System.out);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println(
+ "Failed to generate alignment with selection restricted and groups marked.");
+ }
+
+ }
+
+ /**
+ * return pruned visible sequences in each group in alignment view
+ *
+ * @param c
+ * @return
+ */
+ public Collection<? extends AnnotatedCollectionI> getVisibleGroups(char c)
+ {
+ ArrayList<SequenceGroup> groups = new ArrayList<>();
+ for (ScGroup sc : scGroups)
+ {
+ SequenceGroup sg = sc.getNewSequenceGroup(c);
+ groups.add(sg);
+ }
+ return groups;
+ }