All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.heuermh.adam.plugins.JavaADAMPlugin Maven / Gradle / Ivy

There is a newer version: 0.16.0
Show newest version
/**
 * Copyright 2014 held jointly by the individual authors.
 *
 * 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 com.github.heuermh.adam.plugins;

import org.apache.avro.Schema;

import org.apache.spark.SparkContext;

import org.apache.spark.rdd.RDD;

import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;

import org.bdgenomics.adam.apis.java.JavaADAMContext;

import org.bdgenomics.adam.plugins.ADAMPlugin;

import scala.Function1;
import scala.Option;

/**
 * Java ADAM plugin.
 *
 * @param  input RDD type
 * @param  output RDD type
 * @author  Michael Heuer
 */
public abstract class JavaADAMPlugin implements ADAMPlugin {
    private final Option projection;
    // todo:  would be nice if this were org.apache.spark.api.java.function.Function instead
    private final Option> predicate;

    protected JavaADAMPlugin() {
        this.projection = Option.empty();
        this.predicate = Option.empty();
    }

    protected JavaADAMPlugin(final Option projection,
                             final Option> predicate) {
        if (projection == null) {
            throw new NullPointerException("projection must not be null");
        }
        if (predicate == null) {
            throw new NullPointerException("predicate must not be null");
        }
        this.projection = projection;
        this.predicate = predicate;
    }

    @Override
    public final Option projection() {
        return projection;
    }

    @Override
    public final Option> predicate() {
        return predicate;
    }

    @Override
    public final RDD run(final SparkContext sparkContext, final RDD recs, final String args) {
        // todo:  is fromRDD(.., null) valid?
        return run(new JavaADAMContext(sparkContext), JavaRDD.fromRDD(recs, null), args).rdd();
    }

    protected abstract JavaRDD run(JavaADAMContext ac, JavaRDD recs, String args);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy