<commit_before>#! /usr/bin/env perl

# This script can be run from any directory

use strict;
use Carp;
use Cwd;
use Data::Dumper;
use File::Basename;
use Getopt::Long;

my $usage =<<"End_of_Usage";

Usage: sudo add-comp.pl [ options ] components

Options:
      -d dest_dir  - destination directory (D = assembly/bin/)
      -f           - force reinstall even if component exists
      -t tmp_dir   - temporary directory (D = /mnt/tmp)

Compute server components:
      basic        - basic dependencies (apt-get, pip, cpan, etc)
      regular      - regular components (modules to be deployed on all compute nodes)
      special      - special components (large modules: acbio, allpaths-lg, etc)
      all          - all components

      a5           - A5 pipeline (v.20120518)
      a6           - Modified A5 pipeline (git)
      ale          - ALE reference-free assembler evaluator (git)
      bowtie       - Bowtie aligner (v2.1)
      bwa          - BWA aligner (git)
      discovar     - Discovar assembler (FTP latest)
      fastqc       - FastQC quality control (v0.10.1)
      fastx        - FastX preprocessing toolkit (v0.0.13)
      gam_ngs      - GAM-NGS assembler merger (git)
      idba         - IDBA_UD assembler (v1.1.1)
      jgi_rqc      - JGI rolling QC (git)
      kiki         - Kiki assembler (git)
      masurca      - MaSuRCA assembler (v2.0.0)
      pacbio       - SMRT Analysis Software (v2.1.1)
      quast        - QUAST assembly evaluator (v2.2)
      ray          - Ray assembler (git)
      reapr        - REAPR reference-free evaluator (v1.0.15)
      screed       - Screed assembly statistics library (git)
      seqtk        - Modified Seqtk preprocessing toolkit (git)
      solexa       - SolexaQA preprocessing tool (v2.1)
      spades       - SPAdes assembler (v3.0)
      velvet       - Velvet assembler (git)

Examples:
      sudo add-comp.pl basic velvet spades
      sudo add-comp.pl -t /space/tmp -d /usr/bin regular

End_of_Usage

my ($help, $dest_dir, $tmp_dir, $force_reinstall);

GetOptions( 'd|dest=s' => \$dest_dir,
            'f|force'  => \$force_reinstall,
            't|tmp=s'  => \$tmp_dir,
            'h|help'   => \$help);

if ($help) { print $usage; exit 0 }

my @regular_comps = qw (basic a5 a6 ale bowtie bwa discovar fastqc fastx gam_ngs idba kiki masurca quast ray reapr screed seqtk solexa spades velvet); 
my @special_comps = qw (pacbio jgi_rqc);

my @all_comps = (@regular_comps, @special_comps);
my %supported = map { $_ => 1 } @all_comps;

my @comps;
# my @comps = @ARGV; @comps = @all_comps if join(' ', @comps) =~ /\ball\b/;
for (@ARGV) {
    if (/\ball\b/) {
        @comps = @all_comps; last;
    } elsif (/\bregular\b/) {
        @comps = (@comps, @regular_comps);
    } elsif (/\bspecial\b/) {
        @comps = (@comps, @special_comps);
    } else {
        push @comps, $_;
    }
}


my $curr_dir = cwd();
my $base_dir = dirname(Cwd::abs_path($0));
$dest_dir  ||= "$base_dir/../bin";
$tmp_dir     = make_tmp_dir($tmp_dir);

for my $c (@comps) {
    if (!$supported{$c}) { print "Warning: $c not supported.\n"; next; }
    my $found = !$force_reinstall && check_if_installed($c);
    if ($found) { print "Found component $c, skipping...\n"; next; }

    print "Installing $c...\n";
    my $func = "install_$c";    
    
    chdir($tmp_dir);
    { no strict 'refs'; &$func(); }
    chdir($curr_dir);
    print "\n";
}


# Core dependencies

# TODO: python: fallback: strip path prefix and check exe in path

sub install_template {
    # we are in the $tmp_dir directory 
    # 1. download source files
    # 2. compile
    # 3. copy executables to $dest_dir
}

sub install_basic {
    my @apt = qw(python-nova build-essential python-pip rabbitmq-server git mongodb cmake zlib1g-dev mpich2 samtools openjdk-7-jre subversion python-matplotlib unzip r-base unp cpanminus picard-tools gcc-4.7 g++-4.7 graphviz csh pkg-config sparsehash libboost-all-dev gawk);
    my @pip = qw(pika python-daemon pymongo requests yapsy numpy biopython);

    # run("apt-get -q -y update");
    for (@apt) { run("apt-get -y install $_") }
    for (@pip) { run("pip install $_") }
}

sub install_a5 {
    run("mkdir -p a5");
    chdir("a5");
    my $dir = "ngopt_a5pipeline_linux-x64_20120518";<commit_msg>install basic modules with one apt-get<commit_after>#! /usr/bin/env perl

# This script can be run from any directory

use strict;
use Carp;
use Cwd;
use Data::Dumper;
use File::Basename;
use Getopt::Long;

my $usage =<<"End_of_Usage";

Usage: sudo add-comp.pl [ options ] components

Options:
      -d dest_dir  - destination directory (D = assembly/bin/)
      -f           - force reinstall even if component exists
      -t tmp_dir   - temporary directory (D = /mnt/tmp)

Compute server components:
      basic        - basic dependencies (apt-get, pip, cpan, etc)
      regular      - regular components (modules to be deployed on all compute nodes)
      special      - special components (large modules: acbio, allpaths-lg, etc)
      all          - all components

      a5           - A5 pipeline (v.20120518)
      a6           - Modified A5 pipeline (git)
      ale          - ALE reference-free assembler evaluator (git)
      bowtie       - Bowtie aligner (v2.1)
      bwa          - BWA aligner (git)
      discovar     - Discovar assembler (FTP latest)
      fastqc       - FastQC quality control (v0.10.1)
      fastx        - FastX preprocessing toolkit (v0.0.13)
      gam_ngs      - GAM-NGS assembler merger (git)
      idba         - IDBA_UD assembler (v1.1.1)
      jgi_rqc      - JGI rolling QC (git)
      kiki         - Kiki assembler (git)
      masurca      - MaSuRCA assembler (v2.0.0)
      pacbio       - SMRT Analysis Software (v2.1.1)
      quast        - QUAST assembly evaluator (v2.2)
      ray          - Ray assembler (git)
      reapr        - REAPR reference-free evaluator (v1.0.15)
      screed       - Screed assembly statistics library (git)
      seqtk        - Modified Seqtk preprocessing toolkit (git)
      solexa       - SolexaQA preprocessing tool (v2.1)
      spades       - SPAdes assembler (v3.0)
      velvet       - Velvet assembler (git)

Examples:
      sudo add-comp.pl basic velvet spades
      sudo add-comp.pl -t /space/tmp -d /usr/bin regular

End_of_Usage

my ($help, $dest_dir, $tmp_dir, $force_reinstall);

GetOptions( 'd|dest=s' => \$dest_dir,
            'f|force'  => \$force_reinstall,
            't|tmp=s'  => \$tmp_dir,
            'h|help'   => \$help);

if ($help) { print $usage; exit 0 }

my @regular_comps = qw (basic a5 a6 ale bowtie bwa discovar fastqc fastx gam_ngs idba kiki masurca quast ray reapr screed seqtk solexa spades velvet); 
my @special_comps = qw (pacbio jgi_rqc);

my @all_comps = (@regular_comps, @special_comps);
my %supported = map { $_ => 1 } @all_comps;

my @comps;
# my @comps = @ARGV; @comps = @all_comps if join(' ', @comps) =~ /\ball\b/;
for (@ARGV) {
    if (/\ball\b/) {
        @comps = @all_comps; last;
    } elsif (/\bregular\b/) {
        @comps = (@comps, @regular_comps);
    } elsif (/\bspecial\b/) {
        @comps = (@comps, @special_comps);
    } else {
        push @comps, $_;
    }
}


my $curr_dir = cwd();
my $base_dir = dirname(Cwd::abs_path($0));
$dest_dir  ||= "$base_dir/../bin";
$tmp_dir     = make_tmp_dir($tmp_dir);

for my $c (@comps) {
    if (!$supported{$c}) { print "Warning: $c not supported.\n"; next; }
    my $found = !$force_reinstall && check_if_installed($c);
    if ($found) { print "Found component $c, skipping...\n"; next; }

    print "Installing $c...\n";
    my $func = "install_$c";    
    
    chdir($tmp_dir);
    { no strict 'refs'; &$func(); }
    chdir($curr_dir);
    print "\n";
}


# Core dependencies

# TODO: python: fallback: strip path prefix and check exe in path

sub install_template {
    # we are in the $tmp_dir directory 
    # 1. download source files
    # 2. compile
    # 3. copy executables to $dest_dir
}

sub install_basic {
    my @apt = qw(python-nova build-essential python-pip rabbitmq-server git mongodb cmake zlib1g-dev mpich2 samtools openjdk-7-jre subversion python-matplotlib unzip r-base unp cpanminus picard-tools gcc-4.7 g++-4.7 graphviz csh pkg-config sparsehash libboost-all-dev gawk);
    my @pip = qw(pika python-daemon pymongo requests yapsy numpy biopython);

    # run("apt-get -q -y update");
    run("apt-get -y install " . join(" ", @apt));
    for (@pip) { run("pip install $_") }
}

sub install_a5 {
    run("mkdir -p a5");
    chdir("a5");
    my $dir = "ngopt_a5pipeline_linux-x64_20120518";
{'fraction_non_alphanumeric': 0.12635885447106954, 'fraction_numerical': 0.01636469900642899, 'mean_word_length': 2.3738170347003154, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182221', 'n_tokens_mistral': 3158, 'n_tokens_neox': 3013, 'n_words': 866}