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.
- 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
// In your build.gradle.kts
dependencies {
implementation("io.github.kotlin:library:1.0.0")
}// In your build.gradle
dependencies {
implementation 'io.github.kotlin:library:1.0.0'
}<dependency>
<groupId>io.github.kotlin</groupId>
<artifactId>library</artifactId>
<version>1.0.0</version>
</dependency>// 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
)// 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" }
)// 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"// 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);// 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();// 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);The Genome class is the core component for representing genomic data:
size: Gets the size of the genome in bytesget(index): Retrieves the byte at the specified indexfrom(bytes): Creates a genome from a byte arrayrandom(length): Creates a random genome of the specified lengthclone(genome): Creates an exact copy of a genomemutate(genome, probability): Creates a mutated copy with the specified mutation probabilitycrossover(first, second, crossoverType): Performs crossover between two genomes
The Activator class provides utilities for reading and interpreting genomic data:
getByte(): Reads a single byte from the genomegetShort(): Reads two bytes and combines them into a short valuegetInt(): Reads four bytes and combines them into an integer valuegetFloat(): Reads two bytes and converts them to a normalized float valueselect(lambdas): Selects and executes one of the provided lambdas based on genomic data
The Namer interface and SimpleNamer implementation provide a way to generate human-readable identifiers for genomes:
name(genome): Generates a name for the given genomeSimpleNamer(prefix): Creates a namer with the specified prefix (default is "S")
KoGenome is a Kotlin Multiplatform library that supports:
- JVM (Java Virtual Machine)
- iOS (x64, arm64, simulator)
- Linux (x64)
Contributions to KoGenome are welcome! Here are some guidelines:
- Follow Kotlin KMP code styles
- Test new code
Fork, then submit a pull request!
KoGenome is licensed under the Apache License, Version 2.0. See the LICENSE file for details.