public static int cigarRefLength(final String cigar){
  int refLen=0;
  int numStartPos=0;
  for (int i=0; i < cigar.length(); i++) {
    final char c=cigar.charAt(i);
    if (c < '0' || c > '9') {
switch (c) {
case 'M':
case 'D':
case 'N':
case 'P':
case '=':
case 'X':
        int mult=1;
      for (int j=i - 1; j >= numStartPos; j--) {
        refLen+=mult * (cigar.charAt(j) - '0');
        mult*=10;
      }
    break;
default :
  break;
}
numStartPos=i + 1;
}
}
return refLen;
}

public static int cigarRefLength ( final String cigar ) { int refLen = 0 ; int numStartPos = 0 ; for ( int i = 0 ; i < cigar . length ( ) ; i ++ ) { final char c = cigar . charAt ( i ) ; if ( c < '0' || c > '9' ) { switch ( c ) { case 'M' : case 'D' : case 'N' : case 'P' : case '=' : case 'X' : int mult = 1 ; for ( int j = i - 1 ; j >= numStartPos ; j -- ) { refLen += mult * ( cigar . charAt ( j ) - '0' ) ; mult *= 10 ; } break ; default : break ; } numStartPos = i + 1 ; } } return refLen ; }
determines the length of reference that this read covers given a cigar .
