Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrices, son. #39

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions R/simulate_experiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,6 @@ simulate_experiment = function(fasta=NULL, gtf=NULL, seqpath=NULL,
stop('must provide either fasta or both gtf and seqpath')
}

if(length(num_reps) == 1){
fold_changes = rep(1, length(transcripts))
}

# check fold change matrix dimensions:
.check_fold_changes(fold_changes, num_reps, transcripts)

Expand All @@ -367,12 +363,39 @@ simulate_experiment = function(fasta=NULL, gtf=NULL, seqpath=NULL,
logmus = b0 + b1*log2(width(transcripts)) + rnorm(length(transcripts),0,sigma)
reads_per_transcript = 2^logmus-1
}
basemeans = reads_per_transcript * fold_changes

if(length(num_reps) == 1){
fold_changes = matrix(rep(1, length(transcripts)))
} else if(length(num_reps) == 2) {
# This means fold_changes is a numeric vector, per the check function
if(length(reads_per_transcript) == 1) {
basemeans = matrix(reads_per_transcript, ncol=2, nrow=length(transcripts))
basemeans[,2] = fold_changes * basemeans[,1]
} else if(length(reads_per_transcript) == length(transcripts)){
basemeans = matrix(c(reads_per_transcript, reads_per_transcript), nrow=length(reads_per_transcript))
basemeans[,2] = fold_changes * basemeans[,1]
} else {
stop('reads_per_transcript is the wrong length.')
}
} else {
basemeans = reads_per_transcript * fold_changes
}

if(is.null(size)){
size = basemeans / 3
}else if(class(size) == 'numeric'){
size = matrix(size, nrow=nrow(basemeans), ncol=ncol(basemeans))
if(is.matrix(basemeans)){
num_rows = nrow(basemeans)
num_cols = ncol(basemeans)
} else {
num_rows = length(basemeans)
num_cols = 1
}
size = matrix(size, nrow=num_rows, ncol=num_cols)
}else if(class(size) == 'matrix'){
if(!is.matrix(basemeans)){
stop('If you provide a matrix for size, you also need a matrix for reads_per_transcript.')
}
stopifnot(nrow(size) == nrow(basemeans))
stopifnot(ncol(size) == ncol(basemeans))
}else{
Expand Down