I have 2 sequences with gaps:

    15888 CATG----ACAGAGCGACCCGCG--CACGTTACAAACACTACGCGGGGTGGCCCCGG
    42690 CATGCCCGACAGAGCGACCCGCGAACACGTTACAAACACTACG---GGTGGCCCCGG

I would like to encode indels in binary form. Gap is marked with 0 and no gap is 1. I want to receive something like this:

    15888 0 0 1
    42690 1 1 0

Thanks for any answer.
As suggested, consider the *the larger question*. But, based on assumptions from your example, looks like an interesting problem.

Here is using *R*, not going to explain the code in detail. In short, find position of `"-"` in all strings, create groups based on consecutive positions, i.e.: make *"indels"* ranges, then compare those position for each string.

    foo <- function(x){
      xSplit <- strsplit(x, "")
      
      # indels
      indels <- unique(
        unlist(
          lapply(xSplit, function(i){ 
            ix <- which(i == "-")
            g <- c(0, cumsum(diff(ix) > 1))
            split(ix, g)
          }),  recursive = FALSE))
      # sort by position
      indels <- indels[order(sapply(indels, `[`, 1), lengths(indels))]
      names(indels) <- paste0("indel_", seq(length(indels)))
      
      # return binary
      t(
        sapply(xSplit, function(i){
          sapply(indels, function(j){
            !all(i[ j ] == "-")
          })
        }) * 1
      )
    }
    # example data
    x1 <- c("CATG----ACAGAGCGACCCGCG--CACGTTACAAACACTACGCGGGGTGGCCCCGG",
            "CATGCCCGACAGAGCGACCCGCGAACACGTTACAAACACTACG---GGTGGCCCCGG")
    x2 <- c("CATG----ACAGAGCGACCCGCG--CACGTTACAAACACTACGCGGGGTGGCCCCGG",
            "CATGCCCGACAGAGCGACCCGCGAACACGTTACAAACACTACG---GGTGGCCCCGG",
            "CATG----ACAGA---ACCCGCG--CACGTTACAAACACTACGCGGGGTGGCCCCGG")
    
    # test
    foo(x1)
    #      indel_1 indel_2 indel_3
    # [1,]       0       0       1
    # [2,]       1       1       0
    
    foo(x2)
    #      indel_1 indel_2 indel_3 indel_4
    # [1,]       0       1       0       1
    # [2,]       1       1       1       0
    # [3,]       0       0       0       1

