X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FCigarArray.java;h=1723f1d45d148bd082b5d9c17ff0661df2e2216d;hb=653724613f7082c87b17ed519fef06f704876e2a;hp=8961425031ee64d06dfc87116c4b0234f95f1798;hpb=7570956d4b58f313d402cdd0507737c0628f1544;p=jalview.git
diff --git a/src/jalview/datamodel/CigarArray.java b/src/jalview/datamodel/CigarArray.java
index 8961425..1723f1d 100644
--- a/src/jalview/datamodel/CigarArray.java
+++ b/src/jalview/datamodel/CigarArray.java
@@ -1,35 +1,65 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.List;
+
public class CigarArray extends CigarBase
{
- /**
- * Do CIGAR operations on a set of sequences from many other cigars
- * BAD THINGS WILL HAPPEN IF A CIGARARRAY IS PASSED TO A CIGARARRAY
- * or a CIGARCIGAR is given a CIGARARRAY to insert gaps into.
- */
- /**
- * array of subject cigars
- */
- public CigarSimple refCigars[]=null;
- private boolean seqcigararray=false;
- private CigarArray() {
+ /**
+ * Do CIGAR operations on a set of sequences from many other cigars BAD THINGS
+ * WILL HAPPEN IF A CIGARARRAY IS PASSED TO A CIGARARRAY or a CIGARCIGAR is
+ * given a CIGARARRAY to insert gaps into.
+ */
+ /**
+ * array of subject cigars
+ */
+ public CigarSimple refCigars[] = null;
+
+ private boolean seqcigararray = false;
+
+ private CigarArray()
+ {
super();
}
/**
* isSeqCigarArray()
+ *
* @return boolean true if all refCigars resolve to a SeqCigar or a CigarCigar
*/
public boolean isSeqCigarArray()
{
return seqcigararray;
}
+
/**
- * Apply CIGAR operations to several cigars in parallel
- * will throw an error if any of cigar are actually CigarArrays.
- * @param cigar Cigar[]
+ * Apply CIGAR operations to several cigars in parallel will throw an error if
+ * any of cigar are actually CigarArrays.
+ *
+ * @param cigar
+ * Cigar[]
*/
- public CigarArray(CigarSimple[] cigars) {
+ public CigarArray(CigarSimple[] cigars)
+ {
super();
seqcigararray = true;
if (cigars != null && cigars.length > 0)
@@ -38,137 +68,333 @@ public class CigarArray extends CigarBase
for (int c = 0; c < cigars.length; c++)
{
refCigars[c] = cigars[c];
- if (! ( (cigars[c] instanceof SeqCigar)
- || cigars[c] instanceof CigarCigar))
+ if (!((cigars[c] instanceof SeqCigar)
+ || cigars[c] instanceof CigarCigar))
{
seqcigararray = false;
}
}
}
}
+
/**
- * @see Cigar.getSequenceAndDeletions
- * @param GapChar char
- * @return Object[][]
+ * construct a cigar array from the current alignment, or just the subset of
+ * the current alignment specified by selectionGroup. Any columns marked as
+ * hidden in columnSelection will be marked as deleted in the array.
+ *
+ * @param alignment
+ * @param columnSelection
+ * @param selectionGroup
*/
- protected Object[][] getArrayofSequenceAndDeletions(char GapChar) {
- if (refCigars == null || refCigars.length == 0 || length == 0) {
- return null;
- }
- Object[][] sqanddels = new Object[refCigars.length][];
- for (int c=0; c list, SequenceGroup selectionGroup)
+ {
+ int[] _startend = _calcStartEndBounds(alignment, selectionGroup);
+ int start = _startend[1], end = _startend[2];
+ // now construct the CigarArray operations
+ if (list != null)
+ {
+ int[] region;
+ int hideStart, hideEnd;
+ int last = start;
+ for (int j = 0; last < end & j < list.size(); j++)
+ {
+ region = list.get(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+ // edit hidden regions to selection range
+
+ // just move on if hideEnd is before last
+ if (hideEnd < last)
{
- sqanddels[c] = getSequenceAndDeletions(refString, GapChar);
- } else {
- sqanddels[c] = null;
+ continue;
}
+ // exit if next region is after end
+ if (hideStart > end)
+ {
+ break;
+ }
+
+ // truncate region at start if last falls in region
+ if ((hideStart < last) && (hideEnd >= last))
+ {
+ hideStart = last;
+ }
+
+ // truncate region at end if end falls in region
+ if (hideEnd > end) // already checked that hideStart<=end
+ {
+ hideEnd = end;
+ }
+
+ /**
+ * form operations...
+ */
+ if (last < hideStart)
+ {
+ addOperation(CigarArray.M, hideStart - last);
+ }
+ addOperation(CigarArray.D, 1 + hideEnd - hideStart);
+ last = hideEnd + 1;
+ }
+ // Final match if necessary.
+ if (last <= end)
+ {
+ addOperation(CigarArray.M, end - last + 1);
}
- return sqanddels;
}
+ else
+ {
+ addOperation(CigarArray.M, end - start + 1);
+ }
+ }
+
+ /**
+ * @see CigarBase.getSequenceAndDeletions
+ * @param GapChar
+ * char
+ * @return Object[][]
+ */
+ protected Object[][] getArrayofSequenceAndDeletions(char GapChar)
+ {
+ if (refCigars == null || refCigars.length == 0 || length == 0)
+ {
+ return null;
+ }
+ Object[][] sqanddels = new Object[refCigars.length][];
+ for (int c = 0; c < refCigars.length; c++)
+ {
+ String refString = refCigars[c].getSequenceString(GapChar);
+ if (refString != null)
+ {
+ sqanddels[c] = getSequenceAndDeletions(refString, GapChar);
+ }
+ else
+ {
+ sqanddels[c] = null;
+ }
+ }
+ return sqanddels;
+ }
+
/**
* NOTE: this is an improper sequence string function
- * @return String formed by newline concatenated results of applying CIGAR operations to each reference object in turn.
- * @param GapChar char
+ *
+ * @return String formed by newline concatenated results of applying CIGAR
+ * operations to each reference object in turn.
+ * @param GapChar
+ * char
* @return '\n' separated strings (empty results included as \n\n)
*/
public String getSequenceString(char GapChar)
{
- if (length==0 || refCigars==null)
+ if (length == 0 || refCigars == null)
+ {
return "";
+ }
StringBuffer seqStrings = new StringBuffer();
Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);
- for (int c=0; cdmax) dmax=d; }
+ * offset+=dmax; // shift in visible column coordinates
+ */
+ for (int s = 0; s < refCigars.length; s++)
+ {
+ int d = refCigars[s].deleteRange(delstart, delend);
}
+
}
}
- if (delpos!=null)
+ if (delpos != null)
{
- int[] pos=new int[delpos.size()];
- for (int k = 0, l = delpos.size(); k < l; k++) {
- pos[k] = ((Integer) delpos.get(k)).intValue();
- delpos.set(k,null);
+ int[] pos = new int[delpos.size() * 2];
+ for (int k = 0, l = delpos.size(); k < l; k++)
+ {
+ int[] dr = ((int[]) delpos.elementAt(k));
+ pos[k * 2] = dr[0];
+ pos[k * 2 + 1] = dr[1];
+ delpos.setElementAt(null, k);
}
- delpos=null;
+ delpos = null;
return pos;
}
return null;
}
+
/**
- *
- * @return SeqCigar[] or null if CigarArray is not a SeqCigarArray (ie it does not resolve to set of seqCigars)
+ *
+ * @return SeqCigar[] or null if CigarArray is not a SeqCigarArray (ie it does
+ * not resolve to set of seqCigars)
*/
- public SeqCigar[] getSeqCigarArray() {
+ public SeqCigar[] getSeqCigarArray()
+ {
if (!isSeqCigarArray())
+ {
return null;
+ }
SeqCigar[] sa = new SeqCigar[refCigars.length];
- for (int i=0; i