Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HatsuneCode authored and cran-robot committed Mar 16, 2022
0 parents commit c89aa45
Show file tree
Hide file tree
Showing 42 changed files with 1,666 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,21 @@
Package: TrustVDJ
Title: Tools for Immune Repertoire Analysis
Version: 0.1.0
Authors@R:
person('Lianhao', 'Song', , 'hatsunecode@gmail.com', role = c('aut', 'cre'),
comment = c(ORCID = '0000-0002-3211-3726'))
Description: A toolkit for read and prepare immune repertoire data. 'TrustVDJ' package focuses on the reading and processing of 'TRUST4' and '10x cellranger' software output results by using 'ReadTrust' and 'Read10x' functions, respectively, and also provides a convenience function 'build_IMGT_reference' to download the 'IMGT' database reference and split its sequences by species.
BugReports: https://github.com/HatsuneCode/TrustVDJ/issues
License: GPL (>= 3)
Encoding: UTF-8
RoxygenNote: 7.1.2
Collate: 'constants.r' 'utils.r' 'class.r' 'download.r' 'read10x.r'
'readTrust.r' 'refIMGT.r' 'test.r'
Imports: Biostrings, data.table, methods, rvest, stats
Suggests: R.utils
NeedsCompilation: no
Packaged: 2022-03-16 08:16:27 UTC; lhsong
Author: Lianhao Song [aut, cre] (<https://orcid.org/0000-0002-3211-3726>)
Maintainer: Lianhao Song <hatsunecode@gmail.com>
Repository: CRAN
Date/Publication: 2022-03-16 21:00:02 UTC
41 changes: 41 additions & 0 deletions MD5
@@ -0,0 +1,41 @@
3dcd1af1ade569b81e1690b319f8689f *DESCRIPTION
330a22f075386d0cea96fdf1d43ff415 *NAMESPACE
99c5af9bf8918bef2051ce820a841e9b *NEWS.md
3b26c0338bee9a74dc3fc587f5e5f4d9 *R/class.r
edd09ab4bbba2a7a1594a2a390899df0 *R/constants.r
56054decdb3f60cece294fe9fd814f4f *R/download.r
8ccc63cdf851ef4aa7d94e6029bfae13 *R/read10x.r
56b5efe3be779c340d1c99e8bd7f21f4 *R/readTrust.r
fee3c1c86f960c7b8ca7dab5a2605a44 *R/refIMGT.r
2baa72de3d43675f61d7f2f5b4da79d2 *R/test.r
6038a55230ccc5b7911a25ff767a8a5d *R/utils.r
605522a6def929a6708a805568fd0b18 *README.md
e649fe45c3c94eab9770a9d39f10a4e2 *inst/extdata/10x_airr_rearrangement.tsv.gz
68d5eedbfaf18969ab935d1860814194 *inst/extdata/10x_all_contig_annotations.csv.gz
3a8de95b03714801fbb2fd50619f6117 *inst/extdata/10x_clonotypes.csv.gz
00c1d6e8f285d40f8241875577505824 *inst/extdata/10x_consensus_annotations.csv.gz
617775d41da98dc2e263597fa339ee32 *inst/extdata/10x_filtered_contig_annotations.csv.gz
c6cba81dadbf4a54b10dd92f12a83ba8 *inst/extdata/TRUST4_airr.tsv.gz
03579825a4f909a18102d8f416a79a39 *inst/extdata/TRUST4_barcode_airr.tsv.gz
08a80d64f7f0f3461394efe43e5258f5 *inst/extdata/TRUST4_barcode_report.tsv.gz
e3226ad8f9bcbc869768b258a2ec0fdb *inst/extdata/TRUST4_report.tsv.gz
58260e0dde22ddf36b483b00e019665a *man/Download.Rd
a37b435443faee6f0592a045080f1628 *man/Ifnone.Rd
c2c076be4766faa490d4fb14a7246c3d *man/Ifnull.Rd
287d4fc9becb0013cb6c94ab25059a45 *man/Read10x.Rd
ff8e7a8d32293646cbe237c4b75604ff *man/ReadTrust.Rd
45d1b64fa5362e96817beb9a2c609ab8 *man/Trust-class.Rd
4b14d137fe2ac42a0ae308d8fe77dcf0 *man/build_IMGT_reference.Rd
e4a8a546e6df44a4a612105ec088436a *man/cbinds.Rd
856424d513dd4096a532ccb8b06cdfb8 *man/consensus-class.Rd
8ed573149b71532dc4add472d4f12061 *man/corTest.Rd
af915e25d696912a8fd4c7203bc14e26 *man/df_chain.Rd
c354c10cc711fcc10179db46e4b8f7c6 *man/dot-Read10x_clonotype.Rd
02e7b4d17f542c3faef0d0d0a724cc08 *man/dot-Read10x_consensus.Rd
fa0f3d7783556d35271fd76421a195da *man/dot-Read10x_contig.Rd
bb8b049ab6e6343c8070c52a6805d114 *man/dot-ReadAIRR.Rd
99fba0ea5a868339205cab12751c08d6 *man/dot-ReadTrust_BarcodeReport.Rd
d29c9a85af4deecd0fb06880d742fbbd *man/dot-ReadTrust_Report.Rd
4c26bcaee8bcdd5727b46d8ca64d03ba *man/show-Trust-method.Rd
038dda9ce2bc7f82b9b2d857dc002f6f *man/show-consensus-method.Rd
8c0089df41287803f4012ca41696c016 *man/timer.Rd
36 changes: 36 additions & 0 deletions NAMESPACE
@@ -0,0 +1,36 @@
# Generated by roxygen2: do not edit by hand

export("%||%")
export("%|||%")
export(.Read10x_clonotype)
export(.Read10x_consensus)
export(.Read10x_contig)
export(.ReadAIRR)
export(.ReadTrust_BarcodeReport)
export(.ReadTrust_Report)
export(Download)
export(Read10x)
export(ReadTrust)
export(build_IMGT_reference)
export(cbinds)
export(corTest)
export(df_chain)
export(timer)
exportClasses(Trust)
exportClasses(consensus)
exportMethods(show)
importFrom(Biostrings,chartr)
importFrom(Biostrings,readBStringSet)
importFrom(Biostrings,writeXStringSet)
importFrom(data.table,fread)
importFrom(methods,new)
importFrom(methods,show)
importFrom(rvest,html_node)
importFrom(rvest,html_text)
importFrom(rvest,read_html)
importFrom(stats,cor.test)
importFrom(stats,p.adjust)
importFrom(stats,setNames)
importFrom(utils,download.file)
importFrom(utils,setTxtProgressBar)
importFrom(utils,txtProgressBar)
4 changes: 4 additions & 0 deletions NEWS.md
@@ -0,0 +1,4 @@
# TrustVDJ 0.1.0

- Initial release of TrustVDJ.

102 changes: 102 additions & 0 deletions R/class.r
@@ -0,0 +1,102 @@
#' @include utils.r
NULL

#' The consensus class
#'
#' @slot Vgene character. V gene, eg.: TRAV1*01
#' @slot Dgene character. D gene, eg.: TRAD1*01
#' @slot Jgene character. J gene, eg.: TRAJ1*01
#' @slot Cgene character. C gene, eg.: TRAC1*01
#' @slot CDR1dna character. CDR1 nucleic acid sequence, eg.: TCTGAACACAACCGC
#' @slot CDR2dna character. CDR2 nucleic acid sequence, eg.: TTCCAGAATGAAGCTCAA
#' @slot CDR3dna character. CDR3 nucleic acid sequence, eg.: TGTGCCAGCAGCCTACGCAACGAGCAGTACTTC
#' @slot CDR3aa character. CDR3 amino acid sequence, eg.: CASSPTPGEATDTQYF
#' @slot Count numeric. Read counts, eg.: 200
#' @slot ID character. Consensus id, eg.: Sample1_consensus1
#' @slot CDR3germlineSimilarity numeric. CDR3 germline similarity score, eg.: 80
#' @slot FullLength logical. Whether the vdj gene is complete, eg.: TRUE
#'
#' @importFrom methods new
#'
#' @return An object of the consensus class
#' @export
#'
consensus = setClass('consensus', slots = c(
Vgene = 'character',
Dgene = 'character',
Jgene = 'character',
Cgene = 'character',
CDR1dna = 'character',
CDR2dna = 'character',
CDR3dna = 'character',
CDR3aa = 'character',
Count = 'numeric',
ID = 'character',
CDR3germlineSimilarity = 'numeric',
FullLength = 'logical'
))

#' Overview of the consensus class
#'
#' @param consensus class. An object of the consensus class
#' @param object class.
#'
#' @importFrom methods show
#'
#' @return Brief information about an consensus object
#' @export
#'
setMethod('show', 'consensus', function(object) {
cat(length(object@ID), 'consensus contain:\n',
sum(!is.na(object@Vgene)), 'Vgene,',
sum(!is.na(object@Dgene)), 'Dgene,',
sum(!is.na(object@Jgene)), 'Jgene,',
sum(!is.na(object@Cgene)), 'Cgene,',
sum(!is.na(object@CDR3dna)), 'CDR3_dna and',
sum(!is.na(object@CDR3aa)), 'CDR3_aa\n')
})

#' The Trust class
#'
#' The Trust object is the center of each single-cell immune repertoire analysis.
#' slots are listed below:
#'
#' @slot barcode character. Cell barcode in single-cell sequencing, eg: Sample1_ATGCCAGAACGACT.
#' @slot celltype character. Inferred cell type, such as: abT, gdT or B.
#' @slot Achain consensus. confident TCR/BCR Alpha-chain object.
#' @slot Bchain consensus. confident TCR/BCR Beta-chain object.
#' @slot Achain2 list. secondary TCR/BCR Alpha-chain objects.
#' @slot Bchain2 list. secondary TCR/BCR Beta-chain objects.
#'
#' @importFrom methods new
#'
#' @return An object of the trust4 class
#' @export
#'
Trust = setClass('Trust', slots = c(
barcode = 'character',
celltype = 'character',
Achain = 'consensus',
Bchain = 'consensus',
Achain2 = 'list',
Bchain2 = 'list'
))

#' Overview of the Trust class
#'
#' @param Trust class. An object of the Trust class
#' @param object class.
#'
#' @importFrom methods show
#'
#' @return Brief information about an consensus object
#' @export
#'
setMethod('show', 'Trust', function(object) {
cat('Trust object --', length(object@barcode), 'cells contain:\n celltype:',
unlist(lapply(unique(object@celltype), function(cell)
c(sum(object@celltype %in% cell), cell))) %|||% 'None', '\n')
cat(' Alpha-chain(confident):', length(object@Achain@ID), 'consensus \n')
cat(' Beta-chain (confident):', length(object@Bchain@ID), 'consensus \n')
})

10 changes: 10 additions & 0 deletions R/constants.r
@@ -0,0 +1,10 @@
## constants ##

# chain name for TRUST4 barcode report
chainName = c('v_call', 'd_call', 'j_call', 'c_call',
'cdr3', 'cdr3_aa', 'consensus_count', 'sequence_id',
'cdr3_germline_similarity', 'complete_vdj')

# consensus name for 10x clonotype report
consensusName = c('clonotype_id', 'consensus_id', 'clonotype_frequency', 'clonotype_proportion',
'cdr3', 'cdr3_aa', 'clonotype_inkt_evidence', 'clonotypemait_evidence')
74 changes: 74 additions & 0 deletions R/download.r
@@ -0,0 +1,74 @@
#' @include utils.r
NULL

#' Download files retryable
#'
#' @param URLs character/list. URLs to be downloaded.
#' @param names character/list. file names. Default \code{seq(URLs)}
#' @param method character. Method to be used for downloading files, equal to \code{download.file}. Default 'libcurl'
#' @param sleep numeric. retry interval (second). Default 2
#' @param outdir character. output directory.
#' @param verbose logical. Default TRUE
#'
#' @importFrom utils download.file
#'
#' @return if success, return TRUE
#' @export
#'
#' @examples
#' URLs = paste0('http://www.imgt.org//download/', c('V-QUEST/IMGT_V-QUEST_reference_directory',
#' 'GENE-DB/IMGTGENEDB-ReferenceSequences.fasta-nt-WithGaps-F+ORF+inframeP'))
#' \donttest{Download(URLs, c('vdj_species.html', 'IMGT_download.fa'))}
#'
Download = function(URLs, names = NULL, method = NULL, sleep = NULL, outdir = NULL, verbose = TRUE){

# check parameter #
URLs = as.character(unlist(URLs))
names = as.character(unlist(names) %|||% seq(URLs))
method = as.character(method %|||% 'libcurl')
sleep = as.numeric(sleep) %|||% 2
outdir = as.character(outdir %|||% getwd())

# set index
log = 'Download.log'
writeLines('ok', log)

for (i in seq(URLs)) {
name = names[i]
URL = URLs[i]

# check file
if(!length(list.files(outdir, paste0('^', name, '$')))) {

# download
if(verbose) cat('-->', timer(), i, ': downloading for', name, '<--\n')
tryCatch(download.file(URL, paste0(outdir, '/', name), method, TRUE),
error = function(e) {
writeLines('Erro', log)
warning('--! ', timer(), ' ', i, ': download fail for ', name, ' !--') })

# check index
Log = readLines(log)
if('ok' %in% Log & verbose) cat('-->', timer(), i, ': download ok for', name, '<--\n')

# retry
while ('Erro' %in% Log){
writeLines('ok', log)
tryCatch(download.file(URL, destfile = paste0(outdir, '/', name), method, TRUE),
error = function(e){
writeLines('Erro', log)
warning('--! ', timer(), ' ', i, ': download fail for ', name, ' !--') })

# check index
Log = readLines(log)
if('ok' %in% Log & verbose) cat('-->', timer(), i, ': download ok for', name, '<--\n')

# sleep
Sys.sleep(sleep)
}
} else warning('--! ', timer(), ' ', i, ': file already exist for ', name, ' !--')
}

# return
file.remove(log)
}

0 comments on commit c89aa45

Please sign in to comment.