text:
package org.apache.jackrabbit.oak.plugins.index.reference;

import static com.google.common.collect.ImmutableSet.of;
import static com.google.common.collect.Iterables.addAll;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
import static javax.jcr.PropertyType.REFERENCE;
import static javax.jcr.PropertyType.WEAKREFERENCE;
import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
import static org.apache.jackrabbit.oak.api.CommitFailedException.INTEGRITY;
import static org.apache.jackrabbit.oak.api.Type.STRING;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.REF_NAME;
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.WEAK_REF_NAME;
import static org.apache.jackrabbit.oak.plugins.version.VersionConstants.SYSTEM_PATHS;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
import org.apache.jackrabbit.oak.plugins.index.property.strategy.ContentMirrorStoreStrategy;
import org.apache.jackrabbit.oak.spi.commit.DefaultEditor;
import org.apache.jackrabbit.oak.spi.commit.Editor;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

/**
 * Index editor for keeping a references to a node up to date.
 *
 */
class ReferenceEditor extends DefaultEditor implements IndexEditor {

    private static final ContentMirrorStoreStrategy STORE = new ContentMirrorStoreStrategy();

    /** Parent editor, or {@code null} if this is the root editor. */
    private final ReferenceEditor parent;

    /** Name of this node, or {@code null} for the root node. */
    private final String name;

    /** Path of this editor, built lazily in {@link #getPath()}. */
    private String path;

    private final NodeState root;

    private final NodeBuilder definition;

    /**
     * the uuid of the current node, null if the node doesn't have this
     * property.
     */
    private final String uuid;

    /**
     * <UUID, Set<paths-pointing-to-the-uuid>>
     */
    private final Map<String, Set<String>> newRefs;

    /**
     * <UUID, Set<paths-pointing-to-the-uuid>>
     */
    private final Map<String, Set<String>> rmRefs;

    /**
     * <UUID, Set<paths-pointing-to-the-uuid>>
     */
    private final Map<String, Set<String>> newWeakRefs;

    /**
     * <UUID, Set<paths-pointing-to-the-uuid>>
     */
    private final Map<String, Set<String>> rmWeakRefs;

    /**
     * set of removed Ids of nodes that have a :reference property. These UUIDs
     * need to be verified in the #after call
     */
    private final Set<String> rmIds;

    /**
     * set of ids that changed. This can happen when a node with the same name
     * is deleted and added again
     *
     */
    private final Set<String> discardedIds;

    private final Set<String> versionStoreIds;

    /**
     * set of ids that were added during this commit. we need it to reconcile
     * moves
     *
     */
    private final Set<String> newIds;

    public ReferenceEditor(NodeBuilder definition, NodeState root) {
        this.parent = null;
        this.name = null;
        this.path = "/";
        this.definition = definition;
        this.root = root;
        this.uuid = null;
        this.newRefs = newHashMap();
        this.rmRefs = newHashMap();
        this.newWeakRefs = newHashMap();
        this.rmWeakRefs = newHashMap();
        this.rmIds = newHashSet();
        this.discardedIds = newHashSet();
        this.versionStoreIds = newHashSet();
        this.newIds = newHashSet();
    }

    private ReferenceEditor(ReferenceEditor parent, String name, String uuid) {
        this.parent = parent;
        this.name = name;
        this.path = null;
        this.definition = parent.definition;
        this.root = parent.root;
        this.uuid = uuid;
        this.newRefs = parent.newRefs;
        this.rmRefs = parent.rmRefs;
        this.newWeakRefs = parent.newWeakRefs;
        this.rmWeakRefs = parent.rmWeakRefs;
        this.rmIds = parent.rmIds;
        this.discardedIds = parent.discardedIds;
        this.versionStoreIds = parent.versionStoreIds;
        this.newIds = parent.newIds;
    }

    /**
     * Returns the path of this node, building it lazily when first requested.
     */
    private String getPath() {
        if (path == null) {
            path = concat(parent.getPath(), name);
        }
        return path;
    }

    @Override
    public void enter(NodeState before, NodeState after)
            throws CommitFailedException {
    }

    @Override
    public void leave(NodeState before, NodeState after)
            throws CommitFailedException {
        if (parent == null) {
            Set<String> offending = newHashSet(rmIds);
            offending.removeAll(rmRefs.keySet());
            offending.removeAll(newIds);
            if (!offending.isEmpty()) {
                throw new CommitFailedException(INTEGRITY, 1,
                        "Unable to delete referenced node");
            }
            rmIds.addAll(discardedIds);

            // remove ids that are actually deleted (that exist in the rmRefs.keySet())
            versionStoreIds.removeAll(rmRefs.keySet());
            rmIds.addAll(versionStoreIds);

            // update references
            for (Entry<String, Set<String>> ref : rmRefs.entrySet()) {
                String uuid = ref.getKey();
                if (rmIds.contains(uuid)) {
                    continue;
                }
                Set<String> rm = ref.getValue();
                Set<String> add = newHashSet();
                if (newRefs.containsKey(uuid)) {
                    add = newRefs.remove(uuid);
                }
                update(definition, REF_NAME, uuid, add, rm);
            }
            for (Entry<String, Set<String>> ref : newRefs.entrySet()) {
                String uuid = ref.getKey();
                if (rmIds.contains(uuid)) {
                    continue;
                }
                Set<String> add = ref.getValue();
                Set<String> rm = newHashSet();
                update(definition, REF_NAME, uuid, add, rm);
            }

            // update weak references
            for (Entry<String, Set<String>> ref : rmWeakRefs.entrySet()) {
                String uuid = ref.getKey();
                if (rmIds.contains(uuid)) {
                    continue;
                }
                Set<String> rm = ref.getValue();
                Set<String> add = newHashSet();
                if (newWeakRefs.containsKey(uuid)) {
                    add = newWeakRefs.remove(uuid);
                }
                update(definition, WEAK_REF_NAME, uuid, add, rm);
            }
            for (Entry<String, Set<String>> ref : newWeakRefs.entrySet()) {
                String uuid = ref.getKey();
                if (rmIds.contains(uuid)) {
                    continue;
                }
                Set<String> add = ref.getValue();
                Set<String> rm = newHashSet();
                update(definition, WEAK_REF_NAME, uuid, add, rm);
            }
        }
    }

    @Override
    public void propertyAdded(PropertyState after) {
        propertyChanged(null, after);
    }

    @Override
    public void propertyChanged(PropertyState before, PropertyState after) {

        if (before != null) {
            if (before.getType().tag() == REFERENCE) {
                if (isVersionStorePath(getPath())) {
                    addAll(versionStoreIds, before.getValue(STRINGS));
                } else {
                    put(rmRefs, before.getValue(STRINGS),
                            concat(getPath(), before.getName()));
                }
            }
            if (before.getType().tag() == WEAKREFERENCE) {
                put(rmWeakRefs, before.getValue(STRINGS),
                        concat(getPath(), before.getName()));
            }
            if (JCR_UUID.equals(before.getName())) {
                // node remove + add -> changed uuid
                String beforeUuid = before.getValue(STRING);
                if (beforeUuid != null && !beforeUuid.equals(uuid)) {
                    discardedIds.add(beforeUuid);
                }
            }
        }
        if (after != null) {
            if (after.getType().tag() == REFERENCE) {
                if (isVersionStorePath(getPath())) {
                    addAll(versionStoreIds, after.getValue(STRINGS));
                } else {
                    put(newRefs, after.getValue(STRINGS),
                            concat(getPath(), after.getName()));
                }
            }
            if (after.getType().tag() == WEAKREFERENCE) {
                put(newWeakRefs, after.getValue(STRINGS),
                        concat(getPath(), after.getName()));
            }
        }
    }

    @Override
    public void propertyDeleted(PropertyState before) {
        propertyChanged(before, null);
    }

    @Override
    public Editor childNodeAdded(String name, NodeState after) {
        String uuid = after.getString(JCR_UUID);
        if (uuid != null) {
            newIds.add(uuid);
        }
        return new ReferenceEditor(this, name, uuid);
    }

    @Override
    public Editor childNodeChanged(String name, NodeState before,
            NodeState after) {
        return new ReferenceEditor(this, name, after.getString(JCR_UUID));
    }

    @Override
    public Editor childNodeDeleted(String name, NodeState before)
            throws CommitFailedException {
        String uuid = before.getString(JCR_UUID);
        if (uuid != null && check(root, definition.getNodeState(), REF_NAME, uuid)) {
            rmIds.add(uuid);
        }
        return new ReferenceEditor(this, name, uuid);
    }

    // ---------- Utils -----------------------------------------

    private static boolean isVersionStorePath(String oakPath) {
        if (oakPath == null) {
            return false;
        }
        if (oakPath.indexOf(JCR_SYSTEM) == 1) {
            for (String p : SYSTEM_PATHS) {
                if (oakPath.startsWith(p)) {
                    return true;
                }
            }
        }
        return false;
    }

    private static void put(Map<String, Set<String>> map,
            Iterable<String> keys, String value) {
        String asRelative = isAbsolute(value) ? value.substring(1) : value;
        for (String key : keys) {
            Set<String> values = map.get(key);
            if (values == null) {
                values = newHashSet();
            }
            values.add(asRelative);
            map.put(key, values);
        }
    }

    private static void update(NodeBuilder child, String name, String key,
            Set<String> add, Set<String> rm) {
        NodeBuilder index = child.child(name);
        Set<String> empty = of();
        for (String p : rm) {
            STORE.update(index, p, name, child, of(key), empty);
        }
        for (String p : add) {
            // TODO do we still need to encode the values?
            STORE.update(index, p, name, child, empty, of(key));
        }
    }

    private static boolean check(NodeState root, NodeState definition, String name, String key) {
        return definition.hasChildNode(name)
                && STORE.count(root, definition, name, of(key), 1) > 0;
    }

}

redpajama_set_name: RedPajamaGithub


text:
namespace mozc {
namespace gui {
namespace {

void defaultLinkActivated(const QString &str) {
  QByteArray utf8 = str.toUtf8();
  Process::OpenBrowser(string(utf8.data(), utf8.length()));
}

// set document file paths by adding <server_path>/documents/ to file name.
bool AddLocalPath(string *str) {
  const char *filenames[] = { "credits_en.html", "credits_ja.html" };
  for (size_t i = 0; i < arraysize(filenames); ++i) {
    if (str->find(filenames[i]) != string::npos) {
      string tmp;
      const string file_path =
          FileUtil::JoinPath(SystemUtil::GetDocumentDirectory(), filenames[i]);
      Util::StringReplace(*str, filenames[i], file_path, false, &tmp);
      *str = tmp;
      return true;
    }
  }
  return false;
}

void SetLabelText(QLabel *label) {
  string label_text = label->text().toStdString();
  if (AddLocalPath(&label_text)) {
    label->setText(QString::fromStdString(label_text));
  }
}

}  // namespace

AboutDialog::AboutDialog(QWidget *parent)
    : QDialog(parent),
      callback_(NULL) {
  setupUi(this);
  setWindowFlags(Qt::WindowSystemMenuHint);
  setWindowModality(Qt::NonModal);
  QPalette window_palette;
  window_palette.setColor(QPalette::Window, QColor(255, 255, 255));
  setPalette(window_palette);
  setAutoFillBackground(true);
  QString version_info("(");
  version_info += Version::GetMozcVersion().c_str();
  version_info += ")";
  version_label->setText(version_info);

  QPalette palette;
  palette.setColor(QPalette::Window, QColor(236, 233, 216));
  color_frame->setPalette(palette);
  color_frame->setAutoFillBackground(true);

  // change font size for product name
  QFont font = label->font();
#ifdef OS_WIN
  font.setPointSize(22);
#endif  // OS_WIN

#ifdef OS_MACOSX
  font.setPointSize(26);
#endif  // OS_MACOSX

  label->setFont(font);

  SetLabelText(label_terms);
  SetLabelText(label_credits);

  product_image_.reset(new QImage(":/product_logo.png"));
}

void AboutDialog::paintEvent(QPaintEvent *event) {
  // draw product logo
  QPainter painter(this);
  const QRect image_rect = product_image_->rect();
  // allow clipping on right / bottom borders
  const QRect draw_rect(max(5, width() - image_rect.width() - 15),
                        max(0, color_frame->y() - image_rect.height()),
                        image_rect.width(), image_rect.height());
  painter.drawImage(draw_rect, *product_image_.get());
}

void AboutDialog::SetLinkCallback(LinkCallbackInterface *callback) {
  callback_ = callback;
}

void AboutDialog::linkActivated(const QString &link) {
  // we don't activate the link if about dialog is running as root
  if (!RunLevel::IsValidClientRunLevel()) {
    return;
  }
  if (callback_ != NULL) {
    callback_->linkActivated(link);
  } else {
    defaultLinkActivated(link);
  }
}

}  // namespace gui
}  // namespace mozc


text:
server=dev.crunchy.lab
ssh root@$server "systemctl stop cpmagent.service"

scp ./bin/* ./sbin/* \
	root@$server:/var/cpm/bin/

ssh root@$server "systemctl start cpmagent.service"


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdbi.v3.core.array;

import java.lang.reflect.Type;
import java.util.Optional;

import org.jdbi.v3.core.config.ConfigRegistry;

import static org.jdbi.v3.core.generic.GenericTypes.findGenericParameter;

/**
 * A generic {@link SqlArrayTypeFactory} that reflectively inspects an {@link SqlArrayType} and maps
 * only arrays of element type {@code T}. The type parameter {@code T} must be accessible via reflection or an
 * {@link UnsupportedOperationException} will be thrown.
 */
class InferredSqlArrayTypeFactory implements SqlArrayTypeFactory {
    private final Type inferredElementType;
    private final SqlArrayType<?> arrayType;

    InferredSqlArrayTypeFactory(SqlArrayType<?> arrayType) {
        inferredElementType = findGenericParameter(arrayType.getClass(), SqlArrayType.class)
                .orElseThrow(() -> new UnsupportedOperationException("Must use a concretely typed SqlArrayType here"));
        this.arrayType = arrayType;
    }

    @Override
    public Optional<SqlArrayType<?>> build(Type elementType, ConfigRegistry config) {
        return inferredElementType.equals(elementType)
                ? Optional.of(arrayType)
                : Optional.empty();
    }
}


text:
usuario=$(./app/utils/UsuarioLogado.sh)

wget https://downloadsapachefriends.global.ssl.fastly.net/xampp-files/7.1.1/xampp-linux-x64-7.1.1-0-installer.run?from_af=true -O /home/$usuario/Downloads/xampp-linux-x64-7.1.1-0-installer.run

cd /home/$usuario/Downloads/

sudo chmod +x xampp-linux-x64-7.1.1-0-installer.run

sudo ./xampp-linux-x64-7.1.1-0-installer.run

sudo usermod -g root $usuario

sudo chmod 775 /opt/lampp -R
sudo chmod 777 /opt/lampp/htdocs -R

wget https://www.dropbox.com/s/47j3sxtr42l3y5e/xampp.png?dl=0 -O /home/$usuario/Downloads/xampp.png

sudo mv xampp.png /opt/lampp/bin

sudo touch /usr/share/applications/xampp.desktop

sudo chmod 666 /usr/share/applications/xampp.desktop

sudo echo "[Desktop Entry]" > /usr/share/applications/xampp.desktop
sudo echo "Version=1.0" >> /usr/share/applications/xampp.desktop
sudo echo "Type=Application" >> /usr/share/applications/xampp.desktop
sudo echo "Terminal=false" >> /usr/share/applications/xampp.desktop
sudo echo "Name=Xampp" >> /usr/share/applications/xampp.desktop
sudo echo "Exec=gksudo /opt/lampp/manager-linux-x64.run" >> /usr/share/applications/xampp.desktop
sudo echo "Icon=/opt/lampp/bin/xampp.png" >> /usr/share/applications/xampp.desktop
sudo echo "Categories=Application;Development;Java;IDE" >> /usr/share/applications/xampp.desktop

sudo chmod 644 /usr/share/applications/xampp.desktop

sudo rm /home/$usuario/Downloads/xampp-linux-x64-7.1.1-0-installer.run


text:
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit0f9cc13804265250f833d9b42544cb3f::getLoader();


text:
import os
from os.path import join
import logging
import shutil
import pysam

## Local modules
import mglobals
import helpers
import snp2gene
import snps_combine

log = logging.getLogger('pipeline')

def trim():

    log.info('Beginning trim')

    os.chdir(mglobals.samples_path)

    @helpers.multiprocess(mglobals.samples_list)
    def trim_call(sample):
        log.info('Trimming sample {}'.format(sample))

        trimmed_path = join(mglobals.trimmed_path, sample)

        p_trim_R1 = trimmed_path + '_trim_R1.fastq'
        u_trim_R1 = trimmed_path + '_u_trim_R1.fastq'
        p_trim_R2 = trimmed_path + '_trim_R2.fastq'
        u_trim_R2 = trimmed_path + '_u_trim_R2.fastq'

        if os.path.exists(p_trim_R1) and os.path.exists(p_trim_R2):
            log.info('Sample already trimmed, linking from trimmed_path')
            # Need the try block because will fail if link already exists
            try:
                os.symlink(p_trim_R1, os.path.basename(p_trim_R1))
                os.symlink(p_trim_R2, os.path.basename(p_trim_R2))
            except OSError:
                pass
        else:
            threads = str(mglobals.cpu_count//10)  # This optimal for ~40 samples but would
                                                   # probably crash with a higher number.

            log.info('Sample not already trimmed, trimming now')
            trim_params = (['nice', '-n', '5',
                           'java', '-jar', mglobals.trimmomatic_path,
                           'PE',
                           '-threads', threads,
                           '-phred33',
                           sample + '_R1.fastq',
                           sample + '_R2.fastq',
                           p_trim_R1,
                           u_trim_R1,
                           p_trim_R2,
                           u_trim_R2,
                           'SLIDINGWINDOW:4:20',
                           'TRAILING:20',
                           'MINLEN:50'])
            helpers.sub_call(trim_params)
            log.info('Finished trimming sample {}, linking in.'.format(sample))
            os.symlink(p_trim_R1, os.path.basename(p_trim_R1))
            os.symlink(p_trim_R2, os.path.basename(p_trim_R2))

    trim_call()

    log.info('Finished trim')

@helpers.log_func
def my_tophat():

    if mglobals.original:
        log.info('Aligning reads to the original reference fasta')
        fastas = mglobals.original_fastas
    else:
        log.info('Aligning reads to alternate reference fastas')
        fastas = mglobals.alternate_fastas

    @helpers.multiprocess(zip(mglobals.samples_list, fastas))
    def tophat_call(sample, ref_fasta):

        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        ref_fasta_base = ref_fasta.split('.')[0]

        mismatches = '5'
        mate_inner = sample.split('_')[2]
        number_of_samples = len(mglobals.samples_list)
        threads_per_sample = mglobals.cpu_count//number_of_samples

        threads = str(threads_per_sample)
        log.info('threads per sample ' + threads)

        log.info('tophat: aligning sample {} with ref fasta {}'.format(sample, ref_fasta))
        tophat_params = ['nice', '-n', '5',
                         'tophat',
                         '-p', threads,
                         '-G', mglobals.dros_gtf,
                         '--transcriptome-index=../transcriptome_data/known',
                         '-N', mismatches,
                         '--b2-L', '20',
                         '--b2-N', '1',
                         '--read-edit-dist', mismatches,
                         '-o', (sample + '_thout'),
                         '--no-novel-juncs',
                         '--mate-inner-dist', mate_inner,
                         ref_fasta_base,
                         join(mglobals.samples_path, (sample + '_trim_R1.fastq')),
                         join(mglobals.samples_path, (sample + '_trim_R2.fastq'))]
        helpers.sub_call(tophat_params)

        log.info('tophat: finished analyzing sample: {} with ref fasta: {}'.format(sample, ref_fasta))

    # Copy transcriptome index to original_path and alternate_path
    for path in [mglobals.original_path, mglobals.alternate_path]:
        if not os.path.exists(join(path, 'transcriptome_data')):
            log.info('Linking transcriptome data to ' + path)
            os.symlink(mglobals.dros_gtf_index, join(path, 'transcriptome_data'))

    tophat_call()

@helpers.log_func
def my_alignment_filter():

    @helpers.multiprocess(mglobals.samples_list)
    def filter_call(sample):

        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample, (sample + '_thout')))
        else:
            os.chdir(join(mglobals.alternate_path, sample, (sample + '_thout')))

        log.info('Filtering aligned reads for: ' + sample)

        # Index each bamfile
        if not os.path.exists('accepted_hits.bam.bai'):
            pysam.index('accepted_hits.bam')

        # Sort by NH flag
        raw_reads = pysam.Samfile('accepted_hits.bam', 'rb')
        filter_reads = pysam.Samfile('filter.bam', 'wb', template=raw_reads)
        for read in raw_reads.fetch():
            if ('NH', 1) in read.tags:
                filter_reads.write(read)
        raw_reads.close()
        filter_reads.close()

        pysam.index('filter.bam')

    filter_call()

@helpers.log_func
def my_pileup(out_file_extension='.mpileup'):

    if mglobals.original:
        fastas = mglobals.original_fastas
    else:
        fastas = mglobals.alternate_fastas

    @helpers.multiprocess(zip(mglobals.samples_list, fastas))
    def pileup_call(sample, ref_fasta):
        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        log.info('mpileup: creating .mpileup file for {} with ref fasta: {}'.format(sample, ref_fasta))
        pileup_command = ['nice', '-n', '5',
                          'samtools', 'mpileup',
                          '-B',
                          '-d10000000',
                          '-f', ref_fasta,
                          join((sample + '_thout'), 'filter.bam')]

        output_file = sample + out_file_extension
        with open(output_file, 'w') as output_file:
            helpers.sub_call(pileup_command, stdout=output_file)
        log.info('mpileup: finished for {} with ref fasta: {}'.format(sample, ref_fasta))

    pileup_call()

@helpers.log_func
def my_variant_calls(in_file_extension='.mpileup', out_file_extension='.vcf'):
    '''
    Note, build alternate fastas depends on the out_file_extension being '.vcf'.
    '''
    @helpers.multiprocess(mglobals.samples_list)
    def variant_calls_call(sample):
        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        log.info('Varscan: creating csv for: ' + sample)

        varscan_command = ['nice', '-n', '5',
                           'java', '-jar', mglobals.varscan_path,
                           'mpileup2snp',
                           (sample + in_file_extension),
                           '--min-coverage', '2',
                           '--min-avg-qual', '20',
                           '--strand-filter', '0',
                           '--p-value', '1',
                           '--min-var-freq', '1e-10',
                           '--output-vcf', '1',
                           ]

        output_file = sample + out_file_extension
        with open(output_file, 'w') as out:
            helpers.sub_call(varscan_command, stdout=out)
        log.info('varscan finished for: ' + sample)

    variant_calls_call()

@helpers.log_func
def cov_and_dgrp_filter(in_file_extension='.vcf', out_file_extension='_freeze2.vcf'):

    @helpers.multiprocess(mglobals.samples_list)
    def filter_call(sample):
        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        log.info('Filtering {0} by coverage'.format(sample))
        helpers.filter_vcf_by_coverage_cutoffs(vcf=(sample + in_file_extension),
                                               cutoff_table=mglobals.coverage_cutoffs)

        log.info('Filtering {0} according to SNP file: {1}'.format(sample, mglobals.current_snp_file))
        dgrp_intersect_command = ['nice', '-n', '5',
                                  'intersectBed',
                                  '-a', (sample + '_covfil.vcf'),  # the output of the helper
                                                                   # function above.
                                  '-b', mglobals.current_snp_file,
                                  '-wa'
                                  ]
        sample_dgrp_intersect = sample + out_file_extension
        with open(sample_dgrp_intersect, 'w') as out:
            helpers.sub_call(dgrp_intersect_command, stdout=out)

    filter_call()

@helpers.log_func
def annotate_vcf(in_file_extension='_freeze2.vcf', out_file_extension='_geneannot.vcf'):

    @helpers.multiprocess(mglobals.samples_list)
    def annotate_call(sample):
        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        log.info('Annotating ' + sample + in_file_extension + ' with ' + mglobals.current_genes_file)
        gtf_intersect_command = ['nice', '-n', '5',
                                 'intersectBed',
                                 '-a', (sample + in_file_extension),
                                 '-b', mglobals.current_genes_file,
                                 '-wa',
                                 '-wb'
                                 ]
        sample_gtf_intersect = sample + out_file_extension
        with open(sample_gtf_intersect, 'w') as out:
            helpers.sub_call(gtf_intersect_command, stdout=out)

    annotate_call()

@helpers.log_func
def build_alternate_fastas(in_file_extension='_geneannot.vcf'):
    # If we are doing the original alignment, we can now build the alternate
    # reference fastas for each sample

    @helpers.multiprocess(mglobals.samples_list)
    def build_fastas_call(sample):
        os.chdir(join(mglobals.original_path, sample))
        log.info('Beginning to build alternate fasta for: ' + sample)
        fixed_vcf = sample + '_fix.vcf'
        log.info('Removing duplicated annotations (per transcript annotations)')
        helpers.remove_dups(input_f=(sample + in_file_extension),
                            output_f=(sample + '.temp'))
        log.info('Removing duplicate alleles and adding header')
        # The fact that the original vcf was named sample.vcf is hardcoded
        # here. Be careful.
        helpers.vcf_fix(template_f=(sample + '.vcf'),
                        input_f=(sample + '.temp'),
                        output_f=fixed_vcf)
        # Delete temporary file
        os.remove(sample + '.temp')
        log.info('Creating alternate fasta')
        new_fasta = sample + '_unfixed.fa'
        helpers.sub_call(['nice', '-n', '5',
                          'java', '-Xmx2g', '-jar',
                          mglobals.gatk_path,
                          '-R', 'genome.fa',
                          '-T', 'FastaAlternateReferenceMaker',
                          '-o', new_fasta,
                          '--variant', fixed_vcf])
        # Fix the fasta
        log.info('Fixing gatk fasta')
        # If you change this name, you need to change the alternate fastas list as well.
        final_fasta = sample + '.fa'
        helpers.fasta_fix(input_f=new_fasta, output_f=final_fasta)
        # Delete the unfixed version
        os.remove(new_fasta)
        log.info('Moving new fasta to: ' + join(mglobals.alternate_path, sample))
        shutil.move(final_fasta, join(mglobals.alternate_path, sample))
        log.info('Indexing new fasta')
        os.chdir(join(mglobals.alternate_path, sample))
        helpers.sub_call(['bowtie2-build',
                          '-f', final_fasta,
                          sample])

    build_fastas_call()

@helpers.log_func
def vcf_to_csv(in_file_extension='_geneannot.vcf',
               out_file_extension='_INTER_py.csv'):

    @helpers.multiprocess(mglobals.samples_list)
    def vcf_to_csv_call(sample):
        if mglobals.original:
            os.chdir(join(mglobals.original_path, sample))
        else:
            os.chdir(join(mglobals.alternate_path, sample))

        log.info('Converting vcf to csv for: ' + sample)
        snp2gene.converter(input_f=(sample + in_file_extension),
                           output_f=(sample + out_file_extension))

    vcf_to_csv_call()

@helpers.log_func
def combine_snps(in_file_extension='_INTER_py.csv'):

    os.chdir(mglobals.samples_path)

    @helpers.multiprocess(mglobals.samples_list)
    def combine_snps_call(sample):
        log.info('Combining SNPs for: ' + sample)

        snps_combine.combine_SNPs(orig_f=join(mglobals.original_path, sample,
                                             (sample + in_file_extension)),
                                  new_f=join(mglobals.alternate_path, sample,
                                            (sample + in_file_extension)),
                                  orig_bam=join(mglobals.original_path, sample,
                                               (sample + '_thout'), 'filter.bam'),
                                  new_bam=join(mglobals.alternate_path, sample,
                                              (sample + '_thout'), 'filter.bam'),
                                  ref_vcf=join(mglobals.current_snp_file),
                                  output_f=(sample + '_snps.csv'),
                                  cutoff_table=mglobals.coverage_cutoffs)

        mean_propR, snp_count = snps_combine.quick_mean_propR(sample + '_snps.csv')
        log.info('Mean proportion reference for {} = {}'.format(sample, mean_propR))
        log.info('\tNumber of snps = {}'.format(snp_count))

    combine_snps_call()

@helpers.log_func
def csv_recalibrate(in_file_extension='_INTER_py.csv', out_file_extension='_genes.csv'):

    os.chdir(mglobals.samples_path)

    @helpers.multiprocess(mglobals.samples_list)
    def csv_recalibrate_call(sample):
        log.info('Combining genes for: ' + sample)

        snp2gene.snp2gene(input_orig=join(mglobals.original_path, sample,
                                          (sample + in_file_extension)),
                          input_new=join(mglobals.alternate_path, sample,
                                         (sample + in_file_extension)),
                          output_f=(sample + out_file_extension),
                          orig_bam=join(mglobals.original_path, sample,
                                        (sample + '_thout'), 'filter.bam'),
                          new_bam=join(mglobals.alternate_path, sample,
                                       (sample + '_thout'), 'filter.bam'),
                          ref_vcf=mglobals.current_snp_file,
                          snp_stats_f=(sample + '_snp_stats.csv'),
                          cutoff_table=mglobals.coverage_cutoffs)

    csv_recalibrate_call()

def main():

    trim()

    mglobals.original = True
    my_tophat()
    my_alignment_filter()
    my_pileup()
    my_variant_calls()
    cov_and_dgrp_filter()
    annotate_vcf()
    build_alternate_fastas()
    vcf_to_csv()

    mglobals.original = False
    my_tophat()
    my_alignment_filter()
    my_pileup()
    my_variant_calls()
    cov_and_dgrp_filter()
    annotate_vcf()
    vcf_to_csv()

    combine_snps()
    csv_recalibrate()

    log.info('Pipeline completed successfully!')

if __name__ == '__main__':
    main()


text:
#ifndef CAF_DETAIL_SPLIT_JOIN_HPP
#define CAF_DETAIL_SPLIT_JOIN_HPP

#include <vector>

#include "caf/actor.hpp"
#include "caf/locks.hpp"
#include "caf/actor_system.hpp"
#include "caf/event_based_actor.hpp"

#include "caf/detail/shared_spinlock.hpp"

namespace caf {
namespace detail {

using actor_msg_vec = std::vector<std::pair<actor, message>>;

template <class T, class Split, class Join>
class split_join_collector : public event_based_actor {
public:
  split_join_collector(actor_config& cfg, T init_value,
                       Split s, Join j, actor_msg_vec xs)
      : event_based_actor(cfg),
        workset_(std::move(xs)),
        awaited_results_(workset_.size()),
        join_(std::move(j)),
        split_(std::move(s)),
        value_(std::move(init_value)) {
    // nop
  }

  behavior make_behavior() override {
    auto f = [=](scheduled_actor*, message_view& xs) -> result<message> {
      auto msg = xs.move_content_to_message();
      auto rp = this->make_response_promise();
      split_(workset_, msg);
      for (auto& x : workset_)
        this->send(x.first, std::move(x.second));
      auto g = [=](scheduled_actor*, message_view& ys) mutable
               -> result<message> {
        auto res = ys.move_content_to_message();
        join_(value_, res);
        if (--awaited_results_ == 0) {
          rp.deliver(value_);
          quit();
        }
        return delegated<message>{};
      };
      set_default_handler(g);
      return delegated<message>{};
    };
    set_default_handler(f);
    return {
      [] {
        // nop
      }
    };
  }

private:
  actor_msg_vec workset_;
  size_t awaited_results_;
  Join join_;
  Split split_;
  T value_;
};

struct nop_split {
  inline void operator()(actor_msg_vec& xs, message& y) const {
    for (auto& x : xs) {
      x.second = y;
    }
  }
};

template <class T, class Split, class Join>
class split_join {
public:
  split_join(T init_value, Split s, Join j)
      : init_(std::move(init_value)),
        sf_(std::move(s)),
        jf_(std::move(j)) {
    // nop
  }

  void operator()(actor_system& sys,
                  upgrade_lock<detail::shared_spinlock>& ulock,
                  const std::vector<actor>& workers,
                  mailbox_element_ptr& ptr,
                  execution_unit* host) {
    if (! ptr->sender)
      return;
    actor_msg_vec xs;
    xs.reserve(workers.size());
    for (size_t i = 0; i < workers.size(); ++i)
      xs.emplace_back(workers[i], message{});
    ulock.unlock();
    using collector_t = split_join_collector<T, Split, Join>;
    auto hdl = sys.spawn<collector_t, lazy_init>(init_, sf_, jf_, std::move(xs));
    hdl->enqueue(std::move(ptr), host);
  }

private:
  T init_;
  Split sf_; // split function
  Join jf_;  // join function
};

} // namespace detail
} // namespace caf

#endif // CAF_DETAIL_SPLIT_JOIN_HPP