Skip to content

Commit 472692c

Browse files
Fixed bug in getTissueType; updated unit test
1 parent 376c144 commit 472692c

2 files changed

Lines changed: 93 additions & 61 deletions

File tree

R/NetworkDataCompanion.R

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,20 +547,22 @@ NetworkDataCompanion=setRefClass("NetworkDataCompanion",
547547
},
548548

549549
# return tissue type given an input barcode
550-
getTissueType = function(TCGA_barcode)
550+
getTissueType = function(TCGA_barcodes)
551551
{
552-
this_sample = substr(str_split(TCGA_barcode,"-",simplify=T)[1,4],1,2)
553-
if(!this_sample%in% sample_type_mapping$numcode)
552+
these_samples = extractSampleType(TCGA_barcodes)
553+
if(length(setdiff(these_samples,sample_type_mapping$numcode)>0))
554554
{
555-
print(paste("[NetworkDataCompanion::getTissueType()] Error: unknown sample type:",this_sample))
556-
return(NA)
555+
print(paste("[NetworkDataCompanion::getTissueType()] Error: unknown sample type(s):",setdiff(these_samples,sample_type_mapping$numcode)))
556+
return(NULL)
557557
}
558558

559-
this_map = data.frame("TCGA_barcode"=TCGA_barcode)
560-
row.names(this_map) = TCGA_barcode
561-
this_match = sample_type_mapping[which(as.numeric(sample_type_mapping$numcode) == as.numeric(this_sample)),]
562-
563-
return(cbind.data.frame(this_map,this_match))
559+
this_map = data.frame("TCGA_barcode" = TCGA_barcodes,
560+
"numcode" = these_samples,
561+
row.names = TCGA_barcodes)
562+
563+
out_map = this_map %>% left_join(sample_type_mapping, by="numcode") %>%
564+
dplyr::select("TCGA_barcode","description")
565+
return(out_map)
564566
},
565567
## access sample type map
566568
getSampleTypeMap = function(){
Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,89 @@
11
context("[NetworkDataCompanion] Testing getTissueType function ... ")
22

3-
test_that("Testing getTissueType",{
3+
numcodes <- c(
4+
"01",
5+
"02",
6+
"03",
7+
"04",
8+
"05",
9+
"06",
10+
"07",
11+
"08",
12+
"09",
13+
"10",
14+
"11",
15+
"12",
16+
"13",
17+
"14",
18+
"15",
19+
"16",
20+
"20",
21+
"40",
22+
"50",
23+
"60",
24+
"61",
25+
"99"
26+
)
27+
28+
descriptions <- c(
29+
"Primary Solid Tumor",
30+
"Recurrent Solid Tumor",
31+
"Primary Blood Derived Cancer - Peripheral Blood",
32+
"Recurrent Blood Derived Cancer - Bone Marrow",
33+
"Additional - New Primary",
34+
"Metastatic",
35+
"Additional Metastatic",
36+
"Human Tumor Original Cells",
37+
"Primary Blood Derived Cancer - Bone Marrow",
38+
"Blood Derived Normal",
39+
"Solid Tissue Normal",
40+
"Buccal Cell Normal",
41+
"EBV Immortalized Normal",
42+
"Bone Marrow Normal",
43+
"sample type 15",
44+
"sample type 16",
45+
"Control Analyte",
46+
"Recurrent Blood Derived Cancer - Peripheral Blood",
47+
"Cell Lines",
48+
"Primary Xenograft Tissue",
49+
"Cell Line Derived Xenograft Tissue",
50+
"sample type 99"
51+
)
52+
my_friend = NetworkDataCompanion::CreateNetworkDataCompanionObject()
53+
54+
test_that("Testing getTissueType for a single TCGA barcode",{
455

5-
my_friend = NetworkDataCompanion::CreateNetworkDataCompanionObject()
6-
numcodes <- c(
7-
"01",
8-
"02",
9-
"03",
10-
"04",
11-
"05",
12-
"06",
13-
"07",
14-
"08",
15-
"09",
16-
"10",
17-
"11",
18-
"12",
19-
"13",
20-
"14",
21-
"15",
22-
"16",
23-
"20",
24-
"40",
25-
"50",
26-
"60",
27-
"61",
28-
"99"
29-
)
30-
descriptions <- c(
31-
"Primary Solid Tumor",
32-
"Recurrent Solid Tumor",
33-
"Primary Blood Derived Cancer - Peripheral Blood",
34-
"Recurrent Blood Derived Cancer - Bone Marrow",
35-
"Additional - New Primary",
36-
"Metastatic",
37-
"Additional Metastatic",
38-
"Human Tumor Original Cells",
39-
"Primary Blood Derived Cancer - Bone Marrow",
40-
"Blood Derived Normal",
41-
"Solid Tissue Normal",
42-
"Buccal Cell Normal",
43-
"EBV Immortalized Normal",
44-
"Bone Marrow Normal",
45-
"sample type 15",
46-
"sample type 16",
47-
"Control Analyte",
48-
"Recurrent Blood Derived Cancer - Peripheral Blood",
49-
"Cell Lines",
50-
"Primary Xenograft Tissue",
51-
"Cell Line Derived Xenograft Tissue",
52-
"sample type 99"
53-
)
5456
barcode = "TCGA-A1-1234-"
5557
for(numcode in numcodes){
5658
expect_equal(as.character(my_friend$getTissueType(paste0(barcode, numcode))['description']), descriptions[numcodes == numcode])
5759
}
58-
expect_true(is.na(as.character(my_friend$getTissueType(paste0(barcode, "53"))['description'])))
60+
expect_true(is.null(my_friend$getTissueType(paste0(barcode, "53"))))
61+
})
62+
63+
test_that("Testing getTissueType vectorizes properly",{
64+
65+
barcode1 = "TCGA-A1-1234-01A"
66+
barcode2 = "TCGA-A1-1234-10A"
67+
barcode3 = "TCGA-A1-1234-10B"
68+
barcode4 = "TCGA-A1-1234-02A"
69+
barcodes = c(barcode1,
70+
barcode2,
71+
barcode3,
72+
barcode4)
73+
74+
expect_equal(my_friend$getTissueType(c(barcode1,
75+
barcode2,
76+
barcode3,
77+
barcode4))$description,
78+
c(descriptions[1],
79+
descriptions[10],
80+
descriptions[10],
81+
descriptions[2]))
82+
})
83+
84+
test_that("Testing getTissueType is not bamboozled by extra suffix items",{
85+
86+
barcode = "TCGA-A1-1234-01A-1989"
87+
expect_equal(my_friend$getTissueType(barcode)$description,descriptions[1])
88+
5989
})

0 commit comments

Comments
 (0)