@veg/hyphy-eye
Version:
Observable Framework application for building, testing, and exporting visualization components for Datamonkey.org
255 lines (187 loc) • 9.18 kB
Markdown
HyPhy-Eye is an Observable Framework application for building, testing, and exporting visualization components for Datamonkey and HyPhy results. It provides a structured environment where you can develop components with example data, view them in example pages, and export them as an npm package for use in production environments.
The project includes:
- Reusable visualization components for HyPhy analysis results
- Utility functions for data processing and manipulation
- Statistical functions for analysis
- Example pages demonstrating each HyPhy method
- A standardized export system for npm packaging
- Node.js (v14 or higher)
- npm or yarn
```bash
git clone https://github.com/veg/hyphy-eye.git
cd hyphy-eye
npm install
```
This is an [Observable Framework](https://observablehq.com/framework/) app. To start the local preview server, run:
```bash
npm run dev
```
This will launch the Observable Framework application at http://localhost:3000, where you can browse and interact with the example pages.
Components are located in the `src/components` directory. Each component should:
1. Be in its own file or subdirectory
2. Export a function that returns an Observable-compatible element
3. Include appropriate TypeScript definitions if applicable
Example:
```javascript
// src/components/my-component.js
export function MyComponent(data, options = {}) {
// Component implementation
return element;
}
```
You can test components by creating example pages in the `src/pages` directory:
1. Create a new markdown file in `src/pages`
2. Import and use your component in the page
3. View the page in the development server
Example:
```markdown
```js
import { MyComponent } from '../components/my-component.js';
const data = { /* example data */ };
```
<div>${MyComponent(data)}</div>
```
HyPhy-Eye includes a comprehensive registry of all supported HyPhy methods and their visualizations. The registry provides a structured way to discover and use available visualizations for each method.
The registry includes:
- All supported HyPhy methods (BUSTED, aBSREL, FEL, MEME, GARD, NRM, MULTIHIT)
- Available visualizations for each method (plots, tables, networks, trees)
- Component paths for each visualization
- Method-specific attribute getter functions
- Default configuration options
### Updating the Registry
To add or update a method in the registry:
1. Edit `src/registry.ts` to add/update the method definition
2. Ensure the method includes:
- A clear name and description
- List of visualizations with:
- Name and description
- Component path (relative to `src/`)
- Visualization type (plot, table, network, or tree)
- Options object with default values
- Attribute getter function information with parameters
Example of adding a new visualization:
```typescript
// Add a new visualization to an existing method
FEL: {
name: 'FEL',
description: 'Fixed Effects Likelihood',
visualizations: [
{
name: 'New Visualization',
description: 'Description of the visualization',
component: 'new-component.js',
type: 'plot',
options: {
// Default options
}
}
],
attributes: {
function: 'getFelAttributes',
parameters: {
resultsJson: 'Object'
}
}
}
```
The registry can be imported and used in two ways:
```javascript
// Import the registry
import { HyPhyMethods } from 'hyphy-eye/registry';
// Get available methods
const methods = Object.values(HyPhyMethods);
// Get visualizations for a specific method
const felVisualizations = HyPhyMethods.FEL.visualizations;
// Get the attribute getter function for a method
const getBustedAttrs = HyPhyMethods.BUSTED.attributes.function;
```
All components, utilities and functions are exported through `src/index.js`. The registry is also exported through `src/registry.js`.
```bash
npm run build-npm
npm pack
npm publish
```
Then in your project:
```bash
npm install hyphy-eye
```
```javascript
// Import specific components or utilities
import { TileTable, getAbsrelAttributes } from 'hyphy-eye';
```
Contributions are welcome! Please feel free to submit a Pull Request.
For more information on Observable Framework, see <https://observablehq.com/framework/getting-started>.
PRs are welcome!
Our Framework project looks something like this:
```ini
.
├─ src
│ ├─ components
│ │ ├─ tile-table
│ │ ├─ rate-summary-plots
│ │ └─ omega-plots.js
│ ├─ stats
│ │ └─ chi-squared.js
│ ├─ utils
│ │ └─ phylotree-utils.js
│ ├─ data
│ │ └─ meme.json
│ ├─ pages
│ │ ├─ absrel.md
│ │ ├─ busted.md
│ │ ├─ meme.md
│ │ └─ component-demo.md
│ ├─ absrel
│ │ └─ absrel-utils.js
│ ├─ busted
│ │ └─ busted-utils.js
│ ├─ meme
│ │ └─ meme-utils.js
│ └─ index.md
├─ .gitignore
├─ observablehq.config.js
├─ package.json
├─ README.md
└─ rollup.config.js
```
**`src`** - This is the “source root” — where your source files live. Pages go here. Each page is a Markdown file. Observable Framework uses [file-based routing](https://observablehq.com/framework/project-structure#routing), which means that the name of the file controls where the page is served. You can create as many pages as you like. Use folders to organize your pages.
**`src/index.md`** - This is the home page for your app. You can have as many additional pages as you’d like, but you should always have a home page, too.
**`src/data`** - You can put [data loaders](https://observablehq.com/framework/data-loaders) or static data files anywhere in your source root, but we recommend putting them here.
**`src/components`** - You can put shared [JavaScript modules](https://observablehq.com/framework/imports) anywhere in your source root, but we recommend putting them here. This helps you pull code out of Markdown files and into JavaScript modules, making it easier to reuse code across pages, write tests and run linters, and even share code with vanilla web applications.
**`src/stats`** - You can put shared stats functions here, which the various components or demo pages might use. This makes it easier to reuse code across pages, write tests and run linters, and even share code with vanilla web applications.
**`src/utils`** - You can put shared utility functions here, which the various components or demo pages might use. This makes it easier to reuse code across pages, write tests and run linters, and even share code with vanilla web applications.
**`observablehq.config.js`** - This is the [app configuration](https://observablehq.com/framework/config) file, such as the pages and sections in the sidebar navigation, and the app’s title.
| Command | Description |
| -------------------- | -------------------------------------------------------- |
| `npm install` | Install or reinstall dependencies |
| `npm run dev` | Start local preview server |
| `npm run build` | Build your static site, generating `./dist` |
| `npm run deploy` | Deploy your app to Observable |
| `npm run clean` | Clear the local data loader cache |
| `npm run observable` | Run commands like `observable help` |
| `npm run bundle` | Prepare javascript modules and types for distribution |
| `npm run clean-npm` | Cleans `/dist` from previous `bundle` runs |
| `npm run build-npm` | Runs `clean-npm` followed by `bundle` |