Skip to content

Commit

Permalink
Add workspace for testing and add PDO calibrations for single Z spots…
Browse files Browse the repository at this point in the history
… and spots counted from Zs 5-9
  • Loading branch information
alexpopinga committed Nov 12, 2024
1 parent 6890316 commit 017057b
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 1 deletion.
26 changes: 26 additions & 0 deletions WorkSpace/AlexP/SpotCountingByCellAndByZ/merge_dfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pandas as pd

# Load the CSV files
file1_path = 'dataframe_A549_DUSP1_100nM_10min_062723_spot_counts.csv'
file2_path = 'dataframe_A549_DUSP1_100nM_10min_062723_spot_counts_z_5_9.csv'
file3_path = 'dataframe_A549_DUSP1_100nM_10min_062723_spot_counts_z_7.csv'

df1 = pd.read_csv(file1_path)
df2 = pd.read_csv(file2_path)
df3 = pd.read_csv(file3_path)

# Rename the "Spot_Count" column in the second dataframe to "Z_5_9"
df2.rename(columns={'Spot_Count': 'Z_5_9'}, inplace=True)

# Rename the "Spot_Count" column in the third dataframe to "Z_7"
df3.rename(columns={'Spot_Count': 'Z_7'}, inplace=True)

# Merge the three dataframes on the "Image_Cell_ID" column
df4 = pd.merge(df1, df2, on='Image_Cell_ID', how='inner')
merged_df = pd.merge(df4, df3, on='Image_Cell_ID', how='inner')

# Save the merged dataframe to a new CSV file
merged_file_path = 'merged_dataframe_A549_DUSP1_100nM_10min_062723.csv'
merged_df.to_csv(merged_file_path, index=False)

merged_file_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Image_Cell_ID,Spot_Count,Z_5_9,Z_7
"(0, 0)",122,79,25
"(0, 1)",287,193,62
"(0, 2)",215,111,36
"(0, 3)",306,161,52
"(0, 4)",134,101,29
"(0, 5)",124,97,28
"(1, 6)",273,154,18
"(1, 7)",167,94,11
"(1, 8)",45,20,1
"(2, 9)",82,37,8
"(2, 10)",90,66,24
"(2, 11)",204,129,55
"(2, 12)",171,111,34
"(2, 13)",41,28,5
"(2, 14)",111,56,11
"(3, 15)",381,281,85
"(3, 16)",261,210,47
"(3, 17)",195,126,31
"(3, 18)",100,68,18
"(4, 19)",322,189,67
"(4, 20)",327,256,64
"(4, 21)",44,35,6
"(4, 22)",90,59,14
"(5, 23)",47,36,9
"(5, 24)",237,174,37
"(5, 25)",147,107,29
"(5, 26)",93,64,16
"(5, 27)",55,45,9
"(5, 28)",151,133,26
"(5, 29)",75,59,11
"(6, 30)",237,175,51
"(6, 31)",276,222,60
"(6, 32)",220,143,18
"(6, 33)",71,38,6
"(7, 34)",195,150,29
"(7, 35)",240,141,40
"(7, 36)",164,103,25
"(7, 37)",168,114,22
"(7, 38)",72,46,10
"(7, 39)",52,45,15
"(7, 40)",47,41,12
"(8, 41)",123,84,18
"(8, 42)",64,43,11
"(8, 43)",104,83,30
"(8, 44)",62,50,11
"(8, 45)",53,38,11
"(9, 46)",265,213,75
"(9, 47)",164,100,31
"(9, 48)",162,126,32
"(9, 49)",227,160,55
"(9, 50)",65,38,10
"(9, 51)",106,77,25
"(9, 52)",66,47,15
"(9, 53)",32,19,4
"(9, 54)",26,20,6
"(10, 55)",104,75,13
"(10, 56)",127,86,15
"(10, 57)",40,30,10
"(11, 58)",59,45,5
"(11, 59)",149,97,21
"(11, 60)",183,114,19
"(11, 61)",142,95,18
"(11, 62)",70,53,10
"(11, 63)",77,64,11
"(11, 64)",9,6,2
"(12, 65)",272,178,24
"(12, 66)",350,274,58
"(12, 67)",171,108,14
"(12, 68)",274,102,14
"(12, 69)",43,23,4
"(12, 70)",71,56,7
"(13, 71)",81,51,14
"(13, 72)",191,146,21
"(13, 73)",88,72,13
"(14, 74)",141,104,17
"(14, 75)",444,393,80
"(14, 76)",93,66,20
"(15, 77)",60,30,3
"(15, 78)",50,24,1
"(15, 79)",62,36,1
"(15, 81)",62,35,1
"(16, 83)",155,62,1
"(18, 87)",135,124,31
"(18, 88)",45,43,5
"(18, 89)",59,51,12
"(18, 90)",39,29,6
"(19, 91)",93,63,22
"(19, 92)",149,123,46
"(19, 93)",62,42,15
"(19, 94)",51,30,13
"(19, 95)",11,8,3
"(20, 97)",249,183,57
"(20, 98)",134,115,48
"(20, 99)",65,50,21
"(20, 100)",36,26,3
"(22, 102)",91,42,2
"(22, 103)",115,62,11
"(22, 104)",185,109,21
"(22, 105)",34,19,3
"(24, 108)",77,50,11
"(24, 109)",60,39,5
"(25, 110)",77,38,7
"(25, 111)",102,72,7
"(25, 112)",62,42,15
"(25, 113)",23,15,5
"(25, 114)",15,11,2
"(25, 115)",12,8,2
"(26, 116)",97,54,9
"(26, 117)",73,43,1
"(26, 118)",73,37,9
"(26, 119)",25,18,1
"(27, 121)",81,48,13
"(27, 122)",10,4,2
"(27, 123)",66,49,10
"(27, 124)",24,13,3
"(27, 125)",14,13,3
"(28, 126)",17,11,2
"(28, 127)",21,9,2
"(28, 128)",27,17,6
"(29, 130)",38,28,5
"(29, 131)",55,29,5
"(29, 132)",47,30,5
"(29, 134)",54,29,5
"(29, 135)",52,32,6
51 changes: 51 additions & 0 deletions WorkSpace/AlexP/SpotCountingByCellAndByZ/spot_counting_Zs5thru9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pandas as pd

# List of file names
files = [
'dataframe_A549_DUSP1_100nM_10min_062723.csv',
'dataframe_A549_DUSP1_100nM_20min_062723.csv',
'dataframe_A549_DUSP1_100nM_30min_062723.csv',
'dataframe_A549_DUSP1_100nM_40min_062723.csv'
]

# Initialize a dictionary to store the total "spot_count" for each file
spot_count_per_file = {}

# Loop through each file
for file in files:
# Load the CSV file
df = pd.read_csv(file)

# Filter the dataframe to include only rows with "z" values between 5 and 9
filtered_df = df[(df['z'] >= 5) & (df['z'] <= 9)]

# Initialize a dictionary to store the spot count for each "cell_id" in the file
file_spot_counts = {}

# Loop through each "image_id"
for image_id in filtered_df['image_id'].unique():
image_df = filtered_df[filtered_df['image_id'] == image_id]

# Loop through each "cell_id" in the current "image_id"
for cell_id in image_df['cell_id'].unique():
cell_df = image_df[image_df['cell_id'] == cell_id]

# Count the number of unique "spot_id" values per "z" value for this cell_id
spot_count = cell_df.groupby('z')['spot_id'].nunique().sum()

# Save the total "spot_count" for this "cell_id"
file_spot_counts[(image_id, cell_id)] = spot_count

# Store the result for the current file
spot_count_per_file[file] = file_spot_counts

# Save the spot counts for each file into separate CSVs
for file, spot_counts in spot_count_per_file.items():
# Convert the dictionary to a DataFrame
spot_counts_df = pd.DataFrame(list(spot_counts.items()), columns=['Image_Cell_ID', 'Spot_Count'])

# Save the DataFrame to a new CSV file
output_filename = file.replace('.csv', '_spot_counts_z_5_9.csv')
spot_counts_df.to_csv(output_filename, index=False)

print("Spot count files for z=5-9 saved successfully.")
51 changes: 51 additions & 0 deletions WorkSpace/AlexP/SpotCountingByCellAndByZ/spot_counting_singleZ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pandas as pd

# List of file names
files = [
'dataframe_A549_DUSP1_100nM_10min_062723.csv',
'dataframe_A549_DUSP1_100nM_20min_062723.csv',
'dataframe_A549_DUSP1_100nM_30min_062723.csv',
'dataframe_A549_DUSP1_100nM_40min_062723.csv'
]

# Initialize a dictionary to store the total "spot_count" for each file
spot_count_per_file = {}

# Loop through each file
for file in files:
# Load the CSV file
df = pd.read_csv(file)

# Filter the dataframe to include only rows with "z" values = 7
filtered_df = df[(df['z'] == 7)]

# Initialize a dictionary to store the spot count for each "cell_id" in the file
file_spot_counts = {}

# Loop through each "image_id"
for image_id in filtered_df['image_id'].unique():
image_df = filtered_df[filtered_df['image_id'] == image_id]

# Loop through each "cell_id" in the current "image_id"
for cell_id in image_df['cell_id'].unique():
cell_df = image_df[image_df['cell_id'] == cell_id]

# Count the number of unique "spot_id" values per "z" value for this cell_id
spot_count = cell_df.groupby('z')['spot_id'].nunique().sum()

# Save the total "spot_count" for this "cell_id"
file_spot_counts[(image_id, cell_id)] = spot_count

# Store the result for the current file
spot_count_per_file[file] = file_spot_counts

# Save the spot counts for each file into separate CSVs
for file, spot_counts in spot_count_per_file.items():
# Convert the dictionary to a DataFrame
spot_counts_df = pd.DataFrame(list(spot_counts.items()), columns=['Image_Cell_ID', 'Spot_Count'])

# Save the DataFrame to a new CSV file
output_filename = file.replace('.csv', '_spot_counts_z_7.csv')
spot_counts_df.to_csv(output_filename, index=False)

print("Spot count files for z=7 saved successfully.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Import necessary libraries
import pandas as pd
import matplotlib.pyplot as plt

# File paths
file_paths = [
'dataframe_A549_DUSP1_100nM_10min_062723.csv',
'dataframe_A549_DUSP1_100nM_20min_062723.csv',
'dataframe_A549_DUSP1_100nM_30min_062723.csv',
'dataframe_A549_DUSP1_100nM_40min_062723.csv',
]

# Corresponding time points
time_points = ['10min', '20min', '30min', '40min']

# Initialize dictionaries to store spot counts
total_spot_counts_by_time = {}
spot_counts_z_0_3_by_time = {}
spot_counts_z_4_7_by_time = {}
spot_counts_z_8_11_by_time = {}
spot_counts_z_12_15_by_time = {}
spot_counts_z_16_19_by_time = {}
spot_counts_z_20_23_by_time = {}
spot_counts_z_24_27_by_time = {}

# Loop through each file and calculate the spot counts
for file, time_point in zip(file_paths, time_points):
df = pd.read_csv(file)

# Count unique spot_id values per image_id and cell_id for all z-values
total_spot_count = df.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Filter for z-slices
filtered_df_z_0_3 = df[(df['z'] >= 0) & (df['z'] <= 3)]
filtered_df_z_4_7 = df[(df['z'] >= 4) & (df['z'] <= 7)]
filtered_df_z_8_11 = df[(df['z'] >= 8) & (df['z'] <= 11)]
filtered_df_z_12_15 = df[(df['z'] >= 12) & (df['z'] <= 15)]
filtered_df_z_16_19 = df[(df['z'] >= 16) & (df['z'] <= 19)]
filtered_df_z_20_23 = df[(df['z'] >= 20) & (df['z'] <= 23)]
filtered_df_z_24_27 = df[(df['z'] >= 24) & (df['z'] <= 27)]

# Count unique spot_id values per image_id and cell_id for z=0-3
spot_count_z_0_3 = filtered_df_z_0_3.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=4-7
spot_count_z_4_7 = filtered_df_z_4_7.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=8-11
spot_count_z_8_11 = filtered_df_z_8_11.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=12-15
spot_count_z_12_15 = filtered_df_z_12_15.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=16-19
spot_count_z_16_19 = filtered_df_z_16_19.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=20-23
spot_count_z_20_23 = filtered_df_z_20_23.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Count unique spot_id values per image_id and cell_id for z=24-27
spot_count_z_24_27 = filtered_df_z_24_27.groupby(['image_id', 'cell_id'])['spot_id'].nunique().sum()

# Save the total spot counts for this time point
total_spot_counts_by_time[time_point] = total_spot_count
spot_counts_z_0_3_by_time[time_point] = spot_count_z_0_3
spot_counts_z_4_7_by_time[time_point] = spot_count_z_4_7
spot_counts_z_8_11_by_time[time_point] = spot_count_z_8_11
spot_counts_z_12_15_by_time[time_point] = spot_count_z_12_15
spot_counts_z_16_19_by_time[time_point] = spot_count_z_16_19
spot_counts_z_20_23_by_time[time_point] = spot_count_z_20_23
spot_counts_z_24_27_by_time[time_point] = spot_count_z_24_27

# Prepare data for plotting
times = list(total_spot_counts_by_time.keys())
total_spot_counts = list(total_spot_counts_by_time.values())
spot_counts_z_0_3 = list(spot_counts_z_0_3_by_time.values())
spot_counts_z_4_7 = list(spot_counts_z_4_7_by_time.values())
spot_counts_z_8_11 = list(spot_counts_z_8_11_by_time.values())
spot_counts_z_12_15 = list(spot_counts_z_12_15_by_time.values())
spot_counts_z_16_19 = list(spot_counts_z_16_19_by_time.values())
spot_counts_z_20_23 = list(spot_counts_z_20_23_by_time.values())
spot_counts_z_24_27 = list(spot_counts_z_24_27_by_time.values())

# Create the plot
plt.figure(figsize=(10,6))

# Plot total spot counts across all z-values
plt.plot(times, total_spot_counts, marker='o', linestyle='-', color='b', markersize=8, label='Total Spot Counts')

# Plot z=24-27 spot counts
plt.plot(times, spot_counts_z_24_27, marker='o', linestyle='-', color='c', markersize=8, label='Spot Counts (z=24-27)')

# Plot z=20-23 spot counts
plt.plot(times, spot_counts_z_20_23, marker='o', linestyle='-', color='c', markersize=8, label='Spot Counts (z=20-23)')

# Plot z=16-19 spot counts
plt.plot(times, spot_counts_z_16_19, marker='o', linestyle='-', color='c', markersize=8, label='Spot Counts (z=16-19)')

# Plot z=12-15 spot counts
plt.plot(times, spot_counts_z_12_15, marker='o', linestyle='-', color='c', markersize=8, label='Spot Counts (z=12-15)')

# Plot z=8-11 spot counts
plt.plot(times, spot_counts_z_8_11, marker='o', linestyle='-', color='c', markersize=8, label='Spot Counts (z=8-11)')

# Plot z=4-7 spot counts
plt.plot(times, spot_counts_z_4_7, marker='o', linestyle='-', color='r', markersize=8, label='Spot Counts (z=4-7)')

# Plot z=0-3 spot counts
plt.plot(times, spot_counts_z_0_3, marker='o', linestyle='-', color='r', markersize=8, label='Spot Counts (z=0-3)')


# Add labels and title
plt.title('Spot Counts Through Time (All z-stacks and z-slice subsets) 100nM Dex')
plt.xlabel('Time (min)')
plt.ylabel('Spot Count')
plt.grid(True)

# Adjust the legend placement to move it slightly up from the lower right corner
plt.legend(loc='upper left', bbox_to_anchor=(0, 1))

# Display the plot
plt.show()
Loading

0 comments on commit 017057b

Please sign in to comment.