Coverage for src/instawell/figures/fig_06_min_temp.py: 0%

21 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-07 15:47 -0600

1import logging 

2 

3import pandas as pd 

4import plotly.express as px 

5 

6from instawell.core.exp_context import ExperimentContext 

7from instawell.core.steps import StepFiles 

8from instawell.utils.utils import convert_concentration_to_float 

9 

10# set logging level to INFO 

11 

12logger = logging.getLogger(__name__) 

13 

14 

15def create_mintemp_figures_generator(ctx: ExperimentContext): 

16 """ 

17 Generates Plotly figures from grouped data. 

18 

19 This function groups the input DataFrame by 'ligand', 'protein', and 

20 'buffer', then yields a line plot figure for each group. 

21 

22 Args: 

23 data_df: A pandas DataFrame containing the data to plot. 

24 It must include 'ligand', 'protein', 'buffer', 

25 'Temperature', 'value', and 'well_unqcond' columns. 

26 

27 Yields: 

28 A Plotly figure object for each group. 

29 """ 

30 # Load the organized data 

31 min_temperatures_data_path = ctx.experiment_dir / StepFiles.MIN_TEMPERATURES_DATA 

32 if not min_temperatures_data_path.exists(): 

33 raise FileNotFoundError( 

34 f"Min temperatures data file not found: {min_temperatures_data_path}" 

35 ) 

36 data_df = pd.read_csv(min_temperatures_data_path) 

37 

38 # ensure the necessary columns are present 

39 required_columns = [ 

40 "unqcond", 

41 "min_temperature", 

42 "concentration", 

43 "ligand", 

44 "protein", 

45 "buffer", 

46 ] 

47 

48 for col in required_columns: 

49 if col not in data_df.columns: 

50 raise ValueError(f"Missing required column: {col} in the data.") 

51 

52 data_df["concentration2"] = data_df["concentration"].apply(convert_concentration_to_float) 

53 grouped_data = data_df.groupby(["ligand", "protein", "buffer"]) 

54 

55 for (ligand, protein, buffer), group in grouped_data: 

56 fig = px.scatter( 

57 group, 

58 x="concentration2", 

59 y="min_temperature", 

60 color="ligand", 

61 title=f"Min Temperature for {ligand} and {protein} in {buffer} Buffer", 

62 ) 

63 yield fig