Skip to content

Error in validateInputs  #38

@Lewis-W-S-Fisher

Description

@Lewis-W-S-Fisher

Hi there,

I'm currently trying something really niche with fishplot. I'm trying to make fishplots from the output of pairtree. I have formatted the data according to what is specified. My samples drop to 0 across timepoints but this is expected with what i'm working with and fix.missing.clones=TRUE is selected in the settings.

The main error is:
Error in eval(ei, envir) : clones with same nest level cannot have values that sum to more than 100%: Problem is in clusters 2,5,10,11,13

I went into the source code and built the validateInput function (the part where it's failing anyway) into my code then corrected the sample where it was going wrong. The frac.table at this point has been corrected (when originally 101% the clustered added to 100%). The error still occurs though.

#!/usr/bin/env Rscript

library(fishplot)
library(rjson)

getNestLevel <- function(parents,x){
  #sanity checks
  if(x > length(parents)){
    stop(paste("cannot have a parent that does not exist in list. parent =",x,", length(parents) =",length(parents)))
  }
  if(x < 0){
    stop("cannot have a value in parents of less than zero")
  }
  
  if(parents[x] == 0){
    return(0)
  } else {
    return(getNestLevel(parents,parents[x])+1)
  }
}

getAllNestLevels <- function(parents){
  nest.level=c()
  for(i in 1:length(parents)){
    nest.level=c(nest.level, getNestLevel(parents,i))
  }
  return(nest.level)
}

## splitting the clustering plot into a separate script using output tables ## 
## Takes an argument where the input directory is the same as the prefix from cluster_variant.R ##
json_file<- "pap004_pairtree_tree.json"

json_data<- fromJSON(paste(readLines(json_file), collapse=""))

cluster_file<- "pap004_pairtree_cluster_names.json"
tree_names<- fromJSON(paste(readLines(cluster_file), collapse=""))
length(names(tree_names))
##! get population frequencies 
frac.table<- Reduce(rbind, json_data$phi[1:length(json_data$phi)]) # not eta
frac.table<- 100 * round(frac.table, 2)
colnames(frac.table)<- json_data$samples
rownames(frac.table)<- seq(0, nrow(frac.table )-1)
print(frac.table)


## get the structure of the clones, aka parents
## need to insert 0 in the beginning since 0 is the founder clone for everything. 'parents + 1' because python is 0-index and R/fishplot is 1. 
parents<- c(0, json_data$parents + 1) 

parent_names<- c(0, names(tree_names))

#visualization. distribute samples at regular interval from 0 to 100.
timepoints<- seq(0, 100, 100/(ncol(frac.table) - 1) )    


# "16759" 
# frac.table[c(5), c("16759")]<- 90
# print(frac.table[c(2,5,10,11,13), c("16759")]) 
# # print(colSums(frac.table[c(2,5,10,11,13),]))
# print(colSums(frac.table))

clones =  1:dim(frac.table)[1]
timepts = 1:dim(frac.table)[2]
print(clones)
print(timepts)

nest.level<- getAllNestLevels(parents)
print(frac.table[c(2,5,10,11,13), 23])

for(timept in timepts){
  for(i in unique(nest.level)){
    neighbors = which(nest.level==i)
    if(sum(frac.table[neighbors,timept]) > 100){
      print("First Issue \n")
      cur_vector<- frac.table[neighbors,timept]
      index_array<- which(cur_vector == max(cur_vector), arr.ind=TRUE)
      cur_vector[unname(index_array)]<- cur_vector[unname(index_array)] -1
      print(frac.table[parents[i], timept])
      
      frac.table[neighbors,timept]<- cur_vector
      print(parent_names[parents[i+1]])
      stop(paste("clones with same nest level cannot have values that sum to more than 100%: Problem is in clusters ",
                 paste(neighbors,collapse=",")))
    }
  }

  for(i in unique(parents)){
    if(i > 0){
      neighbors = which(parents==i)
      if(sum(frac.table[neighbors,timept]) > frac.table[parents[neighbors[1]],timept]){
        print(paste("clusters:", paste(neighbors, collapse=","), "timepoint:",timept))
        print(parent_names[neighbors])
        print(frac.table[neighbors, timept])
        # parent[i] + 1 seems to be the parent of neighbours
        print(parent_names[parents[i+1]])

        print(frac.table[parents[i], timept])
        # print(parents)
        # print(parent_names)
        # stop(paste("clones with same parent cannot have values that sum to more than the percentage of the parent: Problem is in clusters ",paste(neighbors,collapse=","),"at timepoint",timept))
      }
    }
  }
}
parent_names
length(row.names(frac.table))
print(frac.table[c(2,5,10,11,13), 54])

#create a fish object
fish = createFishObject(frac.table, parents, timepoints=timepoints, fix.missing.clones=TRUE)

Apologies for the scrappy code, i've been trying just about everything to get it to work. It's frankensteined together from some issues on the pairtree github :D so credit goes to them. I can send the files over if necessary.

All the best,
Lewis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions