Skip to Content
🧬 BioQuery is in beta. We'd love your feedback!
SdkQueryCard Reference

QueryCard Reference

The QueryCard class represents a complete analysis result from BioQuery.

Properties

PropertyTypeDescription
card_idstrUnique identifier (e.g., bq-2025-01-15-abc123)
questionstrOriginal natural language question
interpretationstrHow BioQuery understood the query
answerstrNatural language answer
figuredict | NonePlotly figure JSON
statisticsdictStatistical results
sql_querystr | NoneExecuted BigQuery SQL
methods_textstr | NoneGrant-ready methods text
datalist[dict]Underlying data points
analysis_typestr | NoneType of analysis performed
created_atdatetime | NoneCreation timestamp

Convenience Properties

p_value

Get the p-value from statistics:

card = client.query("Is DDR1 higher in KIRP vs KIRC?") print(f"P-value: {card.p_value}") # 0.00012

effect_size

Get the effect size from statistics:

print(f"Effect size: {card.effect_size}") # 0.45

Methods

show_figure()

Display the interactive Plotly figure in a Jupyter notebook.

card.show_figure()

Raises ValueError if no figure is available.

get_figure()

Get the Plotly figure object for customization.

fig = card.get_figure() fig.update_layout(title="Custom Title") fig.show()

Returns a plotly.graph_objects.Figure.

save_figure()

Save the figure to a file.

card.save_figure( path: str, format: str | None = None, width: int = 1200, height: int = 800, scale: float = 2.0 )

Parameters

ParameterTypeDescription
pathstrOutput file path
formatstr | NoneFormat: png, svg, pdf, html. Auto-detected if not specified
widthintImage width in pixels
heightintImage height in pixels
scalefloatScale factor for raster formats

Examples

# Auto-detect format from extension card.save_figure("figure.png") card.save_figure("figure.svg") # High-resolution for publication card.save_figure("figure.png", width=2400, height=1600, scale=3.0) # Interactive HTML card.save_figure("figure.html")

to_dataframe()

Convert the underlying data to a pandas DataFrame.

df = card.to_dataframe() print(df.head())

Returns a pandas.DataFrame. Raises ValueError if no data is available.

to_json()

Export the full card as JSON.

json_str = card.to_json() with open("card.json", "w") as f: f.write(json_str)

Returns a JSON string with indentation.

to_dict()

Export the full card as a dictionary.

d = card.to_dict() print(d["statistics"])

Example: Complete Workflow

import bioquery import pandas as pd client = bioquery.Client() # Submit query card = client.query("Compare BRCA1 expression in breast vs ovarian cancer") # Print summary print(f"Question: {card.question}") print(f"Answer: {card.answer}") print(f"P-value: {card.p_value}") # Display figure in notebook card.show_figure() # Save for publication card.save_figure("brca1_comparison.svg") # Get data for further analysis df = card.to_dataframe() print(f"Data points: {len(df)}") # Save complete card with open("analysis.json", "w") as f: f.write(card.to_json()) # Get methods text for grant print("\nMethods:") print(card.methods_text)

Statistics Dictionary

The statistics property contains analysis-specific results:

Differential Expression

{ "test": "wilcoxon", "p_value": 0.00012, "effect_size": 0.45, "group1_median": 8.2, "group2_median": 5.1, "group1_n": 150, "group2_n": 200 }

Survival Analysis

{ "test": "log_rank", "p_value": 0.023, "hazard_ratio": 1.8, "ci_lower": 1.1, "ci_upper": 2.9, "median_survival_high": 24.5, "median_survival_low": 36.2 }

Mutation Frequency

{ "mutation_rate": 0.42, "mutated_samples": 126, "total_samples": 300 }