This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rearranging data frame based on column values

Hi!

I have a table with different categories and the respective coverage values:

taxonomy coverage
A 20
ADK 6
ADL 3

Now, I want to separate the taxonomy categories into categories of individual letters. I need to assign the coverage value to the new categories of individual letters. The criteria are the following:

The coverage value for categories with 3 letters will be divided by 3 and 1/3 of the value will be assigned to each individual category.

Here is what the table should look like at the end:

taxonomy coverage
A 23
D 3
K 2
L 1

Thanks a lot!

python biopython

In case you don't realize it, what you are doing is an equivalent of saying Here is what I need, go fetch!. You are laying out your expectations without showing the slightest effort to solve the problem. There may be a good soul on this forum who will still do this for you, but that's not a way to go about it.

Out of curiosity, why biopython in keywords?

R:

> df %>% 
+   mutate(v3=nchar(V1)) %>% 
+   separate_rows (V1,sep ="") %>% 
+   na_if("") %>%
+   na.omit %>% 
+   mutate (counts=V2/v3) %>% 
+   group_by(V1) %>% 
+   mutate(count_sum=sum(counts)) %>% 
+   select(V1,count_sum) %>% 
+   distinct()

# A tibble: 4 × 2
# Groups:   V1 [4]
  V1    count_sum
  <chr>     <dbl>
1 A            23
2 D             3
3 K             2
4 L             1

0 answers

No answers yet.

Log in to answer this question.