X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSeqCigar.java;h=5f6933453522aa2c1f5520710ed52fd77d9ba6d0;hb=a8f483d04205bb8273ee311c12968b7e86d205fa;hp=f2777f499b469555ee0ed8bdb051658bd9063784;hpb=153dd62dc91da13ae732600e6ea55ddbe15eab39;p=jalview.git diff --git a/src/jalview/datamodel/SeqCigar.java b/src/jalview/datamodel/SeqCigar.java index f2777f4..5f69334 100644 --- a/src/jalview/datamodel/SeqCigar.java +++ b/src/jalview/datamodel/SeqCigar.java @@ -1,22 +1,24 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.datamodel; +import java.util.Enumeration; import java.util.Hashtable; import jalview.analysis.*; @@ -68,8 +70,8 @@ public class SeqCigar extends CigarSimple */ public String getSequenceString(char GapChar) { - return (length == 0) ? "" : (String) getSequenceAndDeletions(refseq - .getSequenceAsString(start, end), GapChar)[0]; + return (length == 0) ? "" : (String) getSequenceAndDeletions( + refseq.getSequenceAsString(start, end), GapChar)[0]; } /** @@ -85,18 +87,17 @@ public class SeqCigar extends CigarSimple { return null; } - Object[] edit_result = getSequenceAndDeletions(refseq - .getSequenceAsString(start, end), GapChar); + Object[] edit_result = getSequenceAndDeletions( + refseq.getSequenceAsString(start, end), GapChar); if (edit_result == null) { throw new Error( "Implementation Error - unexpected null from getSequenceAndDeletions"); } int bounds[] = (int[]) edit_result[1]; - seq = new Sequence(refseq.getName(), (String) edit_result[0], refseq - .getStart() - + start + bounds[0], refseq.getStart() + start - + ((bounds[2] == 0) ? -1 : bounds[2])); + seq = new Sequence(refseq.getName(), (String) edit_result[0], + refseq.getStart() + start + bounds[0], refseq.getStart() + + start + ((bounds[2] == 0) ? -1 : bounds[2])); seq.setDescription(refseq.getDescription()); int sstart = seq.getStart(), send = seq.getEnd(); // seq.checkValidRange(); probably not needed @@ -170,9 +171,8 @@ public class SeqCigar extends CigarSimple } else { - ds = new Sequence(seq.getName(), ungapped, seq.getStart(), seq - .getStart() - + ungapped.length() - 1); + ds = new Sequence(seq.getName(), ungapped, seq.getStart(), + seq.getStart() + ungapped.length() - 1); // JBPNote: this would be consistent but may not be useful // seq.setDatasetSequence(ds); } @@ -431,12 +431,16 @@ public class SeqCigar extends CigarSimple } /** - * createAlignment + * create an alignment from the given array of cigar sequences and gap + * character, and marking the given segments as visible in the given + * columselection. * * @param alseqs - * SeqCigar[] * @param gapCharacter - * char + * @param colsel + * - columnSelection where hidden regions are marked + * @param segments + * - visible regions of alignment * @return SequenceI[] */ public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs, @@ -501,8 +505,8 @@ public class SeqCigar extends CigarSimple } else { - g_seqs[s].insert(inspos, alseqs_string[i].substring( - region[0], region[1] + 1)); + g_seqs[s].insert(inspos, + alseqs_string[i].substring(region[0], region[1] + 1)); } } shifts.addShift(region[2], insert.length); // update shift in @@ -520,10 +524,9 @@ public class SeqCigar extends CigarSimple { int[] bounds = ((int[]) ((Object[]) gs_regions[i])[1]); SequenceI ref = alseqs[i].getRefSeq(); - seqs[i] = new Sequence(ref.getName(), g_seqs[i].toString(), ref - .getStart() - + alseqs[i].start + bounds[0], ref.getStart() - + alseqs[i].start + (bounds[2] == 0 ? -1 : bounds[2])); + seqs[i] = new Sequence(ref.getName(), g_seqs[i].toString(), + ref.getStart() + alseqs[i].start + bounds[0], ref.getStart() + + alseqs[i].start + (bounds[2] == 0 ? -1 : bounds[2])); seqs[i].setDatasetSequence(ref); seqs[i].setDescription(ref.getDescription()); } @@ -691,4 +694,77 @@ public class SeqCigar extends CigarSimple // System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring()); } + /** + * references to entities that this sequence cigar is associated with. + */ + private Hashtable selGroups = null; + + public void setGroupMembership(Object group) + { + if (selGroups == null) + { + selGroups = new Hashtable(); + } + selGroups.put(group, new int[0]); + } + + /** + * Test for and if present remove association to group. + * + * @param group + * @return true if group was associated and it was removed + */ + public boolean removeGroupMembership(Object group) + { + if (selGroups != null && selGroups.containsKey(group)) + { + selGroups.remove(group); + return true; + } + return false; + } + + /** + * forget all associations for this sequence. + */ + public void clearMemberships() + { + if (selGroups != null) + { + selGroups.clear(); + } + selGroups = null; + } + + /** + * + * @return null or array of all associated entities + */ + public Object[] getAllMemberships() + { + if (selGroups == null) + { + return null; + } + Object[] mmbs = new Object[selGroups.size()]; + Enumeration en = selGroups.keys(); + for (int i = 0; en.hasMoreElements(); i++) + { + mmbs[i] = en.nextElement(); + } + return mmbs; + } + + /** + * Test for group membership + * + * @param sgr + * - a selection group or some other object that may be associated + * with seqCigar + * @return true if sgr is associated with this seqCigar + */ + public boolean isMemberOf(Object sgr) + { + return (selGroups != null) && selGroups.get(sgr) != null; + } }