Databases

2 problems from Rosalind — Bioinformatics Armory. Press Run on any block to execute it in your browser.

GBK — GenBank Introduction

solvedbrowser + CLI · online Problem statement Open in the workbench Download .bl

Calls NCBI, so it needs a network connection and its answer can change over time.

Entrez record counts grow as GenBank is updated, so no fixed answer can be asserted.

# Rosalind: GBK — GenBank Introduction
# https://rosalind.info/problems/gbk/
#
# Given: A genus name, two dates in YYYY/M/D format.
# Return: Number of Nucleotide GenBank entries for that genus published between the dates.

let genus = "Anthoxanthum"
let date_from = "2003/07/25"
let date_to = "2005/12/27"

# Build NCBI Entrez query with organism and date range
let query = genus + "[Organism] AND (\"" + date_from + "\"[PDAT] : \"" + date_to + "\"[PDAT])"

try {
    let result = ncbi_search("nucleotide", query)
    println("Result:   " + str(len(result)))
    println("Expected: 7")
    println("Note:     Count may differ as GenBank is updated over time")
} catch e {
    println("NCBI query failed: " + str(e))
    println("Expected: 7 (from Rosalind sample)")
}

FRMT — Data Formats

solvedbrowser + CLI · online Problem statement Open in the workbench Download .bl

Calls NCBI, so it needs a network connection and its answer can change over time.

# Rosalind: FRMT — Data Formats
# https://rosalind.info/problems/frmt/
#
# Given: A collection of n (n <= 10) GenBank entry IDs.
# Return: The shortest of the strings in FASTA format.

let ids = ["FJ817486", "JX069768", "JX469983"]

try {
    # Fetch each sequence as FASTA string, extract sequence length
    let results = ids |> map(|id| {
        let fasta_str = ncbi_sequence(id)
        # Parse: first line is header (>...), rest is sequence
        let lines = split(fasta_str, "\n")
        let header = lines[0]
        # drop(_, 1) removes the ">" header. tail() would not: it returns the
        # *last* n lines and defaults to 5, so the length below counted only
        # the tail of each record and the comparison was decided by luck.
        let seq = drop(lines, 1) |> join("")
        {id: id, header: header, seq_len: len(seq)}
    })

    # Find shortest
    let shortest = results |> reduce(|a, b| {
        if a.seq_len <= b.seq_len then a else b
    })

    println("Shortest: " + shortest.id + " (" + str(shortest.seq_len) + " bp)")
    println("Header:   " + shortest.header)
    println("Expected: JX469983.1 is the shortest")
} catch e {
    println("NCBI fetch failed: " + str(e))
    println("Expected: JX469983.1 is the shortest sequence")
}