Skip to content

A Go REST API that calculates F2 generation probabilities in plant breeding genetics. Calculate inheritance patterns and expected phenotype distributions based on parent plant genotypes. Features Swagger documentation and handles multiple genetic traits with dominant/recessive expressions. 🧬 🌿

License

Notifications You must be signed in to change notification settings

sTAKKLE5/breeding-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Breeding Probability Calculator REST API

A Go-based REST API for calculating breeding probabilities in plant genetics. This service helps determine the likelihood of specific trait combinations in F2 generation plants.

πŸ“‹ Table of Contents

πŸš€ Features

  • Calculate F2 generation trait probabilities
  • Support for multiple genetic traits
  • Handle dominant and recessive gene expressions
  • RESTful API with Swagger documentation
  • JSON request/response format
  • Input validation and error handling

πŸ”§ Prerequisites

  • Go 1.19 or higher
  • Git

πŸ’» Installation

  1. Clone the repository:
git clone https://github.com/stakkle5/breeding-rest.git
cd breeding-rest
  1. Install dependencies:
go mod download
  1. Build the application:
go build -o breeding-rest

βš™οΈ Configuration

The application uses environment variables for configuration. Create a .env file in the project root:

PORT=8080
GIN_MODE=debug  # Use 'release' for production

πŸ“š API Documentation

Swagger Documentation

The API is documented using Swagger/OpenAPI. Access the Swagger UI at:

http://localhost:8080/swagger/index.html

To regenerate Swagger documentation:

swag init

API Endpoints

Calculate Trait Probability

POST /api/v1/trait-probability

Request body example:

{
  "motherPlant": {
    "name": "Purple Flash",
    "traits": [
      {
        "name": "Regular Leave Shape",
        "dominant": true,
        "geneLabel": "L"
      },
      {
        "name": "Purple Foliage",
        "dominant": false,
        "geneLabel": "C"
      }
    ]
  },
  "fatherPlant": {
    "name": "Candlelight Mutant",
    "traits": [
      {
        "name": "Mutant Leave Shape",
        "dominant": false,
        "geneLabel": "L"
      },
      {
        "name": "Green Foliage",
        "dominant": true,
        "geneLabel": "C"
      }
    ]
  },
  "plantCount": 64
}

Response example:

{
  "plantCount": 64,
  "motherPlantName": "Purple Flash",
  "fatherPlantName": "Candlelight Mutant",
  "combinations": [
    {
      "description": "Regular Leave Shape, Green Foliage",
      "genotype": "L_ C_",
      "numberOfPlants": 36,
      "percentage": 56.25
    },
    {
      "description": "Regular Leave Shape, Purple Foliage",
      "genotype": "L_ cc",
      "numberOfPlants": 12,
      "percentage": 18.75
    }
    // ... more combinations
  ]
}

πŸ“ Usage Examples

Using cURL:

curl -X POST "http://localhost:8080/api/v1/trait-probability" \
     -H "Content-Type: application/json" \
     -d @example-request.json

Using Go Client:

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

func main() {
    request := models.TraitRequest{
        // ... populate request
    }
    
    jsonData, _ := json.Marshal(request)
    resp, err := http.Post(
        "http://localhost:8080/api/v1/trait-probability",
        "application/json",
        bytes.NewBuffer(jsonData),
    )
    // Handle response
}

πŸ› οΈ Development

Project Structure

breeding-rest/
β”œβ”€β”€ main.go
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ handlers/
β”‚   β”‚   └── traitProbability.go
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── trait.go
β”‚   └── routes/
β”‚       └── routes.go
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ docs.go
β”‚   β”œβ”€β”€ swagger.json
β”‚   └── swagger.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ LICENSE
└── README.md

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Go REST API that calculates F2 generation probabilities in plant breeding genetics. Calculate inheritance patterns and expected phenotype distributions based on parent plant genotypes. Features Swagger documentation and handles multiple genetic traits with dominant/recessive expressions. 🧬 🌿

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published