1 /*-------------------------------------------------------------------------- 2 * Copyright 2008 utgenome.org 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 *--------------------------------------------------------------------------*/ 16 //-------------------------------------- 17 // utgb-shell Project 18 // 19 // BED2SilkReader.java 20 // Since: May 26, 2009 21 // 22 // $URL: http://svn.utgenome.org/utgb/trunk/utgb/utgb-shell/src/main/java/org/utgenome/shell/db/bed/BED2SilkReader.java $ 23 // $Author: leo $ 24 //-------------------------------------- 25 package org.utgenome.format.bed; 26 27 import java.io.IOException; 28 import java.io.PrintWriter; 29 import java.io.Reader; 30 import java.io.Writer; 31 32 import org.utgenome.UTGBException; 33 import org.utgenome.format.FormatConversionReader; 34 import org.xerial.lens.SilkLens; 35 36 /** 37 * BED2SilkReader read the input BED data, and the user can read it as if it were a Silk format. 38 * 39 * @author leo 40 * 41 */ 42 public class BED2SilkReader extends FormatConversionReader { 43 44 public BED2SilkReader(Reader bedReader) throws IOException { 45 super(bedReader, new PipeConsumer() { 46 @Override 47 public void consume(Reader in, Writer out) throws Exception { 48 BED2Silk converter = new BED2Silk(in); 49 PrintWriter pout = new PrintWriter(out); 50 converter.toSilk(pout); 51 } 52 }); 53 54 } 55 56 /** 57 * Read an input BED data, and retrieves {@link BEDTrack} and {@link BEDEntry} information through the 58 * {@link BEDQuery} interface. 59 * 60 * @param input 61 * @param query 62 * @return 63 * @throws UTGBException 64 */ 65 public static BEDQuery scan(Reader input, BEDQuery query) throws UTGBException { 66 67 try { 68 BED2SilkReader in = new BED2SilkReader(input); 69 SilkLens.loadSilk(query, in); 70 return query; 71 } 72 catch (Exception e) { 73 throw UTGBException.convert(e); 74 } 75 } 76 77 }