View Javadoc

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  // Sam2Wig.java
20  // Since: 2010/09/28
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.shell;
26  
27  import java.io.BufferedWriter;
28  import java.io.File;
29  import java.io.FileWriter;
30  import java.io.OutputStreamWriter;
31  import java.io.Writer;
32  
33  import org.utgenome.format.sam.Sam2WigConverter;
34  import org.xerial.util.opt.Argument;
35  
36  public class Sam2Wig extends UTGBShellCommand {
37  
38  	@Argument(index = 0, name = "input", required = false)
39  	File input = null;
40  	@Argument(index = 1, name = "output", required = false)
41  	String output = "-";
42  
43  	@Override
44  	public void execute(String[] args) throws Exception {
45  
46  		Sam2WigConverter converter = new Sam2WigConverter();
47  
48  		Writer out = "-".equals(output) ? new OutputStreamWriter(System.out) : new BufferedWriter(new FileWriter(output));
49  
50  		try {
51  			converter.convert(input, out);
52  		}
53  		finally {
54  			out.close();
55  		}
56  	}
57  
58  	@Override
59  	public String name() {
60  		return "readdepth";
61  	}
62  
63  	@Override
64  	public String getOneLinerDescription() {
65  		return "create a WIG file (coverage depth) from a given BAM (with BAI) file";
66  	}
67  
68  }