Coder Social home page Coder Social logo

Comments (2)

ahurbanski avatar ahurbanski commented on July 21, 2024

Hey @gustavjoh.

I was facing the same issue trying to use the pubRepApply function. This is how dealt with it:

I searched for the function code with trace(pubRepApply, edit = T) and copied it to my script with another name, but changing the original line

pr.res = dplyr::inner_join(.pr1, .pr2, by = col_before_samples)

for this

pr.res = as.data.table(dplyr::inner_join(.pr1, .pr2, by = col_before_samples))

as it follows:

my_function <- function (.pr1, .pr2, .fun = function(x) log10(x[1])/log10(x[2])) 
{
  col_before_samples = names(.pr1)[1:(match("Samples", colnames(.pr1)) - 
                                        1)]
  tmp = rowMeans(public_matrix(.pr1), na.rm = T)
  .pr1[, (match("Samples", colnames(.pr1)) + 1):ncol(.pr1)] = NULL
  .pr1[["Quant"]] = tmp
  tmp = rowMeans(public_matrix(.pr2), na.rm = T)
  .pr2[, (match("Samples", colnames(.pr2)) + 1):ncol(.pr2)] = NULL
  .pr2[["Quant"]] = tmp
  pr.res = as.data.table(dplyr::inner_join(.pr1, .pr2, by = col_before_samples))
  pr.res[["Samples.x"]] = pr.res[["Samples.x"]] + pr.res[["Samples.y"]]
  pr.res[, `:=`(Samples.y, NULL)]
  names(pr.res)[match("Samples.x", colnames(pr.res))] = "Samples"
  pr.res[["Result"]] = apply(pr.res[, c("Quant.x", "Quant.y")], 
                             1, .fun)
  add_class(pr.res, "immunr_public_repertoire_apply")
}

Then calling the new function:

pr3 = my_function(pr1, pr2)

I don't know how the output was intended to be, but I think it's working fine now.

Hope it helps.

from immunarch.

gustavjoh avatar gustavjoh commented on July 21, 2024

Thank you!

Your solution works, seems like the line causing the problem is the one below.

pr.res[, ':='(Samples.y, NULL)]

What I can see is that it only removes the column "Samples.y" so that line could also be replaced by the code below, perhaps not as clean code. But at least it doesn't change the datatype.

'pr.res = dplyr::select(pr.res, -Samples.y)'

Hope this is fixed in the next version

Thank you again!

from immunarch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.