I have a dataset for mutation data and I want to calculate mutation frequencies across all genes
df (This is only the small subset of data)
Gene name Sample id MUTATION_ID Mutation Description
ARID1B 2719660 171258500 Substitution - Missense
ARID1B 2719659
ARID1B 2719661 171258501 Substitution - Missense
ARID1B 2719662
ARID1B 2719663 171258501 Substitution - Nonsense
CD58 2878555 110346783 Substitution - Nonsense
CD58 2877956
CD58 2878557
CD58 2877958 110346784 Substitution - Nonsense
CD58 2878559 110346785 Substitution - Nonsense
CD58 2877960
MRE11 2861617 123320443 Substitution - coding silent
MRE12 2861617 123320444 Substitution - coding
MRE13 2861617
MRE14 2861617 123320445 Substitution - coding silent
MRE15 2861617
MRE16 2861617 123320446 Substitution - coding
The formula for calculating the mutation is
Positives ÷ (Positives + Negatives) x 100
where,
Positives
= No of samples where MUTATION_ID
is present
Negative
= No of samples MUTATION_ID
for the sample
I want to calculate mutation frequency for every gene in the column_1:Gene name
with python script
I tried the following code
df = df.groupby("Gene name").count()
Positives = df["MUTATION_ID"]
Negatives = df["Sample id"] - df["MUTATION_ID"]
df['Mutation_Frequency'] = Positives / (Positives + Negatives) * 100
-
? Is that a separate field with no header? $\endgroup$