public static byte[] unrollLegacyRead(final byte[] samRead,final byte[] gs,final String gc){
  final int overlap=gs.length;
  if (overlap == 0) {
    return samRead;
  }
 else {
    if (gc == null) {
      return null;
    }
    final ByteArrayOutputStream baos=new ByteArrayOutputStream();
    int lastCigarPos=0;
    int readPos=0;
    int attPos=0;
    while (true) {
      final int cigarPos=nextCigarPos(gc,lastCigarPos);
      if (cigarPos == -1) {
        break;
      }
      final int cigarLen=stringToInt(gc,lastCigarPos,cigarPos);
      if (cigarLen < 0) {
        return null;
      }
      if (gc.charAt(cigarPos) == 'S') {
        if (readPos + cigarLen > samRead.length) {
          return null;
        }
        baos.write(samRead,readPos,cigarLen);
        lastCigarPos=cigarPos + 1;
        readPos=readPos + cigarLen;
      }
 else {
        if (cigarLen == 0) {
          return null;
        }
        final int consumed=cigarLen * 2;
        if (attPos + consumed > gs.length) {
          return null;
        }
        baos.write(gs,attPos,consumed);
        attPos=attPos + consumed;
        lastCigarPos=cigarPos + 1;
        readPos+=cigarLen;
      }
    }
    if (readPos != samRead.length || lastCigarPos != gc.length() || attPos != gs.length) {
      return null;
    }
    return baos.toByteArray();
  }
}

public static byte [ ] unrollLegacyRead ( final byte [ ] samRead , final byte [ ] gs , final String gc ) { final int overlap = gs . length ; if ( overlap == 0 ) { return samRead ; } else { if ( gc == null ) { return null ; } final ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; int lastCigarPos = 0 ; int readPos = 0 ; int attPos = 0 ; while ( true ) { final int cigarPos = nextCigarPos ( gc , lastCigarPos ) ; if ( cigarPos == - 1 ) { break ; } final int cigarLen = stringToInt ( gc , lastCigarPos , cigarPos ) ; if ( cigarLen < 0 ) { return null ; } if ( gc . charAt ( cigarPos ) == 'S' ) { if ( readPos + cigarLen > samRead . length ) { return null ; } baos . write ( samRead , readPos , cigarLen ) ; lastCigarPos = cigarPos + 1 ; readPos = readPos + cigarLen ; } else { if ( cigarLen == 0 ) { return null ; } final int consumed = cigarLen * 2 ; if ( attPos + consumed > gs . length ) { return null ; } baos . write ( gs , attPos , consumed ) ; attPos = attPos + consumed ; lastCigarPos = cigarPos + 1 ; readPos += cigarLen ; } } if ( readPos != samRead . length || lastCigarPos != gc . length ( ) || attPos != gs . length ) { return null ; } return baos . toByteArray ( ) ; } }
reconstructs a cg read from the flattened , plus the extended attributes
