-package jalview.datamodel;
-
-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() {
- 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[]
- */
- public CigarArray(CigarSimple[] cigars) {
- super();
- seqcigararray = true;
- if (cigars != null && cigars.length > 0)
- {
- refCigars = new CigarSimple[cigars.length];
- for (int c = 0; c < cigars.length; c++)
- {
- refCigars[c] = cigars[c];
- if (! ( (cigars[c] instanceof SeqCigar)
- || cigars[c] instanceof CigarCigar))
- {
- seqcigararray = false;
- }
- }
- }
- }
- /**
- * @see Cigar.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 '\n' separated strings (empty results included as \n\n)
- */
- public String getSequenceString(char GapChar)
- {
- if (length==0 || refCigars==null)
- return "";
- StringBuffer seqStrings = new StringBuffer();
- Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);
- for (int c=0; c<refCigars.length; c++) {
- if (sqanddels[c]!=null) {
- seqStrings.append( (String) sqanddels[c][0]);
- sqanddels[c][0] = null;
- }
- seqStrings.append('\n');
- }
- return seqStrings.toString();
- }
- /**
- * return string results of applying cigar string to all reference cigars
- * @param GapChar char
- * @return String[]
- */
- public String[] getSequenceStrings(char GapChar) {
-
- if (length==0 || refCigars==null || refCigars.length==0)
- return null;
- Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);
- String[] seqs = new String[sqanddels.length];
- for (int c=0; c<refCigars.length; c++) {
- seqs[c] = (String) sqanddels[c][0];
- }
- return seqs;
- }
- /**
- * Combines the CigarArray cigar operations with the operations in each
- * reference cigar - creating a new reference cigar
- * @return Cigar[]
-
- public CigarBase[] getEditedCigars() {
-
- return new CigarBase[] {};
- }
-*/
- /**
- * applyDeletions
- * edits underlying refCigars to propagate deleted regions, and removes deletion
- * operations from CigarArray operation list.
- * @return int[] position where deletion occured in cigarArray or null if none occured
- */
- public int[] applyDeletions()
- {
- java.util.Vector delpos=null;
- if (length==0)
- return null;
- int cursor=0; // range counter for deletions
- int vcursor=0; // visible column index
- for (int i=0; i<length; i++) {
- if (operation[i]!=D) {
- if (operation[i]==M)
- cursor+=range[i];
- vcursor+=range[i];
- }
- else
- {
- if (delpos==null)
- delpos=new java.util.Vector();
- int delstart=cursor, delend=cursor+range[i]-1; // inclusive
- delpos.add(new Integer(vcursor-1)); // index of left hand column of hidden region boundary
- System.arraycopy(operation, i+1, operation, i, length-i);
- System.arraycopy(range, i+1, range, i, length-i);
- length--;
- for (int s=0; s<refCigars.length; s++) {
- refCigars[s].deleteRange(delstart, delend);
- }
- }
- }
- 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);
- }
- 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)
- */
- public SeqCigar[] getSeqCigarArray() {
- if (!isSeqCigarArray())
- return null;
- SeqCigar[] sa = new SeqCigar[refCigars.length];
- for (int i=0; i<refCigars.length; i++)
- sa[i] = (SeqCigar) refCigars[i];
- return sa;
- }
-}
+package jalview.datamodel;\r
+\r
+public class CigarArray extends CigarBase\r
+{\r
+ /**\r
+ * Do CIGAR operations on a set of sequences from many other cigars\r
+ * BAD THINGS WILL HAPPEN IF A CIGARARRAY IS PASSED TO A CIGARARRAY\r
+ * or a CIGARCIGAR is given a CIGARARRAY to insert gaps into.\r
+ */\r
+ /**\r
+ * array of subject cigars\r
+ */\r
+ public CigarSimple refCigars[]=null;\r
+ private boolean seqcigararray=false;\r
+ private CigarArray() {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * isSeqCigarArray()\r
+ * @return boolean true if all refCigars resolve to a SeqCigar or a CigarCigar\r
+ */\r
+ public boolean isSeqCigarArray()\r
+ {\r
+ return seqcigararray;\r
+ }\r
+ /**\r
+ * Apply CIGAR operations to several cigars in parallel\r
+ * will throw an error if any of cigar are actually CigarArrays.\r
+ * @param cigar Cigar[]\r
+ */\r
+ public CigarArray(CigarSimple[] cigars) {\r
+ super();\r
+ seqcigararray = true;\r
+ if (cigars != null && cigars.length > 0)\r
+ {\r
+ refCigars = new CigarSimple[cigars.length];\r
+ for (int c = 0; c < cigars.length; c++)\r
+ {\r
+ refCigars[c] = cigars[c];\r
+ if (! ( (cigars[c] instanceof SeqCigar)\r
+ || cigars[c] instanceof CigarCigar))\r
+ {\r
+ seqcigararray = false;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * @see Cigar.getSequenceAndDeletions\r
+ * @param GapChar char\r
+ * @return Object[][]\r
+ */\r
+ protected Object[][] getArrayofSequenceAndDeletions(char GapChar) {\r
+ if (refCigars == null || refCigars.length == 0 || length == 0) {\r
+ return null;\r
+ }\r
+ Object[][] sqanddels = new Object[refCigars.length][];\r
+ for (int c=0; c<refCigars.length; c++) {\r
+ String refString = refCigars[c].getSequenceString(GapChar);\r
+ if (refString != null)\r
+ {\r
+ sqanddels[c] = getSequenceAndDeletions(refString, GapChar);\r
+ } else {\r
+ sqanddels[c] = null;\r
+ }\r
+ }\r
+ return sqanddels;\r
+ }\r
+ /**\r
+ * NOTE: this is an improper sequence string function\r
+ * @return String formed by newline concatenated results of applying CIGAR operations to each reference object in turn.\r
+ * @param GapChar char\r
+ * @return '\n' separated strings (empty results included as \n\n)\r
+ */\r
+ public String getSequenceString(char GapChar)\r
+ {\r
+ if (length==0 || refCigars==null)\r
+ return "";\r
+ StringBuffer seqStrings = new StringBuffer();\r
+ Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);\r
+ for (int c=0; c<refCigars.length; c++) {\r
+ if (sqanddels[c]!=null) {\r
+ seqStrings.append( (String) sqanddels[c][0]);\r
+ sqanddels[c][0] = null;\r
+ }\r
+ seqStrings.append('\n');\r
+ }\r
+ return seqStrings.toString();\r
+ }\r
+ /**\r
+ * return string results of applying cigar string to all reference cigars\r
+ * @param GapChar char\r
+ * @return String[]\r
+ */\r
+ public String[] getSequenceStrings(char GapChar) {\r
+\r
+ if (length==0 || refCigars==null || refCigars.length==0)\r
+ return null;\r
+ Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);\r
+ String[] seqs = new String[sqanddels.length];\r
+ for (int c=0; c<refCigars.length; c++) {\r
+ seqs[c] = (String) sqanddels[c][0];\r
+ }\r
+ return seqs;\r
+ }\r
+ /**\r
+ * Combines the CigarArray cigar operations with the operations in each\r
+ * reference cigar - creating a new reference cigar\r
+ * @return Cigar[]\r
+\r
+ public CigarBase[] getEditedCigars() {\r
+\r
+ return new CigarBase[] {};\r
+ }\r
+*/\r
+ /**\r
+ * applyDeletions\r
+ * edits underlying refCigars to propagate deleted regions, and removes deletion\r
+ * operations from CigarArray operation list.\r
+ * @return int[] position where deletion occured in cigarArray or null if none occured\r
+ */\r
+ public int[] applyDeletions()\r
+ {\r
+ java.util.Vector delpos=null;\r
+ if (length==0)\r
+ return null;\r
+ int cursor=0; // range counter for deletions\r
+ int vcursor=0; // visible column index\r
+ for (int i=0; i<length; i++) {\r
+ if (operation[i]!=D) {\r
+ if (operation[i]==M)\r
+ cursor+=range[i];\r
+ vcursor+=range[i];\r
+ }\r
+ else\r
+ {\r
+ if (delpos==null)\r
+ delpos=new java.util.Vector();\r
+ int delstart=cursor, delend=cursor+range[i]-1; // inclusive\r
+ delpos.addElement(new Integer(vcursor-1)); // index of left hand column of hidden region boundary\r
+ System.arraycopy(operation, i+1, operation, i, length-i);\r
+ System.arraycopy(range, i+1, range, i, length-i);\r
+ length--;\r
+ for (int s=0; s<refCigars.length; s++) {\r
+ refCigars[s].deleteRange(delstart, delend);\r
+ }\r
+ }\r
+ }\r
+ if (delpos!=null)\r
+ {\r
+ int[] pos=new int[delpos.size()];\r
+ for (int k = 0, l = delpos.size(); k < l; k++) {\r
+ pos[k] = ((Integer) delpos.elementAt(k)).intValue();\r
+ delpos.setElementAt(null,k);\r
+ }\r
+ delpos=null;\r
+ return pos;\r
+ }\r
+ return null;\r
+ }\r
+ /**\r
+ *\r
+ * @return SeqCigar[] or null if CigarArray is not a SeqCigarArray (ie it does not resolve to set of seqCigars)\r
+ */\r
+ public SeqCigar[] getSeqCigarArray() {\r
+ if (!isSeqCigarArray())\r
+ return null;\r
+ SeqCigar[] sa = new SeqCigar[refCigars.length];\r
+ for (int i=0; i<refCigars.length; i++)\r
+ sa[i] = (SeqCigar) refCigars[i];\r
+ return sa;\r
+ }\r
+}\r