Counting all samples numbers for every gene
Is there a method to automate the counting of all the numbers for every gene -including all different variants. Thats for large number of genes over 10000 genes.
| Variant | numbers_cases | numbers_control | Gene |
|---|---|---|---|
| 1 | 20 | 55 | ABC |
| 2 | 48 | 149 | ABC |
| 3 | 20 | 456 | ABC |
| 4 | 73 | 55 | TET |
| 5 | 48 | 77 | TET |
| 6 | 189 | 454 | TET |
Out put I want
| Gene | numbers_cases | numbers_control |
| ------- | --------- | --------|
| ABC |88 |660 |
| TET|310 |586 |
• 1,662 views
•
link
1 answer
Here is a solution in R:
First load the data.
counting = read.csv('counting.csv')
Then create a list of genes to group by.
gene.list = list(counting$Gene)
Then combine your rows.
new.counting = aggregate(x = counting[c('numbers_cases', 'numbers_control')], by = gene.list, FUN = sum)
new.counting
• 0 views
•
link
Log in to answer this question.
Tidyverse solution.
with datamash
with csvtk
with R data table:
with base R:
R, Datamash and csvtk don't come by default with OS. You may have to install via apt, yum, brew, conda etc.