0
$\begingroup$

I'm wondering how can I show unique gene names in the volcano plot.

My data looks like,

head(DMCf1_huMetGNc)
     chr    start    end.x       pvalue       qvalue meth.diff        gene
152 chr1 24909805 24909805 1.915400e-03 0.0168087962 -52.00000 RUNX3;RUNX3
168 chr1 24931440 24931440 8.645625e-03 0.0489503201  28.98551 RUNX3;RUNX3
179 chr1 26862096 26862096 1.308307e-04 0.0023224596 -42.48366         SFN
187 chr1 26914178 26914178 4.508416e-06 0.0001786963 -57.97872       NR0B2
188 chr1 26914203 26914203 5.337425e-05 0.0011910452 -47.30424       NR0B2
194 chr1 35573100 35573100 1.433689e-03 0.0135780139 -42.04545      TFAP2E

The original data file is quite large, here under the gene column some of the rows have multiple same gene names separated by ;. How can I show only unique gene names.

No pattern of gene names exists when multiple names are present. In certain cases, the same gene is repeated, while in other cases, distinct genes are present in the same cell. The majority of the time, a single gene exists in a cell.

library(ggplot2)
library(ggrepel)
    v1<-ggplot(data=DMCf1_huMetGNc, aes(x=meth.diff, y=-log10(pvalue) )) + geom_point()
    v1+geom_text_repel(aes(label= gene))

enter image description here

Here, you may see how the FGFR2 gene is repetitive in the plot that I want to remove and the same name from a single row should appear only once in the plot.

$\endgroup$
5
  • 1
    $\begingroup$ What do you want done with lines that include multiple gene names? $\endgroup$
    – gringer
    Commented Dec 19, 2023 at 20:46
  • $\begingroup$ I want to show the unique names only, not the same repetitive names. $\endgroup$
    – Deb
    Commented Dec 20, 2023 at 15:04
  • 2
    $\begingroup$ So if there's A;B;A, you wish to show A;B and if there's A;A, you want just A? $\endgroup$
    – Ram RS
    Commented Dec 20, 2023 at 18:12
  • $\begingroup$ This explanation is not descriptive enough. Do you want lines to be duplicated, one for each gene? Do you want to exclude lines with multiple genes? Or something else? $\endgroup$
    – gringer
    Commented Dec 20, 2023 at 19:14
  • $\begingroup$ Yes, RamRS is true. I want to show the names as @RamRS is suggested. $\endgroup$
    – Deb
    Commented Dec 21, 2023 at 15:19

1 Answer 1

1
$\begingroup$

Based on your comments, you wish to obtain a semi-colon separated list of unique values in the gene column. You can create a new column containing these using:

xyz <- data.frame(chr="chr1", gene = c("RUNX3;RUNX3", "RUNX3;RUNX3", "SFN", "NR0B2", "NR0B2", "TFAP2E", "A;B;A"))

xyz
   chr        gene
1 chr1 RUNX3;RUNX3
2 chr1 RUNX3;RUNX3
3 chr1         SFN
4 chr1       NR0B2
5 chr1       NR0B2
6 chr1      TFAP2E
7 chr1       A;B;A

xyz$gene_uniq <- sapply(xyz$gene, function(x) paste(unique(unlist(strsplit(x, ";"))), collapse=";"))

xyz
   chr        gene gene_uniq
1 chr1 RUNX3;RUNX3     RUNX3
2 chr1 RUNX3;RUNX3     RUNX3
3 chr1         SFN       SFN
4 chr1       NR0B2     NR0B2
5 chr1       NR0B2     NR0B2
6 chr1      TFAP2E    TFAP2E
7 chr1       A;B;A       A;B

Or you can use dplyr. I'm adding a column called entry_num below since my example has non-unique combinations of chr and gene that we need to retain.

library(dplyr)
library(tidyr)

xyz <- data.frame(chr="chr1", gene = c("RUNX3;RUNX3", "RUNX3;RUNX3", "SFN", "NR0B2", "NR0B2", "TFAP2E", "A;B;A"))
xyz %>% mutate(entry_num = 1:nrow(xyz)) %>% separate_rows(gene, sep = ";") %>% unique() %>% group_by(chr, entry_num) %>% summarize(gene = paste(gene, collapse=";")) %>% select(-entry_num) %>% as.data.frame()

   chr   gene
1 chr1  RUNX3
2 chr1  RUNX3
3 chr1    SFN
4 chr1  NR0B2
5 chr1  NR0B2
6 chr1 TFAP2E
7 chr1    A;B
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.