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  // Pack.java
20  // Since: Mar 15, 2010
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.shell;
26  
27  import java.net.URL;
28  import java.util.regex.Pattern;
29  
30  import org.utgenome.UTGBException;
31  import org.utgenome.format.fasta.CompactFASTAGenerator;
32  import org.xerial.util.StopWatch;
33  import org.xerial.util.log.Logger;
34  import org.xerial.util.opt.Argument;
35  import org.xerial.util.opt.Option;
36  
37  /**
38   * creating packed FASTA
39   * 
40   * @author leo
41   * 
42   */
43  public class Pack extends UTGBShellCommand {
44  
45  	private static Logger _logger = Logger.getLogger(Pack.class);
46  
47  	@Argument(index = 0)
48  	private String inputFile = null;
49  
50  	@Option(symbol = "o", description = "output directory. default = db")
51  	private String outputDir = "db";
52  
53  	@Override
54  	public void execute(String[] args) throws Exception {
55  
56  		if (inputFile == null)
57  			throw new UTGBException("missing an input file");
58  
59  		_logger.info("input file: " + inputFile);
60  		_logger.info("output dir: " + outputDir);
61  
62  		StopWatch sw = new StopWatch();
63  		CompactFASTAGenerator g = new CompactFASTAGenerator();
64  		g.setWorkDir(outputDir);
65  		// is protocol?
66  		if (Pattern.matches("^\\w+:\\/.*", inputFile)) {
67  			g.packFASTA(new URL(inputFile));
68  		}
69  		else
70  			g.packFASTA(inputFile);
71  
72  		_logger.info(String.format("elapsed time %s sec.", sw.getElapsedTime()));
73  	}
74  
75  	@Override
76  	public String getOneLinerDescription() {
77  		return "create a pack file of the input FASTA sequences";
78  	}
79  
80  	@Override
81  	public String name() {
82  		return "pack";
83  	}
84  
85  }