Skip to content

Commit 9671796

Browse files
committed
Conditionally display legend
1 parent 59fd7f1 commit 9671796

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/sv-pipeline/scripts/vcf_qc/analyze_fams.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,12 @@ plotDNRvsSize <- function(DNRs, bins, k=4, title=NULL, legend=T,
688688

689689
#Add legend
690690
if(legend==T){
691-
idx.for.legend <- which(apply(DNRs, 1, function(vals){any(!is.na(vals))}))
692-
legend("topright", bg="white", pch=19, cex=0.8*cex.lab, lwd=2,
693-
legend=rownames(DNRs)[idx.for.legend],
694-
col=colors[idx.for.legend])
691+
idx.for.legend <- which(apply(DNRs, 1, function(vals){any(!is.na(vals) & !is.infinite(vals) & vals>0)}))
692+
if(length(idx.for.legend) > 0) {
693+
legend("topright", bg="white", pch=19, cex=0.8*cex.lab, lwd=2,
694+
legend=rownames(DNRs)[idx.for.legend],
695+
col=colors[idx.for.legend])
696+
}
695697
}
696698

697699
#Add title & number of families
@@ -776,9 +778,11 @@ plotDNRvsFreq <- function(DNRs, bins, k=4, title=NULL, legend=T,
776778
#Add legend
777779
if(legend==T){
778780
idx.for.legend <- which(apply(DNRs, 1, function(vals){any(!is.na(vals))}))
779-
legend("topright", bg="white", pch=19, cex=0.7, lwd=3,
780-
legend=rownames(DNRs)[idx.for.legend],
781-
col=colors[idx.for.legend])
781+
if(length(idx.for.legend) > 0) {
782+
legend("topright", bg="white", pch=19, cex=0.7, lwd=3,
783+
legend=rownames(DNRs)[idx.for.legend],
784+
col=colors[idx.for.legend])
785+
}
782786
}
783787

784788
#Add title & number of families
@@ -840,9 +844,11 @@ plotDNRvsGQ <- function(DNRs, bins, k=4, title=NULL, xlabel="Mininum GQ",
840844
#Add legend
841845
if(legend==T){
842846
idx.for.legend <- which(apply(DNRs, 1, function(vals){any(!is.na(vals))}))
843-
legend("topright", bg="white", pch=19, cex=0.7, lwd=3,
844-
legend=rownames(DNRs)[idx.for.legend],
845-
col=colors[idx.for.legend])
847+
if(length(idx.for.legend) > 0) {
848+
legend("topright", bg="white", pch=19, cex=0.7, lwd=3,
849+
legend=rownames(DNRs)[idx.for.legend],
850+
col=colors[idx.for.legend])
851+
}
846852
}
847853

848854
#Add title & number of families

0 commit comments

Comments
 (0)