<jupyter_start><jupyter_text>South African Mutation (501Y.V2)<jupyter_code>### South African Mutation, add a column of binary values showing whether there is a mutation there
my_df['South_African_mutation'] = pd.Series(np.zeros(len(my_df)))
my_df
south_african_indeces = my_df[np.logical_or(my_df.protein=='S1', my_df.protein=='S2')].index
south_african_indeces
def south_africa(mutation_point):
    '''
    Inputs:
        - mutation point: the number of the nucleotide in the S protein that is mutated
    Outputs:
        nothing
        But, it changes the my_df dataframe
    '''
    for my_index in south_african_indeces:
        temp_start = my_df.loc[my_index, 'start_pos']
        temp_len = my_df.loc[my_index, 'epi_len']
        if temp_start <= mutation_point and temp_start+temp_len > mutation_point:
            my_df.loc[my_index, 'South_African_mutation'] = 1
#             print(my_df.loc[my_index,:])
        
### From this paper: https://www.medrxiv.org/content/10.1101/2020.12.21.20248640v1.full.pdf
### Last figure graph B, remember everything here is 0-indexed, so 701 becomes 700
### A701V 
south_africa(700)
### D215G
south_africa(214)
### D80A
south_africa(79)
### E484K
south_africa(483)
### K417N
south_africa(416)
### L18F
south_africa(17)
### N501Y
south_africa(500)
### R246I
south_africa(245)

my_df
my_df.South_African_mutation.value_counts()
### Uncomment to save the file!!!
# my_df.to_csv('data/processed/AllEpitopeFeatures_with_South_African_mutation_larger.csv', index=False)<jupyter_output><empty_output><jupyter_text>UK mutation (B.1.1.7)<jupyter_code>my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_mutation_larger.csv')
my_df;
my_df['UK_mutation'] = pd.Series(np.zeros(len(my_df)))
# my_df.UK_mutation.value_counts()
my_df.protein.unique();
my_df[my_df.protein=='ORF1a'];
my_df[np.logical_and(my_df.protein=='ORF1a', my_df.start_pos==1000)];
def uk_mutation(mutation_point, my_protein):
    '''
    Inputs:
        - mutation point: the number of the nucleotide in the S protein that is mutated
        - protein: the protein, ex. S (S1 and S2), ORF1a (there is no need to say ORF1ab as 
        there are no mutations past the cutoff between ORF1a and ORF1b) etc.
    Outputs:
        nothing
        But, it changes the my_df dataframe
    '''
    if my_protein == 'S':
        indeces = my_df[np.logical_or(my_df.protein=='S1', my_df.protein=='S2')].index
    else:
        indeces = my_df[my_df.protein==my_protein].index
        
    for my_index in indeces:
        temp_start = my_df.loc[my_index, 'start_pos']
        temp_len = my_df.loc[my_index, 'epi_len']
        if temp_start <= mutation_point and temp_start+temp_len > mutation_point:
            my_df.loc[my_index, 'UK_mutation'] = 1
#             print(my_index)
#             print(my_df.loc[my_index,:])
### From this paper: https://virological.org/t/preliminary-genomic-characterisation-of-an-emergent-sars-cov-2-lineage-in-the-uk-defined-by-a-novel-set-of-spike-mutations/563
### 0-indexed!!!, also instead of ORF1ab I use ORF1a, because all the mutations are in the beginning of 
### the ORF1ab, so in ORF1a

### ORF1ab -> ORF1a
### T1001I
uk_mutation(1000, 'ORF1a')
### A1708D
uk_mutation(1707, 'ORF1a')
### I2230T
uk_mutation(2229, 'ORF1a')
### SGF 3675-3677 deletion
uk_mutation(3674, 'ORF1a')
uk_mutation(3675, 'ORF1a')
uk_mutation(3676, 'ORF1a')

### S (Spike protein)
### HV 69-70 deletion
uk_mutation(68, 'S')
uk_mutation(69, 'S')
### Y144 deletion
uk_mutation(143, 'S')
### N501Y
uk_mutation(500, 'S')
### A570D
uk_mutation(569, 'S')
### P681H
uk_mutation(680, 'S')
### T716I
uk_mutation(715, 'S')
### S982A
uk_mutation(981, 'S')
### D1118H
uk_mutation(1117, 'S')

### ORF8
### Q27stop -> Basically get rid of all of ORF8 !!!!!

# ### R52I
# uk_mutation(51, 'ORF8')
# ### Y73C
# uk_mutation(72, 'ORF8')

### N
### D3L
uk_mutation(2, 'N')
### S235F
uk_mutation(234, 'N')
my_df.UK_mutation.value_counts()
### Take care of all of ORF8
indeces_orf8 = my_df[my_df.protein=='ORF8'].index
indeces_orf8
for my_index in indeces_orf8:
    my_df.loc[my_index, 'UK_mutation'] = 1
my_df.UK_mutation.value_counts()
### Uncomment to save the file
# my_df.to_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_mutation_larger.csv', index=False)<jupyter_output><empty_output><jupyter_text>Indian Mutation (B.1.617)<jupyter_code>### Use paper: https://www.biorxiv.org/content/10.1101/2021.04.23.441101v1.full
my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_mutation_larger.csv')
my_df
my_df['Indian_mutation'] = pd.Series(np.zeros(len(my_df)))
def indian_mutation(mutation_point, my_protein):
    '''
    Inputs:
        - mutation point: the number of the nucleotide in the S protein that is mutated
        - protein: the protein, ex. S (S1 and S2), ORF1a, ORF1b etc.
    Outputs:
        nothing
        But, it changes the my_df dataframe
    '''
#     if my_protein == 'S':
#         indeces = my_df[np.logical_or(my_df.protein=='S1', my_df.protein=='S2')].index
#     elif my_protein == '':
#         indeces = my_df[my_df.protein==my_protein].index

    indeces = my_df[my_df.protein==my_protein].index
    
    anything = False
        
    for my_index in indeces:
        temp_start = my_df.loc[my_index, 'start_pos']
        temp_len = my_df.loc[my_index, 'epi_len']
        if temp_start <= mutation_point and temp_start+temp_len > mutation_point:
            my_df.loc[my_index, 'Indian_mutation'] = 1
            anything = True
            
    if not anything:
        print('Problem with ', mutation_point, ' in protein ', my_protein)
#             print(my_index)
#             print(my_df.loc[my_index,:])
### Mutation points for the Indian Mutation (B.1.617)
### From the paper: https://www.biorxiv.org/content/10.1101/2021.04.23.441101v1.full
### For all the proteins the mutation point is -1 from what is written, because of zero indexing
### Exception: ORF1b, where the mutation point is -3 - 4399, because the numbering continues over from ORF1a
### Note that we need not worry in the same way about S2, as the numbering simply continues on there.

### ORF1a
### T 1567 I 
indian_mutation(1567 - 1, 'ORF1a')
### T 3646 A
indian_mutation(3646 - 1, 'ORF1a')

### ORF1b 
### P 4715 L
indian_mutation(4715 - 3 - 4399, 'ORF1b')
### G 5530 I
indian_mutation(5530 - 3 - 4399, 'ORF1b')
### M 5753 I
indian_mutation(5753 - 3 - 4399, 'ORF1b')
### K 6711 R
indian_mutation(6711 - 3 - 4399, 'ORF1b')
### S 6713 A
indian_mutation(6713 - 3 - 4399, 'ORF1b')

### S protein
### S1 domain
### T 95 I
indian_mutation(95 - 1, 'S1')
### G 142 D
indian_mutation(142 - 1, 'S1')
### E 154 K
indian_mutation(154 - 1, 'S1')
### L 452 R
indian_mutation(452 - 1, 'S1')
### E 484 Q
indian_mutation(484 - 1, 'S1')
### D 614 G
indian_mutation(614 - 1, 'S1')
### P 681 R
indian_mutation(681 - 1, 'S1')
### S2 domain
### Q 1071 H
indian_mutation(1071 - 1, 'S2')

### ORF3a
### S 26 L
indian_mutation(26 - 1, 'ORF3a')

### M
### I 82 S
indian_mutation(82 - 1, 'M')

### ORF6
### D 61 (the last amino acid)
indian_mutation(61 - 1, 'ORF6')
### 62 (anything after that)

### ORF7a
### N 43 Y
indian_mutation(43 - 1, 'ORF7a')
### V 82 A
indian_mutation(82 - 1, 'ORF7a')

### N
### R 203 M
indian_mutation(203 - 1, 'N')
### D 377 Y
indian_mutation(377 - 1, 'N')
my_df.Indian_mutation.value_counts()
### Code to save the data
# my_df.to_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_and_Indian_mutation_larger.csv', index=False)
my_df[my_df.protein == 'ORF1a'].start_pos.unique()
my_df[np.logical_and(my_df.protein == 'ORF1a', my_df.start_pos == 4392)]
my_df[my_df.protein == 'ORF1b'].start_pos.unique()
my_df[my_df.protein == 'S1'].start_pos.unique()[-1]
my_df[my_df.protein == 'S2'].start_pos.unique()[0]
### ORF1b is after ORF1a, but starts with 0
### S2 is after S1, but starts at 685, while S1 ends with 684
# my_df[np.logical_and(my_df.protein == 'ORF1b', my_df.start_pos == 4712 - 4399)]
# my_df[np.logical_and(my_df.protein == 'ORF1b', my_df.start_pos == 5529 - 4392)]
# my_df[np.logical_and(my_df.protein == 'N', my_df.start_pos == 376)]
# my_df.protein.unique()
# my_df[my_df.protein == 'ORF6']
# my_df[np.logical_and(my_df.protein == 'S1', my_df.start_pos == 245)]
# my_df[np.logical_and(my_df.protein == 'N', my_df.start_pos == 2)]
my_df[np.logical_and(my_df.protein == 'ORF1b', my_df.start_pos == 6713 - 3 - 4399)]<jupyter_output><empty_output><jupyter_text>Brazilian Mutation (P.1)<jupyter_code>### Use the following paper: https://virological.org/t/genomic-characterisation-of-an-emergent-sars-cov-2-lineage-in-manaus-preliminary-findings/586
my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_and_Indian_mutation_larger.csv')
my_df.Indian_mutation.value_counts()
my_df['Brazilian_mutation'] = pd.Series(np.zeros(len(my_df)))
def brazilian_mutation(mutation_point, my_protein):
    ### exact same function as the indian_mutation !!!
    '''
    Inputs:
        - mutation point: the number of the nucleotide in the S protein that is mutated
        - protein: the protein, ex. S (S1 and S2), ORF1a, ORF1b etc.
    Outputs:
        nothing
        But, it changes the my_df dataframe
    '''
#     if my_protein == 'S':
#         indeces = my_df[np.logical_or(my_df.protein=='S1', my_df.protein=='S2')].index
#     elif my_protein == '':
#         indeces = my_df[my_df.protein==my_protein].index

    indeces = my_df[my_df.protein==my_protein].index
    
    anything = False
        
    for my_index in indeces:
        temp_start = my_df.loc[my_index, 'start_pos']
        temp_len = my_df.loc[my_index, 'epi_len']
        if temp_start <= mutation_point and temp_start+temp_len > mutation_point:
            my_df.loc[my_index, 'Brazilian_mutation'] = 1
            anything = True
            
    if not anything:
        print('Problem with ', mutation_point, ' in protein ', my_protein)
#             print(my_index)
#             print(my_df.loc[my_index,:])
### Mutations from the paper
### Paper: https://virological.org/t/genomic-characterisation-of-an-emergent-sars-cov-2-lineage-in-manaus-preliminary-findings/586

### For all the proteins the mutation point is -1 from what is written, because of zero indexing
### Exception: ORF1b, where the mutation point is -3 - 4399, because the numbering continues over from ORF1a
### Note that we need not worry in the same way about S2, as the numbering simply continues on there.



### ORF1ab
### ORF1a
### S 1188 L
brazilian_mutation(1188 - 1, 'ORF1a')
### K 1795 Q
brazilian_mutation(1795 - 1, 'ORF1a')
### del 3675
brazilian_mutation(3675 - 1, 'ORF1a')
### del 3676
brazilian_mutation(3676 - 1, 'ORF1a')
### del 3677
brazilian_mutation(3677 - 1, 'ORF1a')
### ORF1b
### E 5665 D
brazilian_mutation(5665 - 3 - 4399, 'ORF1b')

### S (S1 and S2)
### S1
### L 18 F
brazilian_mutation(18 - 1, 'S1')
### T 20 N
brazilian_mutation(20 - 1, 'S1')
### P 26 S
brazilian_mutation(26 - 1, 'S1')
### D 138 Y
brazilian_mutation(138 - 1, 'S1')
### R 190 S
brazilian_mutation(190 - 1, 'S1')
### K 417 T (important!!!)
brazilian_mutation(417 - 1, 'S1')
### E 484 K (important!!!)
brazilian_mutation(484 - 1, 'S1')
### N 501 Y (important!!!)
brazilian_mutation(501 - 1, 'S1')
### H 655 Y
brazilian_mutation(655 - 1, 'S1')
### S2
### T 1027 I
brazilian_mutation(1027 - 1, 'S2')

### ORF8
### E 92 K
brazilian_mutation(92 - 1, 'ORF8')
### insertion in DNA 28269 - 28273 ???

### N
### P 80 R
brazilian_mutation(80 - 1, 'N')
### Checking that things work
# my_df[np.logical_and(my_df.protein == 'ORF1b', my_df.start_pos == 5665 - 3 - 4399)]
# my_df[np.logical_and(my_df.protein == 'N', my_df.start_pos == 79)]
my_df.Brazilian_mutation.value_counts()
my_df[np.logical_and(my_df.protein == 'N', my_df.start_pos == 80 - 1)]
### Code to save the data
### my_df.to_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_and_Indian_and_Brazilian_mutation_larger.csv', index=False)<jupyter_output><empty_output><jupyter_text>Play around with the total data<jupyter_code>my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_and_Indian_and_Brazilian_mutation_larger.csv')
my_df.Brazilian_mutation.value_counts()<jupyter_output><empty_output><jupyter_text>Set the mutation rate equal to 1 if the peptide is hit by (South_African, UK, Indian, Brazilian) mutation<jupyter_code>my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_and_Indian_and_Brazilian_mutation_larger.csv')
my_df
for ind in my_df.index:
    if ind%10000==0:
        print(ind)
    if my_df.loc[ind,'UK_mutation'] == 1 or my_df.loc[ind,'South_African_mutation'] == 1 or my_df.loc[ind,'Indian_mutation'] == 1 or my_df.loc[ind,'Brazilian_mutation'] == 1:
        my_df.loc[ind,'perc_mutated'] = 1.0
new_df = my_df.drop(labels = ['South_African_mutation','UK_mutation', 'Indian_mutation', 'Brazilian_mutation'], axis='columns')
new_df
### Code to save the new data!!!
### new_df.to_csv('data/processed/AllEpitopeFeatures_accounting_for_all_major_mutations_mutrate_set_to_1.csv')
new_df[np.logical_and(new_df.protein == 'S1', new_df.start_pos == 451)]<jupyter_output><empty_output><jupyter_text>New code for setting the mutation rate for any peptide that has the UK or South African Mutation equal to 1 (can run this separately from the above)<jupyter_code>my_df = pd.read_csv('data/processed/AllEpitopeFeatures_with_South_African_and_UK_mutation_larger.csv')
my_df
for ind in my_df.index:
    if ind%10000==0:
        print(ind)
    if my_df.loc[ind,'UK_mutation'] == 1 or my_df.loc[ind,'South_African_mutation'] == 1:
        my_df.loc[ind,'perc_mutated'] = 1.0
my_df
my_df[my_df.UK_mutation == 1]
my_df[my_df.South_African_mutation == 1]
new_df = my_df.drop(labels = ['South_African_mutation','UK_mutation'], axis='columns')
new_df
new_df.to_csv('data/processed/AllEpitopeFeatures_accounting_for_UK_and_SA_mutations.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14328765157494439, 'fraction_numerical': 0.05826217980914113, 'mean_word_length': 4.404420317952695, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 6, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '572258', 'license': 'MIT', 'n_tokens_mistral': 6161, 'n_tokens_neox': 5395, 'n_words': 1151, 'path': 'covid_mutation_analysis_and_nextstrain_build/ExcludeImportantMutations_Alex.ipynb', 'repo_name': 'gifford-lab/optivax', 'size': '13937'}