BioSwift

master

An attempt to create a set of freely available tools for biological computation written in pure Swift
valdirunars/BioSwift

Description

An attempt to create a set of freely available tools for biological computation written in pure Swift

Features

  • DNA & RNA Sequencing
    • Pattern matching algorithms
    • Reverse Compliment
    • Transcription
    • Translation (into Protein)
    • Ambiguous alphabet support
    • Probability matching
  • Protein
    • Pattern matching algorithms
    • Ambiguous alphabet support
    • Probability matching
  • IO Support (e.g. support for file formats FASTA, FASTQ, EMBL etc.)

How To Use

This library is brand new with a lot of features missing, but it's not entirely useless

Swift Package Manager

.Package(url: "https://github.com/valdirunars/BioSwift.git", from: "0.0.1")

Sequencing

var genome: DNAGenome = "AGCTGCTTTGGCGCAATGATCGAGCTGCTTTGGCGCAATGATCGAGCTGCTTTGGCGCAATGATCGAGCTGCTTTGGCGCAATGATCG"
!genome
// "TCGACGAAACCGCGTTACTAGCTCGACGAAACCGCGTTACTAGCTCGACGAAACCGCGTTACTAGCTCGACGAAACCGCGTTACTAGC"

genome.reverseComplement()
// "CGATCATTGCGCCAAAGCAGCTCGATCATTGCGCCAAAGCAGCTCGATCATTGCGCCAAAGCAGCTCGATCATTGCGCCAAAGCAGCT"

genome.indicesOfMinimalSkew(increment: .a, decrement: .t)
// [ 74, 75, 76, 77, 78, 79 ]

genome.mostFrequentPattern(length: 2)
// "GC"

genome = "ACGTTGCATGTCGCATGATGCATGAGAGCT"
genome.mostFrequentPatterns(length: 4, maxDistance: 1)
// [ "GATG", "ATGC", "ATGT" ]

genome = "AGT"
genome.neighbors(maxDistance: 1)
// [ "AGT", "CGT", "TGT", "GGT", "ACT", "AAT", "ATT", "AGA", "AGC", "AGG" ]

let genomes: [DNAGenome] = [
    "CTTTTAGTGGTATTAAGGGTGCCCA",
    "ATTCTAGCCCTATAAGCAATCACTC",
    "GAATGAATATACTCTGACAATATCA",
    "GCTTGCCGGGATTCACACACTATGA",
    "CTGTGTATTAGACGAACTTAAGTCC",
    "CAATATGAGCGTTAGGGAGCTATAA",
    "CGTAGTATGAAAGCGCTCCCTTCCT",
    "ACATTTATAAGGAGTATGGCAGTAG",
    "ATGAGACTCGCACTCTATGATGGCC",
    "ATGGATGCAATATTAGCGGCTAAAT"
]
genomes.motifs(length: 5, maxDistance: 1)
// [ "ATTAT", "TATAA", "TATCA", "TATGA", "TATTA" ]

genome = "AGCATGGGCCCAAACTTTCATAAGCCGGAGCAATGCC"

genome.transcribe()
// RNAGenome("AGCAUGGGCCCAAACUUUCAUAAGCCGGAGCAAUGCC")
genome.transcribe()
// DNAGenome("AGCATGGGCCCAAACTTTCATAAGCCGGAGCAATGCC")

let protein: Protein = genome.translate()
// "MGPNFHKPEQ"

Init sequences from FASTA file

let fastaURL = URL(string: "../genome.fasta")!
var fastaFileData: Data! = Data(contentsOf: fastaURL)

let genomes: [DNAGenome]? = try! DNAGenome.decode(fastaFileData, type: .fasta)

let proteinFastaURL = URL(string: "../protein.fasta")!
fastaFileData = Data(contentsOf: proteinFastaURL, type: .fasta)

let proteins: [Protein]? = try! Protein.decode(fastaFileData)

Encode sequences to FASTA

let genome: DNAGenome = "ACGT"
let data: Data? = genome.encode(.fasta)

Compression

let genome: DNAGenome = "ACGT"
let compressed: Data! = genome.compress(.bigIntCompress)

let decompressed: DNAGenome = DNAGenome.decompress(data: compressed, type: .bigIntCompress)

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Tue Oct 22 2024 06:01:52 GMT-0900 (Hawaii-Aleutian Daylight Time)