X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignmentView.java;h=fe8b3a799482e2eaabdde24cddafb9bea644d920;hb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;hp=efb7c4ac1553193ea364dc4e1982abcbfb94cbc0;hpb=aced09c4feeaf3406269442c14e54abeeb4cad81;p=jalview.git diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java index efb7c4a..fe8b3a7 100644 --- a/src/jalview/datamodel/AlignmentView.java +++ b/src/jalview/datamodel/AlignmentView.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -24,7 +24,7 @@ import jalview.util.MessageManager; import jalview.util.ShiftList; import java.io.PrintStream; -import java.util.Enumeration; +import java.util.ArrayList; import java.util.List; import java.util.Vector; @@ -47,7 +47,7 @@ public class AlignmentView * one or more ScGroup objects, which are referenced by each seqCigar's group * membership */ - private Vector scGroups; + private List scGroups = null; private boolean isNa = false; @@ -133,27 +133,24 @@ public class AlignmentView selseqs = alignment.getSequencesArray(); } + List> seqsets = new ArrayList>(); // get the alignment's group list and make a copy - Vector grps = new Vector(); + List grps = new ArrayList(); List gg = alignment.getGroups(); grps.addAll(gg); ScGroup[] sgrps = null; boolean addedgps[] = null; if (grps != null) { - SequenceGroup sg; if (selection != null && selectedRegionOnly) { // trim annotation to the region being stored. // strip out any groups that do not actually intersect with the // visible and selected region int ssel = selection.getStartRes(), esel = selection.getEndRes(); - Vector isg = new Vector(); - Enumeration en = grps.elements(); - while (en.hasMoreElements()) + List isg = new ArrayList(); + for (SequenceGroup sg : grps) { - sg = (SequenceGroup) en.nextElement(); - if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel)) { // adjust bounds of new group, if necessary. @@ -168,7 +165,7 @@ public class AlignmentView sg.setStartRes(sg.getStartRes() - ssel + 1); sg.setEndRes(sg.getEndRes() - ssel + 1); - isg.addElement(sg); + isg.add(sg); } } grps = isg; @@ -178,13 +175,15 @@ public class AlignmentView addedgps = new boolean[grps.size()]; for (int g = 0; g < sgrps.length; g++) { - sg = (SequenceGroup) grps.elementAt(g); + SequenceGroup sg = grps.get(g); sgrps[g] = new ScGroup(); sgrps[g].sg = new SequenceGroup(sg); addedgps[g] = false; - grps.setElementAt(sg.getSequences(null), g); + // can't set entry 0 in an empty list + // seqsets.set(g, sg.getSequences(null)); + seqsets.add(sg.getSequences()); } - // grps now contains vectors (should be sets) for each group, so we can + // seqsets now contains vectors (should be sets) for each group, so we can // track when we've done with the group } int csi = 0; @@ -198,11 +197,11 @@ public class AlignmentView sequences[csi].setGroupMembership(selected); selected.addElement(sequences[csi]); } - if (grps != null) + if (seqsets != null) { for (int sg = 0; sg < sgrps.length; sg++) { - if (((Vector) grps.elementAt(sg)).contains(selseqs[i])) + if ((seqsets.get(sg)).contains(selseqs[i])) { sequences[csi].setGroupMembership(sgrps[sg]); sgrps[sg].sg.deleteSequence(selseqs[i], false); @@ -211,10 +210,10 @@ public class AlignmentView { if (scGroups == null) { - scGroups = new Vector(); + scGroups = new ArrayList(); } addedgps[sg] = true; - scGroups.addElement(sgrps[sg]); + scGroups.add(sgrps[sg]); } } } @@ -242,7 +241,9 @@ public class AlignmentView { if (!seqcigararray.isSeqCigarArray()) { - throw new Error(MessageManager.getString("error.implementation_error_can_only_make_alignmnet_from_cigararray")); + throw new Error( + MessageManager + .getString("error.implementation_error_can_only_make_alignmnet_from_cigararray")); } // contigs = seqcigararray.applyDeletions(); contigs = seqcigararray.getDeletedRegions(); @@ -299,8 +300,7 @@ public class AlignmentView { ColumnSelection colsel = new ColumnSelection(); - return new Object[] - { + return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel }; } @@ -356,7 +356,7 @@ public class AlignmentView SequenceGroup[] nsg = new SequenceGroup[nvg]; for (int g = 0; g < nvg; g++) { - SequenceGroup sg = ((ScGroup) scGroups.elementAt(g)).sg; + SequenceGroup sg = scGroups.get(g).sg; if (r) { if (sg.getStartRes() > gend || sg.getEndRes() < gstart) @@ -442,7 +442,7 @@ public class AlignmentView for (int g = 0; g < nvg; g++) { if (nsg[g] != null - && sequences[nsq].isMemberOf(scGroups.elementAt(g))) + && sequences[nsq].isMemberOf(scGroups.get(g))) { nsg[g].addSequence(aln[nsq], false); } @@ -466,6 +466,7 @@ public class AlignmentView * alignment. * * @param c + * gap character to use to recreate the alignment * @return */ private SequenceI[] getVisibleSeqs(char c) @@ -473,13 +474,9 @@ public class AlignmentView SequenceI[] aln = new SequenceI[sequences.length]; for (int i = 0, j = sequences.length; i < j; i++) { - aln[i] = sequences[i].getSeq('-'); - } - // Remove hidden regions from sequence objects. - String seqs[] = getSequenceStrings('-'); - for (int i = 0, j = aln.length; i < j; i++) - { - aln[i].setSequence(seqs[i]); + aln[i] = sequences[i].getSeq(c); + // Remove hidden regions from sequence + aln[i].setSequence(getASequenceString(c, i)); } return aln; } @@ -515,8 +512,38 @@ public class AlignmentView } /** + * build a string excluding hidden regions from a particular sequence in the + * view + * + * @param c + * @param n + * @return + */ + private String getASequenceString(char c, int n) + { + String sqn; + String fullseq = sequences[n].getSequenceString(c); + if (contigs != null) + { + sqn = ""; + int p = 0; + for (int h = 0; h < contigs.length; h += 3) + { + sqn += fullseq.substring(p, contigs[h + 1]); + p = contigs[h + 1] + contigs[h + 2]; + } + sqn += fullseq.substring(p); + } + else + { + sqn = fullseq; + } + return sqn; + } + + /** * get an array of visible sequence strings for a view on an alignment using - * the given gap character + * the given gap character uses getASequenceString * * @param c * char @@ -527,22 +554,7 @@ public class AlignmentView String[] seqs = new String[sequences.length]; for (int n = 0; n < sequences.length; n++) { - String fullseq = sequences[n].getSequenceString(c); - if (contigs != null) - { - seqs[n] = ""; - int p = 0; - for (int h = 0; h < contigs.length; h += 3) - { - seqs[n] += fullseq.substring(p, contigs[h + 1]); - p = contigs[h + 1] + contigs[h + 2]; - } - seqs[n] += fullseq.substring(p); - } - else - { - seqs[n] = fullseq; - } + seqs[n] = getASequenceString(c, n); } return seqs; } @@ -652,7 +664,9 @@ public class AlignmentView { if (sequences == null || width <= 0) { - throw new Error(MessageManager.getString("error.empty_view_cannot_be_updated")); + throw new Error( + MessageManager + .getString("error.empty_view_cannot_be_updated")); } if (nvismsa == null) { @@ -682,7 +696,17 @@ public class AlignmentView j++; if (mseq.length != sequences.length) { - throw new Error(MessageManager.formatMessage("error.mismatch_between_number_of_sequences_in_block", new String[]{Integer.valueOf(j).toString(),Integer.valueOf(mseq.length).toString(),Integer.valueOf(sequences.length).toString() })); + throw new Error( + MessageManager + .formatMessage( + "error.mismatch_between_number_of_sequences_in_block", + new String[] { + Integer.valueOf(j).toString(), + Integer.valueOf(mseq.length) + .toString(), + Integer.valueOf( + sequences.length) + .toString() })); } swidth = mseq[0].getLength(); // JBPNote: could ensure padded // here. @@ -835,25 +859,30 @@ public class AlignmentView else { // place gaps. - throw new Error(MessageManager.getString("error.padding_not_yet_implemented")); + throw new Error( + MessageManager + .getString("error.padding_not_yet_implemented")); } } } } } - return new Object[] - { alignment, columnselection }; + return new Object[] { alignment, columnselection }; } else { if (nvismsa.length != 1) { - throw new Error(MessageManager.formatMessage("error.mismatch_between_visible_blocks_to_update_and_number_of_contigs_in_view", new String[]{Integer.valueOf(nvismsa.length).toString()})); + throw new Error( + MessageManager + .formatMessage( + "error.mismatch_between_visible_blocks_to_update_and_number_of_contigs_in_view", + new String[] { Integer.valueOf( + nvismsa.length).toString() })); } if (nvismsa[0] != null) { - return new Object[] - { nvismsa[0], new ColumnSelection() }; + return new Object[] { nvismsa[0], new ColumnSelection() }; } else { @@ -914,8 +943,7 @@ public class AlignmentView } else { - return new int[] - { 0, width }; + return new int[] { 0, width }; } } @@ -1038,7 +1066,7 @@ public class AlignmentView + " groups defined on the view."); for (int g = 0; g < view.scGroups.size(); g++) { - ScGroup sgr = (ScGroup) view.scGroups.elementAt(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 "