Inferring Protein from Spectrum

AUTHOR

L. Grondin

http://rosalind.info/problems/spec/

Sample input

3524.8542
    3710.9335
    3841.974
    3970.0326
    4057.0646

Sample output

WMQS
use v6;



constant monoisotopic-mass-table = Hash.new: <
    A   71.03711
    C   103.00919
    D   115.02694
    E   129.04259
    F   147.06841
    G   57.02146
    H   137.05891
    I   113.08406
    K   128.09496
    L   113.08406
    M   131.04049
    N   114.04293
    P   97.05276
    Q   128.05858
    R   156.10111
    S   87.03203
    T   101.04768
    V   99.06841
    W   186.07931
    Y   163.06333
>;

my @default-data = qw:to/END/;
    3524.8542
    3710.9335
    3841.974
    3970.0326
    4057.0646
    END

sub spec(@weight, :$accuracy = .01) {
    my @a = my @b = sort *.Num, @weight;
    join '', gather
    for @b[1..*] Z- @b[0..*] -> $mass {
        take .key given
        first { abs($_.value - $mass) < $accuracy },
        monoisotopic-mass-table;
    }
}

sub MAIN($input-file = Nil) {
    my @weights = $input-file ?? $input-file.IO.lines !! @default-data;
    say spec @weights;
}

# vim: expandtab shiftwidth=4 ft=perl6

See Also

afrq-grondilu.raku

Counting Disease Carriers

aspc-grondilu.raku

Introduction to Alternative Splicing

cons-grondilu.raku

Consensus and Profile

conv-grondilu.raku

Comparing Spectra with the Spectral Convolution

cstr-grondilu.raku

Creating a Character Table from Genetic Strings

ctbl-grondilu.raku

Creating a Character Table

dbpr-grondilu.raku

Introduction to Protein Databases

dna-gerdr.raku

Counting DNA Nucleotides

dna-grondilu.raku

Counting DNA Nucleotides

eubt-grondilu.raku

Enumerating Unrooted Binary Trees

eval-grondilu.raku

Expected Number of Restriction Sites

fib-grondilu.raku

Rabbits and Recurrence Relations

fibd-grondilu.raku

Mortal Fibonacci Rabbits

gc-gerdr.raku

Computing GC Content

grph-grondilu.raku

Overlap Graphs

hamm-grondilu.raku

Counting Point Mutations

iev-grondilu.raku

Calculating Expected Offspring

indc-grondilu.raku

Independent Segregation of Chromosomes

iprb-grondilu.raku

Mendel's First Law

itwv-grondilu.raku

Finding Disjoint Motifs in a Gene

lcsq-grondilu.raku

Finding a Shared Spliced Motif

lia-grondilu.raku

Independent Alleles

lrep-grondilu-p5.raku

mmch-grondilu.raku

Maximum Matchings and RNA Secondary Structures

mprt-grondilu.raku

Finding a Protein Motif

mrna-grondilu.raku

Inferring mRNA from Protein

nwck-grondilu.raku

Distances in Trees

orf-grondilu.raku

Open Reading Frames

pmch-grondilu.raku

Perfect Matchings and RNA Secondary Structures

pper-grondilu.raku

Partial Permutations

prob-grondilu.raku

Introduction to Random Strings

qrt-grondilu.raku

Quartets

README.md

revc-gerdr.raku

Complementing a Strand of DNA

rna-gerdr.raku

Transcribing DNA into RNA

rstr-grondilu.raku

Matching Random Motifs

sexl-grondilu.raku

Sex-Linked Inheritance

sgra-grondilu.raku

Using the Spectrum Graph to Infer Peptides

sseq-grondilu.raku

Finding a Spliced Motif

subs-grondilu.raku

Finding a Motif in DNA

suff-grondilu.raku

Encoding Suffix Trees

tran-grondilu.raku

Transitions and Transversions

trie-grondilu.raku

Introduction to Pattern Matching

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.