Package com.yahoo.labs.taxomo

Source Code of com.yahoo.labs.taxomo.GenerateSequences

/*
* Copyright (c) 2011, Yahoo! Inc. All rights reserved.
*
* Redistribution and use of this software in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission of Yahoo!
* Inc.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.yahoo.labs.taxomo;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.martiansoftware.jsap.FlaggedOption;
import com.martiansoftware.jsap.JSAP;
import com.martiansoftware.jsap.JSAPException;
import com.martiansoftware.jsap.JSAPResult;
import com.martiansoftware.jsap.Parameter;
import com.martiansoftware.jsap.SimpleJSAP;
import com.martiansoftware.jsap.Switch;
import com.yahoo.labs.taxomo.util.StateSet;
import com.yahoo.labs.taxomo.util.Taxonomy;
import com.yahoo.labs.taxomo.util.Util;

/**
* Generates sequences given a model.
* <p>
* See <tt>--help</tt> for command-line options.
* @author chato
*
*/
public class GenerateSequences {

  static final Logger logger = Logger.getLogger(GenerateSequences.class);
  static {
    Util.configureLogger(logger, Level.INFO);
  }
 
  private static final int DEFAULT_SEQUENCES = 10;
 
  /**
   * @param args
   * @throws IOException
   * @throws JSAPException
   */
  public static void main(String[] args) throws IOException, JSAPException {
   
    final SimpleJSAP jsap = new SimpleJSAP(
        GenerateSequences.class.getName(),
        "Generates sequences given a HMM.",
        new Parameter[] {
            new Switch("verbose", 'v', "verbose", "Set the verbose output"),
            new FlaggedOption("num-sequences", JSAP.INTEGER_PARSER, Integer.toString(DEFAULT_SEQUENCES), JSAP.NOT_REQUIRED, 'n', "num-sequences",
            "Number of sequences to generate."),
            new FlaggedOption("model-file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'm', "model-file",
                "File containing the description of the HMM."),
            new FlaggedOption("taxonomy-file", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 't', "taxonomy-file",
                "File containing the taxonomy."),
    });
   
    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
      return;
    if (jsapResult.getBoolean("verbose")) {
      logger.setLevel(Level.DEBUG);
    }
   
    File modelFile = new File(jsapResult.getString("model-file"));
    File taxoFile = new File(jsapResult.getString("taxonomy-file"));
    int numSequences = jsapResult.getInt("num-sequences");
   
    StateSet taxo = new StateSet( modelFile, new Taxonomy(taxoFile) );
    Model hmm = new Model(modelFile, taxo);
   
    for( int i=0; i<numSequences; i++) {
      ArrayList<String> seq = hmm.sequence();
      System.out.println(seq2str(seq));
    }

  }
 
  private static String seq2str( ArrayList<String> seq ) {
    StringBuffer sb = new StringBuffer();
    for( int i=0; i<seq.size(); i++ ) {
      if( i > 0 ) {
        sb.append( " " );
      }
      sb.append( seq.get(i) );
    }
    return sb.toString();
  }

}
TOP

Related Classes of com.yahoo.labs.taxomo.GenerateSequences

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.