Defines functions alignLigands

alignLigands<-function(patterns, n, verbose){

  print("Aligning Ligands...")
  blockLen <- (n*2)+2 # +1 for L +1 for dash or plus sign
  rows <- as.integer(length(patterns[,1]))  # max col length
  cols <- as.integer(length(patterns[1,]))  # max row length
  patternsMat<-as.matrix(patterns)          # make an input copy and turns it to a matrix
  # creating the matrix that will contain the aligned ligands
  new.cols= length(patterns[1,])*blockLen # worst case scenario: all the residues are ligands
  new.patterns <- matrix(NA,nrow=rows, ncol=new.cols) 
  # creating the header for new.patterns
  header<-rep("x", new.cols) # replicate X
  ligandPos<-seq(blockLen-n-1, new.cols-n, by = blockLen) # generate positions of ligands
  header[ligandPos] <- "L" # substitute L in the x replication
  print("Calculating new positions...")
  for (i in 1:rows){
    for (j in 1:cols){
      # if it's a ligand and header[j]!="L"
      if(((identical(substr(as.character(patternsMat[i,j]), 1, 1), "("))&&((!(header[k]=="L"))&&(!(is.na(header[k]=="L")))))){
        # insert a shift
        shiftPos<- shift(k, closestCenterPos(k, ligandPos))
        if(verbose == 1) print(paste("shift",patternsMat[i,j],"to position",k))

      new.patterns[i, k] <- patternsMat[i, j]

  df.patterns<-as.data.frame(new.patterns, stringsAsFactors = FALSE)  # convert to a data.frame
  names(df.patterns)<-header                 # update the header of the data.frame
  # df.patterns <- df.patterns[,colSums(is.na(df.patterns))<nrow(df.patterns)]
  df.patterns[is.na(df.patterns)] <- "*"

Try the PdPDB package in your browser

Any scripts or data that you put into this service are public.

PdPDB documentation built on Nov. 17, 2017, 5:09 a.m.