I have csv file genes_averages.csv in the following format: Gene name;starting bp;ending…
- User
I have csv file genes_averages.csv in the following format: Gene name;starting bp;ending bp;average INTERGENIC00001;1;189;0.0 thrL gene;190;255;0.0 INTERGENIC00002;256;336;1.9876543209876543 thrA gene;337;2799;34.27771010962241 INTERGENIC00003;2800;2800;35.0 thrB gene;2801;3733;56.89067524115756
Write a python script to plot it. Plot averages of genes in red, averages of intergenic regions in blue.
Assistant
Here's a Python script using pandas and matplotlib to plot the averages of genes and intergenic regions.
import pandas as pd import matplotlib.pyplot as plt # Load the csv file def load_data(file_name): try: data = pd.read_csv(file_name, sep=';') return data except Exception as e: print(f"Failed to load data: {e}") return None # Plot the data def plot_data(data): # Separate genes and intergenic regions genes = data[data['Gene name'].str.contains('gene')] intergenic = data[data['Gene name'].str.contains('INTERGENIC')] # Create the plot plt.figure(figsize=(10, 6)) plt.scatter(genes['starting bp'], genes['average'], color='red', label='Genes') plt.scatter(intergenic['starting bp'], intergenic['average'], color='blue', label='Intergenic regions') # Set labels and title plt.xlabel('Starting bp') plt.ylabel('Average') plt.title('Averages of Genes and Intergenic Regions') plt.legend() # Show the plot plt.show() # Main function def main(): file_name = 'genes_averages.csv' data = load_data(file_name) if data is not None: plot_data(data) if __name__ == "__main__": main()This script first loads the csv file into a pandas DataFrame. Then it separates the genes and intergenic regions into two separate DataFrames. Finally, it creates a scatter plot with the starting bp on the x-axis and the average on the y-axis, using red for genes and blue for intergenic regions. The plot includes labels, a title, and a legend.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.