Split amino acid and nucleotide sequences

A labmate got a FASTA file of sequences that had a mix of amino acids and nucleotides that she wanted separated into separate files. Here's a little script to do that. Again, I wish there was an easier way to get the basename for a file that does not have the extension.

#!/usr/bin/env perl6

sub MAIN (Str $file) {
    my $ext   = $file.IO.extension;
    (my $base = $file.IO.basename) ~~ s/\.$ext$//;
    my $dna   = open "$base.fna", :w;
    my $aa    = open "$base.faa", :w;
    my $fh    = open $file, :r, nl-in => '>';

    for $fh.lines -> $rec {
        next unless $rec;
        my ($header, @seqs) = $rec.split(/\n/);
        my $seq = @seqs.join;
        my $out = $seq ~~ m:i/^<[actgn]>+$/ ?? $dna !! $aa;
        $out.put(join("\n", ">$header", $seq));

    put "Done.";

Yet another FASTA something

Yes, I write a lot of scripts having to do with parsing FASTA. I want to put lots of example code out into the wild so people have things to read and copy. In this example, a student needed to take a subset of reads from a set of FASTA files as her assembly was failing due to excessive memory requirements. This script will process a list of FASTA files to take the first "n" (default 100,000) reads from each, placing the output file into "out-dir" (or the same directory as the input file). So as not to accidentally overwrite the original data, I append an integer (1, 2, ...) if the output file already exists.

A discussion of DBIx-Class governance and future development

Due to a dispute on the exact nature of the future of DBIx-Class development after Peter Rabbitson's pending departure, a conversaton has been opened on the DBIx-Class mailing list to feel out what the users of DBIx-Class think.

If you have an interest in the module and its future, please have a read of the current sitation, and maybe leave a note on your position:


In order to leave a comment of your own, you can subscribe to the mailing list here:


With David Golden's permission, i reproduce a copy of his email below:

XML::CompactTree::XS Works Again

The Report

In a GitHub issue discussion by my former colleagues, I noticed weird errors being reported. I was curious about the cause, but not enough to dig deeper, and as nothing happened, I forgot about it.

But then they asked me for a favour, and I agreed to help them with a project. But, to my surprise, I wasn’t able to install the tools I originally helped to create, getting the same error as the poor GitHub guy. Quick check of the CPAN Testers showed problems in Treex::PML, one of the underlying libraries, all the way down to 5.20.0. A typical report would look like this:

Monitoring minion workers/tasks using Sparrow

Hi! This is small post concerning sparrow plugin to monitor minion workers. I had some post on this recently, but now I have made some improvements at existed plugin, so I am writing a new one ...

On my production server I use Minion to send emails to my clients. For some reasons there are faults on executing minion tasks or even minion workers get stopped sometimes for reasons unknown. As sending emails is a vital part of the service registration system I need to know if everything goes bad with my email system. Here is minon-check sparrow plugin to risqué.

Install sparrow

$ cpanm Sparrow

Install sparrow plugin

$ sparrow index update # get latest plugins index from Sparrowhub
$ sparrow plg install minion-check # install plugin

Set plugin up

SECURITY RELEASE - Buffer overflow in DBD::mysql perl library

DBD::mysql is the perl DBI driver for MySQL and the primary way Perl applications and scripts access MySQL and MariaDB databases. The source repository is at https://github.com/perl5-dbi/DBD-mysql.

A vulnerability was discovered that can lead to a buffer overflow, possibly triggered by user supplied data. This vulnerability is present in all releases at least back to versions 3.0 of the driver, which were released in 2005.

The CVE identifier for this vulnerability is CVE-2016-1246.

Version 4.037, including the fix for this vulnerability, is available on CPAN at https://metacpan.org/pod/DBD::mysql

Users of DBD::mysql are advised to patch their installations as soon as possible.

We have already made a pre-announcement for this security release at the distros security mailing list. People using DBD::mysql installed from their (linux) distributions can expect to receive an updated version soon.

Many thanks to Pali Rohár for discovering and fixing the vulnerability.

The DBD::mysql maintainers, Patrick Galbraith Michiel Beijen

Mojolicious and FullCalendar.js

You've been pulled into an impromptu meeting where the client now wants a web calendar tacked onto their application. Grimace. Walk out worried. But most important ...

Don't re-invent the wheel.

FullCalendar.js has most of what's required by default, is extensible and will take a json web feed. Given a list of hash refs, Mojolicious will spit out json. I'll show you a short template for displaying the calendar. Creating all your calendar appointments in json is left as an exercise for the reader.

FASTA splitter

#!/usr/bin/env perl6

sub MAIN (
    Str :$fasta! where *.IO.f,
    Int :$number=100,
    Str :$out-dir=$*PROGRAM.IO.dirname
) {
    mkdir $out-dir unless $out-dir.IO.d;

    my $ext      = $fasta.IO.extension;
    my $basename = $fasta.IO.basename;
    $basename ~~ s/\.$ext$//;

    sub writer (@seqs) {
        state $fnum = 0;
        my $fname = $*SPEC.catfile(
            $out-dir, sprintf('%s.%04d.%s', $basename, ++$fnum, $ext)
        printf "Writing %s to %s\n", @seqs.elems, $fname.IO.basename;
        my $out = open $fname, :w;

    my $buffer = '';
    my @seq_buff = ();
    for $fasta.IO.lines -> $line {
        if $line.starts-with('>') {
            push @seq_buff, $buffer if $buffer;
            $buffer = '';

        $buffer ~= $line;

        if @seq_buff.elems == $number {
            @seq_buff = ();

    writer(@seq_buff) if @seq_buff;

    put "Done, see directory '$out-dir'";

I know, another script having to do with FASTA? Well, I'm writing posts if only to put out more example Perl 6 code so people can see what's possible. I also happen to need these things, so I'm writing them and exploring what the language makes easy for me and what I don't understand.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.