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

org.geneweaver.io.connector.BedConnector Maven / Gradle / Ivy

There is a newer version: 2.7.12
Show newest version
/*-
 * 
 * Copyright 2018, 2020  The Jackson Laboratory Inc.
 *
 * 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.
 * 
 * @author Matthew Gerring
 */
package org.geneweaver.io.connector;

import java.io.PrintStream;
import java.util.function.Function;
import java.util.stream.Stream;

import org.geneweaver.domain.Entity;
import org.geneweaver.domain.NamedEntity;
import org.geneweaver.domain.Peak;
import org.geneweaver.domain.Track;
import org.geneweaver.domain.Tracked;
import org.neo4j.ogm.session.Session;

/**
 * 
 * Connects tracks with regions. This connector is *not* thread safe
 * and cannot be used parallel.
 * 
 * @author gerrim
 *
 */
public class BedConnector implements Connector, Function> {
	
	
	private Track currentTrack;

	/**
	 * @param session, not required.
	 */
	@Override
	public Stream stream(N bean, Session session, PrintStream log) {
		return apply(bean);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Stream apply(N bean) {
		String name = bean.getName();
		if (bean instanceof Track && (name==null || name.isEmpty())) {
			throw new ConnectorException("Tracks must have a name!");
		}
        if (bean instanceof Track) {
        	currentTrack = (Track)bean;
        	return (Stream) Stream.of(bean);
        	
        } else if (bean instanceof Peak) {
        	
        	if (currentTrack!=null) {
        		return (Stream)Stream.of(bean, new Tracked((Peak)bean, currentTrack));
        	} else {
        		return (Stream)Stream.of(bean);
        	}
        }
        
        throw new ConnectorException(getClass().getSimpleName()+" may not be used with "+bean.getClass().getSimpleName());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy