> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openbio.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Analysis (Code Mode)

> Use Python code execution for advanced data analysis and computational tasks

OpenBio's **Code Mode** enables powerful Python-based data analysis directly within your research conversations. When activated, OpenBio prioritizes using a stateful Jupyter notebook environment for computational tasks, data visualization, and scientific computing.

<Info>
  **What is Code Mode?**

  Code Mode is a toggle that tells OpenBio to use Python code execution tools for computational analysis. When enabled, OpenBio will use the code sandbox environment for data analysis, visualizations, calculations, and other computational tasks.
</Info>

Watch a demo of Code Mode in action:

<iframe className="w-full aspect-video rounded-xl" src="https://www.youtube.com/embed/sds1Eiz0BhA" title="Code Mode Demo" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerPolicy="strict-origin-when-cross-origin" allowFullScreen />

## Activating Code Mode

### Toggle Button

<Info>
  **Location**: Code icon button (\<>) in the chat input toolbar
</Info>

1. Look for the **code icon** in the chat input area
2. Click to toggle Code Mode on/off
3. When active, the icon and the chat input area highlights in purple
4. Your preference is saved automatically

### Visual Indicator

When Code Mode is active:

* The code icon and the chat input area appears highlighted (purple background)
* OpenBio will prioritize Python execution tools
* Code execution results appear inline in your chat

## What Code Mode Does

When Code Mode is enabled, OpenBio:

* **Prioritizes code execution** for computational tasks
* **Uses Python tools** for data analysis, visualizations, and calculations
* **Maintains state** across multiple code executions in the same chat
* **Provides a sandboxed environment** with pre-installed scientific libraries

## Available Capabilities

### Pre-installed Libraries

The code sandbox includes popular data science packages:

* **Data manipulation**: `pandas`, `numpy`
* **Visualization**: `matplotlib`, `seaborn`
* **Scientific computing**: `scipy`, `scikit-learn`
* **Bioinformatics**: Standard Python libraries for sequence analysis

### File Management Integration

Code Mode integrates with OpenBio's file system:

* **Upload files**: Transfer project files to the sandbox for analysis
* **Download results**: Save analysis outputs back to your project
* **List files**: See what's available in the sandbox environment

## Common Use Cases

### Data Analysis

Analyze experimental data, datasets, and research results:

```
Analyze the protein expression data in @experiment_results.csv
Create a scatter plot showing correlation between variables
Calculate statistical significance of the differences
```

### Visualization

Generate plots, charts, and visualizations:

```
Create a heatmap of gene expression data
Plot the binding affinity distribution
Generate a 3D visualization of the molecular structure
```

### Scientific Computing

Perform calculations and simulations:

```
Calculate GC content for these DNA sequences
Perform statistical analysis on the experimental results
Simulate protein folding kinetics
```

### Bioinformatics Analysis

Process biological data:

```
Parse FASTA files and extract sequences
Calculate sequence similarity scores
Analyze phylogenetic relationships
```

## Working with Files

### Using File References

Reference uploaded files with @:

```
Analyze the sequences in @protein_sequences.fasta
```

This ensures OpenBio knows which file you mean and will use it for the analysis. OpenBio will also automatically upload the file to the sandbox for you.

### Downloading Results

After the analysis is complete, OpenBio will automatically save the analysis outputs back to your project. In case it does not, you can ask OpenBio to download the results:

```
Download the processed_data.csv and plot.png to my project
```

Files are saved to your project filesystem and you can access them through the Files tab.

<Tip>
  When working on a file, it is better to create a folder that OpenBio can use to save the results. You should save the input files in the same folder as the analysis files.
  Also, better to reference the folder in your query to make sure OpenBio saves the results in the same folder.

  ```
  Analyze the sequences in @sequences folder, and save the results in the same folder.
  ```
</Tip>

## Rich Output Support

For each session, the outputs and code of the analysis are available in the research panel. You can open the "Python Session" tab to view the outputs from the visualizations and code of the analysis.

This displays the outputs in a readable format.

* **Text output**: Print statements and return values
* **DataFrames**: Formatted tables from pandas
* **Images**: Generated figures and charts
* **HTML**: Interactive visualizations

## Best Practices

<AccordionGroup>
  <Accordion title="Be Specific About Data">
    Tell OpenBio what data you want to analyze:

    * "Analyze the protein sequences in @sequences.fasta"
    * "Create a plot of binding affinities from @experiment.csv"
  </Accordion>

  <Accordion title="Describe Your Data">
    Describe the data you are working on:

    * "I am working on the protein sequences in @sequences.fasta"
    * "I am working on the binding affinities from @experiment.csv"
  </Accordion>

  <Accordion title="Describe Your Goals">
    Explain what you want to achieve:

    * "Calculate the mean and standard deviation"
    * "Create a scatter plot with regression line"
    * "Find sequences with GC content > 60%"
  </Accordion>

  <Accordion title="Request Visualizations">
    Ask for plots and charts explicitly:

    * "Create a bar chart showing..."
    * "Generate a heatmap of..."
    * "Plot the distribution of..."
  </Accordion>

  <Accordion title="Save Important Results">
    Always download important outputs:

    * "Save the processed data to my project"
    * "Download the visualization as PNG"
    * "Export the results to CSV"
  </Accordion>

  <Accordion title="Use File References">
    Reference uploaded files with @:

    * "@my\_data.csv" instead of "my\_data.csv"
    * This ensures OpenBio knows which file you mean
  </Accordion>
</AccordionGroup>

## Limitations

* **Timeout protection**: Long-running code may timeout and in case you leave the page, the session will be lost.
* **Resource limits**: Very large datasets may need optimization
* **Package installation**: Some packages may need to be installed on-demand, OpenBio will install them for you.
* **State scope**: Variables persist only within the same chat session

## Next Steps

<CardGroup cols={2}>
  <Card title="Chat Guide" href="/user-guide/features/chat">
    Learn more about chat interactions
  </Card>

  <Card title="File Management" href="/user-guide/features/file-management">
    Organize your data files
  </Card>

  <Card title="Notebooks" href="/user-guide/features/notebooks">
    Document your analysis findings
  </Card>

  <Card title="Tools Reference" href="/user-guide/tools/overview">
    Explore all available tools
  </Card>
</CardGroup>

<Tip>
  **Pro Tip**: Code Mode is perfect for exploratory data analysis. Start with a simple question, review results, then ask follow-up questions to dive deeper into your data.
</Tip>
