X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignmentView.java;h=88e9a9c004cc4ad3e230f522c239c464718043ff;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=f73fb74872a498042c8c1e2a303f4e1f43b3ab75;hpb=ad15cff29620f960119f80176f1fd443da9f6763;p=jalview.git diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java index f73fb74..88e9a9c 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-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -47,7 +47,7 @@ public class AlignmentView * one or more ScGroup objects, which are referenced by each seqCigar's group * membership */ - private List scGroups=null; + private List scGroups = null; private boolean isNa = false; @@ -133,7 +133,7 @@ public class AlignmentView selseqs = alignment.getSequencesArray(); } - List> seqsets=new ArrayList>(); + List> seqsets = new ArrayList>(); // get the alignment's group list and make a copy List grps = new ArrayList(); List gg = alignment.getGroups(); @@ -179,7 +179,9 @@ public class AlignmentView sgrps[g] = new ScGroup(); sgrps[g].sg = new SequenceGroup(sg); addedgps[g] = false; - seqsets.set(g, sg.getSequences(null)); + // can't set entry 0 in an empty list + // seqsets.set(g, sg.getSequences(null)); + seqsets.add(sg.getSequences()); } // seqsets now contains vectors (should be sets) for each group, so we can // track when we've done with the group @@ -239,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(); @@ -296,8 +300,7 @@ public class AlignmentView { ColumnSelection colsel = new ColumnSelection(); - return new Object[] - { + return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel }; } @@ -463,6 +466,7 @@ public class AlignmentView * alignment. * * @param c + * gap character to use to recreate the alignment * @return */ private SequenceI[] getVisibleSeqs(char c) @@ -470,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; } @@ -512,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 @@ -524,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; } @@ -649,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) { @@ -679,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. @@ -832,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 { @@ -911,8 +943,7 @@ public class AlignmentView } else { - return new int[] - { 0, width }; + return new int[] { 0, width }; } }