Skip to content

A kotlin library and API for creating genomes with Kotlin.

License

Notifications You must be signed in to change notification settings

wildware-uk/kogenome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KoGenome

License Kotlin Multiplatform

KoGenome is a Kotlin Multiplatform library for representing and expressing genomes. It provides a flexible and efficient way to work with genomic data across different platforms.

Features

  • Genome Representation: Store and manipulate genomic data as byte arrays
  • Genetic Operations: Perform mutations and crossovers with different strategies
  • Data Interpretation: Read genomic data in various formats (byte, short, int, float)
  • Naming System: Generate human-readable identifiers for genomes
  • Cross-Platform: Works on JVM, iOS, and Linux
  • Java Interoperability: Fully usable from Java code

Installation

Gradle (Kotlin DSL)

// In your build.gradle.kts
dependencies {
    implementation("io.github.kotlin:library:1.0.0")
}

Gradle (Groovy DSL)

// In your build.gradle
dependencies {
    implementation 'io.github.kotlin:library:1.0.0'
}

Maven

<dependency>
    <groupId>io.github.kotlin</groupId>
    <artifactId>library</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Kotlin

Creating and Manipulating Genomes

// Create a genome from a byte array
val bytes = byteArrayOf(1, 2, 3, 4, 5)
val genome = Genome.from(bytes)

// Get the size of the genome
val size = genome.size // 5

// Access a specific byte
val byte = genome[2] // 3

// Create a random genome
val randomGenome = Genome.random(10)

// Clone a genome
val clonedGenome = Genome.clone(genome)

// Mutate a genome with 10% probability per byte
val mutatedGenome = Genome.mutate(genome, 0.1f)

// Perform crossover between two genomes
val parent1 = Genome.random(20)
val parent2 = Genome.random(20)

// Single-point crossover at position 10
val (child1, child2) = Genome.crossover(
    parent1, 
    parent2, 
    Genome.CrossoverType.SinglePoint(10)
)

// Two-point crossover at positions 5 and 15
val (child3, child4) = Genome.crossover(
    parent1, 
    parent2, 
    Genome.CrossoverType.TwoPoints(5, 15)
)

// Uniform crossover
val (child5, child6) = Genome.crossover(
    parent1, 
    parent2, 
    Genome.CrossoverType.Uniform
)

Reading Genomic Data with Activator

// Create a genome
val bytes = byteArrayOf(0x12, 0x34, 0x56, 0x78, 0x9A.toByte())
val genome = Genome.from(bytes)

// Create an activator to read from the genome
val activator = Activator(genome)

// Read a single byte
val byte = activator.getByte() // 0x12

// Read a short (2 bytes)
val short = activator.getShort() // 0x3456

// Read an int (4 bytes)
val int = activator.getInt() // Reads 4 bytes

// Read a normalized float value
val float = activator.getFloat() // Value between -1.0 and 1.0

// Select between different operations based on genome data
val result = activator.select(
    { "Option A" },
    { "Option B" },
    { "Option C" }
)

Naming Genomes

// Create a genome
val bytes = byteArrayOf(10, 20, 30, 40, 50)
val genome = Genome.from(bytes)

// Create a namer with default prefix "S"
val defaultNamer = SimpleNamer()
val name1 = defaultNamer.name(genome) // "S5-0a32140a"

// Create a namer with custom prefix
val customNamer = SimpleNamer("Genome")
val name2 = customNamer.name(genome) // "Genome5-0a32140a"

Java

Working with Genomes in Java

// Create a genome from a byte array
byte[] bytes = {1, 2, 3, 4, 5};
Genome genome = Genome.from(bytes);

// Get the size of the genome
int size = genome.getSize(); // 5

// Access a specific byte
byte value = genome.get(2); // 3

// Create a random genome
Genome randomGenome = Genome.random(10);

// Clone a genome
Genome clonedGenome = Genome.clone(genome);

// Mutate a genome with 10% probability per byte
Genome mutatedGenome = Genome.mutate(genome, 0.1f);

Using the Activator in Java

// Create a genome
byte[] bytes = {0x12, 0x34, 0x56, 0x78, (byte)0x9A};
Genome genome = Genome.from(bytes);

// Create an activator
Activator activator = new Activator(genome);

// Read data
byte b = activator.getByte();
short s = activator.getShort();
int i = activator.getInt();
float f = activator.getFloat();

Using the Namer in Java

// Create a genome
byte[] bytes = {10, 20, 30, 40, 50};
Genome genome = Genome.from(bytes);

// Create a namer with default prefix
SimpleNamer namer = new SimpleNamer();
String name = namer.name(genome);

API Documentation

Genome

The Genome class is the core component for representing genomic data:

  • size: Gets the size of the genome in bytes
  • get(index): Retrieves the byte at the specified index
  • from(bytes): Creates a genome from a byte array
  • random(length): Creates a random genome of the specified length
  • clone(genome): Creates an exact copy of a genome
  • mutate(genome, probability): Creates a mutated copy with the specified mutation probability
  • crossover(first, second, crossoverType): Performs crossover between two genomes

Activator

The Activator class provides utilities for reading and interpreting genomic data:

  • getByte(): Reads a single byte from the genome
  • getShort(): Reads two bytes and combines them into a short value
  • getInt(): Reads four bytes and combines them into an integer value
  • getFloat(): Reads two bytes and converts them to a normalized float value
  • select(lambdas): Selects and executes one of the provided lambdas based on genomic data

Namer

The Namer interface and SimpleNamer implementation provide a way to generate human-readable identifiers for genomes:

  • name(genome): Generates a name for the given genome
  • SimpleNamer(prefix): Creates a namer with the specified prefix (default is "S")

Supported Platforms

KoGenome is a Kotlin Multiplatform library that supports:

  • JVM (Java Virtual Machine)
  • iOS (x64, arm64, simulator)
  • Linux (x64)

Contributing

Contributions to KoGenome are welcome! Here are some guidelines:

  • Follow Kotlin KMP code styles
  • Test new code

Fork, then submit a pull request!

License

KoGenome is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

About

A kotlin library and API for creating genomes with Kotlin.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors