Hi Humberto, It may simply be that the file is C(omma)SV format and the default separator for read.delim is a TAB character. Try read.csv. Jim On Tue, Jun 21, 2016 at 2:14 AM, Humberto Munoz Barona
<hmunoz40 at hotmail.com> wrote:
Hi Jim, Thanks for your reply. length(lens) gives me 6, which is the size of lens in the previous run with a shorter file. length(data1)=1, that means data1 is not reading the data from the file DarkAerobic1.CSV, which contains the four columns in this order Gene ID, Length, ReadCount, and Normalized Coverage. I want the vector lens = Length and cnts = ReadCounts. How I can make this import of data correctly?
> data1 <- read.delim("DarkAerobic1.CSV", check.names=FALSE, stringsAsFactors=FALSE)
lenght(data1)
Error: could not find function "lenght"
length(data1)
[1] 1 I need to calculate two normalizations with the vectors lens and cnts, and have the two options for sorting the normalizations up or down. Thanks for any help you can give me to fix this issue. Humberto
On Jun 18, 2016, at 12:19 AM, Jim Lemon <drjimlemon at gmail.com> wrote: Hi Humberto, The "0 row" error usually arises from a calculation in which a non-existent object is used. I see that you have created a vector with the name "lens" and that may be where this is happening. Have a look at: length(lens) or if it is not too long, just: lens If it is zero length, that is your problem. This might be due to "data1" not having a column named "Length" or it may not contain numeric values (i.e. a factor).. Jim On Sat, Jun 18, 2016 at 9:53 AM, Humberto Munoz Barona <hmunoz40 at hotmail.com> wrote:
I am running the following R-code
countToTpm <- function(counts, effLen)
{
rate <- log(counts) - log(effLen)
denom <- log(sum(exp(rate)))
exp(rate - denom + log(1e6))
}
countToFpkm <- function(counts, effLen)
{
N <- sum(counts)
exp( log(counts) + log(1e9) - log(effLen) - log(N) )
}
fpkmToTpm <- function(fpkm)
{
exp(log(fpkm) - log(sum(fpkm)) + log(1e6))
}
countToEffCounts <- function(counts, len, effLen)
{
counts * (len / effLen)
}
################################################################################
# An example
################################################################################
data1 <- read.delim("Dark Aerobic1.csv", check.names=FALSE, stringsAsFactors=FALSE)
cnts <- data1['ReadCount']
lens <- data1['Length']
countDf <- data.frame(count = cnts, length = lens)
# assume a mean(FLD) = 170.71
countDf$effLength <- countDf$length - 170.71 + 1
countDf$tpm <- with(countDf, countToTpm(count, effLength))
countDf$fpkm <- with(countDf, countToFpkm(count, effLength))
with(countDf, all.equal(tpm, fpkmToTpm(fpkm)))
countDf$effCounts <- with(countDf, countToEffCounts(count, length, effLength))
I am receiving the errors
countDf$effLength <- countDf$length - 170.71 + 1
Error in `$<-.data.frame`(`*tmp*`, "effLength", value = numeric(0)) : replacement has 0 rows, data has 2809
countDf$tpm <- with(countDf, countToTpm(count, effLength))
Error in countToTpm(count, effLength) : object 'count' not found
countDf$fpkm <- with(countDf, countToFpkm(count, effLength))
Error in countToFpkm(count, effLength) : object 'count' not found
with(countDf, all.equal(tpm, fpkmToTpm(fpkm)))
Error in all.equal(tpm, fpkmToTpm(fpkm)) : object 'tpm' not found
countDf$effCounts <- with(countDf, countToEffCounts(count, length, effLength))
Error in countToEffCounts(count, length, effLength) : object 'count' not found
Thanks for any help to fix this error Humberto Munoz
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.