}
/**
- * turn a cigar string into a series of operation range pairs
- *
- * @param cigarString
- * String
- * @return object[] {char[] operation, int[] range}
- * @throws java.lang.Exception
- * for improperly formated cigar strings or ones with unknown
- * operations
- */
- public static Object[] parseCigarString(String cigarString)
- throws Exception
- {
- int ops = 0;
- for (int i = 0, l = cigarString.length(); i < l; i++)
- {
- char c = cigarString.charAt(i);
- if (c == M || c == (M - _case_shift) || c == I
- || c == (I - _case_shift) || c == D || c == (D - _case_shift))
- {
- ops++;
- }
- }
- char[] operation = new char[ops];
- int[] range = new int[ops];
- int op = 0;
- int i = 0, l = cigarString.length();
- while (i < l)
- {
- char c;
- int j = i;
- do
- {
- c = cigarString.charAt(j++);
- } while (c >= '0' && c <= '9' && j < l);
- if (j >= l && c >= '0' && c <= '9')
- {
- throw new Exception(MessageManager
- .getString("exception.unterminated_cigar_string"));
- }
- try
- {
- String rangeint = cigarString.substring(i, j - 1);
- range[op] = Integer.parseInt(rangeint);
- i = j;
- } catch (Exception e)
- {
- throw new Error(MessageManager
- .getString("error.implementation_bug_parse_cigar_string"));
- }
- if (c >= 'a' && c <= 'z')
- {
- c -= _case_shift;
- }
- if ((c == M || c == I || c == D))
- {
- operation[op++] = c;
- }
- else
- {
- throw new Exception(MessageManager.formatMessage(
- "exception.unexpected_operation_cigar_string_pos",
- new String[]
- { new StringBuffer(c).toString(),
- Integer.valueOf(i).toString(), cigarString }));
- }
- }
- return new Object[] { operation, range };
- }
-
- /**
* add an operation to cigar string
*
* @param op
}
/**
- * Create a cigar object from a cigar string like '[<I|D|M><range>]+' Will
- * fail if the given seq already contains gaps (JBPNote: future implementation
- * will fix)
- *
- * @param seq
- * SequenceI object resolvable to a dataset sequence
- * @param cigarString
- * String
- * @return Cigar
- */
- public static SeqCigar parseCigar(SequenceI seq, String cigarString)
- throws Exception
- {
- Object[] opsandrange = parseCigarString(cigarString);
- return new SeqCigar(seq, (char[]) opsandrange[0],
- (int[]) opsandrange[1]);
- }
-
- /**
* create an alignment from the given array of cigar sequences and gap
* character, and marking the given segments as visible in the given
* hiddenColumns.
assertEquals("Failed to recover ungapped sequence cigar operations",
"42M", cs_null);
testCigar_string(s_gapped, ex_cs_gapped);
- SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped);
- assertEquals("Failed parseCigar", ex_cs_gapped,
- gen_sgapped.getCigarstring());
-
- testSeqRecovery(gen_sgapped, s_gapped);
/*
* Test dataset resolution