-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a function check_tx_names to change sig_transcripts if ENSEMBL
Co-authored-by: Nick Eagles <[email protected]>
- Loading branch information
1 parent
249b7e4
commit 1b49012
Showing
2 changed files
with
47 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' Check validity of transcript vectors | ||
|
||
#' @export | ||
|
||
|
||
check_tx_names = function(tx1, tx2, arg_name1, arg_name2) { | ||
# Functions for checking whether a vector of transcripts all match GENCODE | ||
# or ENSEMBL naming conventions | ||
is_gencode = function(x) all(grepl("^ENST.*?\\.", x)) | ||
is_ensembl = function(x) all(grepl("^ENST", x) & !grepl("\\.", x)) | ||
|
||
# Check that both vectors either follow GENCODE or ENSEMBL | ||
if (!is_gencode(tx1) && !is_ensembl(tx1)) { | ||
stop( | ||
sprintf( | ||
"'%s' must use either all GENCODE or all ENSEMBL transcript IDs", | ||
arg_name1 | ||
) | ||
) | ||
} | ||
if (!is_gencode(tx2) && !is_ensembl(tx2)) { | ||
stop( | ||
sprintf( | ||
"'%s' must use either all GENCODE or all ENSEMBL transcript IDs", | ||
arg_name2 | ||
) | ||
) | ||
} | ||
|
||
# Change 'tx2' to match 'tx1', noting that the case where 'tx1' is GENCODE | ||
# but 'tx2' is ENSEMBL is not allowed (and an error will be thrown further | ||
# down) | ||
if (is_gencode(tx2) && is_ensembl(tx1)) { | ||
tx2 = sub('\\..*', '', tx2) | ||
} | ||
|
||
# At least some transcripts must overlap between 'tx1' and 'tx2' | ||
if (!any(tx2 %in% tx1)) { | ||
stop(sprintf("None of '%s' are in '%s'", arg_name2, arg_name1)) | ||
} | ||
|
||
# Since only 'tx2' was modified, return the changed copy | ||
return(tx2) | ||
} |