1 package jalview.datamodel;
3 public class CigarArray extends CigarBase
6 * Do CIGAR operations on a set of sequences from many other cigars
7 * BAD THINGS WILL HAPPEN IF A CIGARARRAY IS PASSED TO A CIGARARRAY
8 * or a CIGARCIGAR is given a CIGARARRAY to insert gaps into.
11 * array of subject cigars
13 public CigarSimple refCigars[]=null;
14 private boolean seqcigararray=false;
15 private CigarArray() {
21 * @return boolean true if all refCigars resolve to a SeqCigar or a CigarCigar
23 public boolean isSeqCigarArray()
29 * Apply CIGAR operations to several cigars in parallel
30 * will throw an error if any of cigar are actually CigarArrays.
31 * @param cigar Cigar[]
33 public CigarArray(CigarSimple[] cigars) {
36 if (cigars != null && cigars.length > 0)
38 refCigars = new CigarSimple[cigars.length];
39 for (int c = 0; c < cigars.length; c++)
41 refCigars[c] = cigars[c];
42 if (! ( (cigars[c] instanceof SeqCigar)
43 || cigars[c] instanceof CigarCigar))
45 seqcigararray = false;
51 * @see Cigar.getSequenceAndDeletions
55 protected Object[][] getArrayofSequenceAndDeletions(char GapChar) {
56 if (refCigars == null || refCigars.length == 0 || length == 0) {
59 Object[][] sqanddels = new Object[refCigars.length][];
60 for (int c=0; c<refCigars.length; c++) {
61 String refString = refCigars[c].getSequenceString(GapChar);
62 if (refString != null)
64 sqanddels[c] = getSequenceAndDeletions(refString, GapChar);
72 * NOTE: this is an improper sequence string function
73 * @return String formed by newline concatenated results of applying CIGAR operations to each reference object in turn.
75 * @return '\n' separated strings (empty results included as \n\n)
77 public String getSequenceString(char GapChar)
79 if (length==0 || refCigars==null)
81 StringBuffer seqStrings = new StringBuffer();
82 Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);
83 for (int c=0; c<refCigars.length; c++) {
84 if (sqanddels[c]!=null) {
85 seqStrings.append( (String) sqanddels[c][0]);
86 sqanddels[c][0] = null;
88 seqStrings.append('\n');
90 return seqStrings.toString();
93 * return string results of applying cigar string to all reference cigars
97 public String[] getSequenceStrings(char GapChar) {
99 if (length==0 || refCigars==null || refCigars.length==0)
101 Object[][] sqanddels = getArrayofSequenceAndDeletions(GapChar);
102 String[] seqs = new String[sqanddels.length];
103 for (int c=0; c<refCigars.length; c++) {
104 seqs[c] = (String) sqanddels[c][0];
109 * Combines the CigarArray cigar operations with the operations in each
110 * reference cigar - creating a new reference cigar
113 public CigarBase[] getEditedCigars() {
115 return new CigarBase[] {};