Coronavirus Mutation Analysis using Python | Towards Data Science

The novel coronavirus Sars Cov-2 was first identified and it’s genome sequenced from Wuhan, China. The genome of any organism will consist of four nucleotide bases (Adenine -A, Guanine -G, Cytosine -C, Thymine -T) placed in a specific order, in a molecule named DNA (DeoxyriboNucleic Acid). The order in which these four bases are sequenced is of utmost importance. Any deviation to this sequence in a gene of an organism is what is termed as the gene mutation. In the case of the novel coronavirus it has a single stranded RNA. With the help of enzymes DNA molecule can be constructed from RNA. Below is the gene sequence of the Membrane gene of the novel coronavirus Sars Cov-2. As previously said it’s a sequence of A,T,G,C in a specific order. In our coronavirus mutation analysis, we will be comparing two different genomic sequence of the novel coronavirus. The two sequences are downloaded from NCBI gene bank. One of sequence is from USA and the other one is sequenced from China.
Every organism is constantly evolving/undergoing mutations to better adapt to it’s environment. Similarly the novel coronavirus will also be undergoing mutations to better adapt to human. It is very important to understand the pattern in which it mutates. Understanding this pattern has significant impact to vaccine/drug development efforts. For example if the Spike protein is undergoing mutation, then the vaccine/drug developed to target the Spike protein may not be effective in all cases. This would mean that we will have to re-start our search for a new drug/vaccine against covid-19 again.
github.com
Lets start with some background about Corona Virus’s. The novel coronavirus named SARS COV-2 is the reason for the current Covid-19 pandemic. This virus was first identified and sequenced from Wuhan, China in 2019 December. The virus got it’s name due to its similarity with a well known previously identified coronavirus SARS COV (The virus which caused Severe Accute Respiratory Syndrome in 2002–2003). At the time of writing this article, scientists have identified and studied over 500 different coronaviruses. Out of this 500 odd coronaviruses, 7 coronaviruses are known to cause infections in humans. SARS COV-2 is the latest one in the list. SARS COV, MERS COV (Caused Middle East Respiratory Syndrome in 2012), HKU1, NL63, OC43, 229E are the other known coronaviruses that cause infections in humans.
Lets take a closer look at SARS COV-2. SARS COV-2 has an high affinity for ACE2 receptors on the humans cells. They use ACE2 receptors to dock on to the human cells before endocytosis. From the figure, it is quite clear that the virus has the following structural proteins namely Spike protein, Nucleocapsid protein, Membrane protein and Envelope protein. The vaccine/drug development efforts targets specific viral protein structures/enzymes. It is very important that we understand the viral mutations before such a target is decided. If the target protein structure undergoes mutation then the drug/vaccine may not be effective in the future. This is where the mutation analysis plays a critical role in the efforts to create a drug/vaccine. The SARS COV-2 genome consist of 11 genes. Each gene and there expressions (Proteins) are listed below.
gene=ORF1ab. Open Reading Frame 1 which encodes for the proteins ORF1a and ORF1ab. This creates several non structural protein as-well.
gene=S. This gene encodes Spike Protein which docks with the ACE2 receptors of the human cell before endocytosis.This is a trimer protein with S1 and S2 subunits.
gene=ORF3a. Open Reading Frame 3 which encodes for ORF3a protein.
gene=E. This gene encodes for the Envelope protein.
gene=M. This gene encodes for the Membrane protein.
gene=ORF6. Open Reading Frame 6 which encodes for ORF6 protein.
gene=ORF7a. Open Reading Frame 7a which encodes for ORF7a protein.
gene=ORF7b. Open Reading Frame 7b which encodes for ORF7b protein.
gene=ORF8. Open Reading Frame 8 which encodes for ORF8 protein.
gene=N. This gene encodes for the Nucleocapsid phosphoprotein.
gene=ORF10. Open Reading Frame 10 which encodes for ORF10 protein.
Link to Github for the complete code
Before we go to the Main.py, lets see the dna class, python dictionary numpy_image_dict and helper functions like read_dna_seq and gene_mod.
First i have created a new class dna with the __init__ method and the important method numpfy. The __init__ method will check if the base sequence provided is valid. If the base sequence comes with an invalid character, an error will be thrown. The method numpfy converts the base nucleotide sequence into a numpy array by converting A -0, T -255, G -200, C -100 and the dummy base N -75.
The NCBI website has a collection of over 4500 different SARS COV-2 viral genome sequences. Anybody can go to the NCBI website and download the genome sequence’s for analysis. Alternatively they also provide API’s to programmatically access the gene bank. In this example i have already downloaded 2 different nucleotides. First one, which is a reference sequence from China released in Jan 2020. The other nucleotide sequence is from USA released in April 2020. By analyzing these 2 nucleotides we will get to see the mutations to each gene over 3–4 months and across geographies.
Read the genome sequences downloaded from NCBI. The nucleotide base sequence will have Adenine, Guanine, Cytosine and Thymine. Both the downloaded files will have the base sequence for each gene. The following method will read the file and figure out the meta data and the base sequence for each gene. At the end of this step we will have the python dictionary named genome. The dictionary will have gene names as keys and the value pair will be a list of base sequence for that gene.
We have created a dictionary with all of the information pre-populated for creating a numpy array for each gene. Here gene name is the key and the value pair is a list. The first element is a tuple, this tuple has the predefined array shape for that gene. The second element is the number of dummy element ‘N’ to be added to the sequence. For example, for the gene ORF1ab, i have calculated the array dimensions to be 115 * 115. Which means there has to be 13225 base sequence of A,T,C and G. The sequences which i have considered have only 13218 base sequences for that gene. To make up for the this shortage we are adding 7 dummy character ’N’ to the gene sequence from both the files. The method gene_mod will read the dictionary numpy_image_dict for each of the genes and add the number of ’N’ if specified in the dictionary.
Having gone thru all of the required class, dictionary and the helper functions, now lets go thru the main module and start using all of the previously mentioned methods. We need to import numpy and matplotlib for this to work. Let’s also import the custom built dna class, numpy_image_dictionary and the helper function (read_dna_seq, gene_mod) mentioned above. After importing all of the required modules lets read both the files downloaded from NCBI and make necessary modifications on each gene to convert them into numpy arrays.
Create 3 matplotlib subplots(gene from file-1, gene from file-2, resultant mutation plot) for each of the 11 genes.
f,ax = plt.subplots(nrows=11,ncols=3,figsize=(25,30))
Create a list of all the gene_name from the dictionary returned by the read_dna_seq method.
gene_name = list(numpy_image_dict.keys())
For every gene in the gene_name list, create a dna object and call the method numpfy to convert it into a numpy array. Which means for every gene from a sequence, there will be a dna object which will have a numpy array attribute. This is true for all of the genes from the second list too. Each of this numpy array will be converted into subplot’s with pcolor method of matplotlib.pyplot.
# Create the dna object for the USA sequencegene_us = dna(dict_seq_1['gene=ORF10')# Call the numpfy methodnumpfy_usa = gene_us.numpfy()# After numpfy do a reshape with numpy_image_dict tuplenumpfy_usa = numpfy_usa.reshape(numpy_image_dict['gene=ORF10'][0])# Create the matplotlib subplotax[row][col].pcolor(numpfy_usa)# Create the dna object for the CHINA sequencegene_ch = dna(dict_seq_2['gene=ORF10')# Call the numpfy methodnumpfy_china = gene_ch.numpfy()# After numpfy do a reshape with numpy_image_dict tuplenumpfy_china = numpfy_china.reshape(numpy_image_dict['gene=ORF10'][0])# Create the matplotlib subplotax[row][col].pcolor(numpfy_china)
Finally we find the mutation for a gene. This is done by simply subtracting the numpy arrays of the same gene from both the sequences. For example there will be a numpy array for ORF10 gene from the USA sequence and there will be a numpy array for ORF10 gene from the CHINA sequence. To find the mutation, simply subtract the numpy arrays. After this subtraction the resultant numpy array will be checked to see if there exist any non-zero values. If there exists a non-zero value that’s the mutation that we were looking for. We will capture this mutation in a python dictionary for further analysis. The mutated gene and the specific location will be printed out in the python console.
Python Console prints out the mutation information out.
The matplotlib subplot will be created for all of the eleven genes with there mutation results. Each row shows one gene from first sequence followed by the same gene from the second gene followed by the mutation on that gene. If there is a bright spot in the 3rd subplot on each row, that means there is at-least one mutation on that gene. If there are no mutations then the 3rd subplot will be dark with no bright spots.
By following this approach the entire genome and its mutation from 2 different sequence can be visualized within a single image. This is a significant difference between other mutation analysis tools out there in the market. This is just a start and we have the data now as numpy arrays. This means we can apply more transformations on these numpy arrays either for a handful or for all the sequence from a specific country or from a region. This will help us come up with more insights and predictions than what other tools out there can offer.
This project was written rite from scratch. I have built all of the code for this project and did not use any other library other than numpy and matplotlib. If you have reached this far, i thank you for reading this article.
Special Thanks to Markus Spiske. The first image that i have used at the start of this post is created by him.
Note from the editors: towardsdatascience.com is a Medium publication primarily based on the study of data science and machine learning. We aren’t health professionals or epidemiologists. To learn more about the coronavirus pandemic, you can click here.
Some rights reserved