Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

In this page you can find the example usage for java.lang RuntimeException RuntimeException.

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.diversityarrays.dal.server.DalServer.java

public static void main(String[] args) {

    String host = null;//www  . j a va2 s. c om
    int port = DalServerUtil.DEFAULT_DAL_SERVER_PORT;

    int inactiveMins = DalServerUtil.DEFAULT_MAX_INACTIVE_MINUTES;

    File docRoot = null;

    String serviceName = null;

    for (int i = 0; i < args.length; ++i) {
        String argi = args[i];
        if (argi.startsWith("-")) {
            if ("--".equals(argi)) {
                break;
            }

            if ("-version".equals(argi)) {
                System.out.println(DAL_SERVER_VERSION);
                System.exit(0);
            }

            if ("-help".equals(argi)) {
                giveHelpThenExit(0);
            }

            if ("-docroot".equals(argi)) {
                if (++i >= args.length || args[i].startsWith("-")) {
                    fatal("missing value for " + argi);
                }
                docRoot = new File(args[i]);
            } else if ("-sqllog".equals(argi)) {
                SqlUtil.logger = Logger.getLogger(SqlUtil.class.getName());
            } else if ("-expire".equals(argi)) {
                if (++i >= args.length || args[i].startsWith("-")) {
                    fatal("missing value for " + argi);
                }

                try {
                    inactiveMins = Integer.parseInt(args[i], 10);
                    if (inactiveMins <= 0) {
                        fatal("invalid minutes: " + args[i]);
                    }
                } catch (NumberFormatException e) {
                    fatal("invalid minutes: " + args[i]);
                }
            } else if ("-localhost".equals(argi)) {
                host = "localhost";
            } else if ("-port".equals(argi)) {
                if (++i >= args.length || args[i].startsWith("-")) {
                    fatal("missing value for " + argi);
                }
                try {
                    port = Integer.parseInt(args[i], 10);
                    if (port < 0 || port > 65535) {
                        fatal("invalid port number: " + args[i]);
                    }
                } catch (NumberFormatException e) {
                    fatal("invalid port number: " + args[i]);
                }
            } else {
                fatal("invalid option: " + argi);
            }
        } else {
            if (serviceName != null) {
                fatal("multiple serviceNames not supported: " + argi);
            }
            serviceName = argi;
        }
    }

    final DalServerPreferences preferences = new DalServerPreferences(
            Preferences.userNodeForPackage(DalServer.class));

    if (docRoot == null) {
        docRoot = preferences.getWebRoot(new File(System.getProperty("user.dir"), "www"));
    }

    DalServer server = null;

    if (serviceName != null && docRoot.isDirectory()) {
        try {
            DalDatabase db = createDalDatabase(serviceName, preferences);
            if (db.isInitialiseRequired()) {
                Closure<String> progress = new Closure<String>() {
                    @Override
                    public void execute(String msg) {
                        System.out.println("Database Initialisation: " + msg);
                    }
                };
                db.initialise(progress);
            }
            server = create(preferences, host, port, docRoot, db);
        } catch (NoServiceException e) {
            throw new RuntimeException(e);
        } catch (DalDbException e) {
            throw new RuntimeException(e);
        }
    }

    Image serverIconImage = null;
    InputStream imageIs = DalServer.class.getResourceAsStream("dalserver-24.png");
    if (imageIs != null) {
        try {
            serverIconImage = ImageIO.read(imageIs);

            if (Util.isMacOS()) {
                try {
                    MacApplication macapp = new MacApplication(null);
                    macapp.setDockIconImage(serverIconImage);
                } catch (MacApplicationException e) {
                    System.err.println(e.getMessage());
                }
            }

        } catch (IOException ignore) {
        }
    }

    if (server != null) {
        server.setMaxInactiveMinutes(inactiveMins);
    } else {
        AskServerParams asker = new AskServerParams(serverIconImage, null, "DAL Server Start", docRoot,
                preferences);
        GuiUtil.centreOnScreen(asker);
        asker.setVisible(true);

        if (asker.cancelled) {
            System.exit(0);
        }

        host = asker.dalServerHostName;
        port = asker.dalServerPort;
        inactiveMins = asker.maxInactiveMinutes;

        server = create(preferences, host, port, asker.wwwRoot, asker.dalDatabase);
        // server.setUseSimpleDatabase(asker.useSimpleDatabase);
    }

    final DalServer f_server = server;
    final File f_wwwRoot = docRoot;
    final Image f_serverIconImage = serverIconImage;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            DalServerFactory factory = new DalServerFactory() {
                @Override
                public DalServer create(String hostName, int port, File wwwRoot, DalDatabase dalDatabase) {
                    return DalServer.create(preferences, hostName, port, wwwRoot, dalDatabase);
                }
            };
            ServerGui gui = new ServerGui(f_serverIconImage, f_server, factory, f_wwwRoot, preferences);
            gui.setVisible(true);
        }
    });

}

From source file:edu.msu.cme.rdp.graph.utils.ContigMerger.java

public static void main(String[] args) throws IOException {
    final BufferedReader hmmgsResultReader;
    final IndexedSeqReader nuclContigReader;
    final double minBits;
    final int minProtLength;
    final Options options = new Options();
    final PrintStream out;
    final ProfileHMM hmm;
    final FastaWriter protSeqOut;
    final FastaWriter nuclSeqOut;
    final boolean prot;
    final boolean all;
    final String shortSampleName;

    options.addOption("a", "all", false,
            "Generate all combinations for multiple paths, instead of just the best");
    options.addOption("b", "min-bits", true, "Minimum bits score");
    options.addOption("l", "min-length", true, "Minimum length");
    options.addOption("s", "short_samplename", true,
            "short sample name, to be used as part of contig identifiers. This allow analyzing contigs together from different samples in downstream analysis ");
    options.addOption("o", "out", true, "Write output to file instead of stdout");

    try {//from   w  w  w  .j a  va 2 s  .c  o  m
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("min-bits")) {
            minBits = Double.valueOf(line.getOptionValue("min-bits"));
        } else {
            minBits = Double.NEGATIVE_INFINITY;
        }

        if (line.hasOption("min-length")) {
            minProtLength = Integer.valueOf(line.getOptionValue("min-length"));
        } else {
            minProtLength = 0;
        }

        if (line.hasOption("short_samplename")) {
            shortSampleName = line.getOptionValue("short_samplename") + "_";
        } else {
            shortSampleName = "";
        }

        if (line.hasOption("out")) {
            out = new PrintStream(line.getOptionValue("out"));
        } else {
            out = System.err;
        }

        all = line.hasOption("all");

        args = line.getArgs();

        if (args.length != 3) {
            throw new Exception("Unexpected number of arguments");
        }

        hmmgsResultReader = new BufferedReader(new FileReader(new File(args[1])));
        nuclContigReader = new IndexedSeqReader(new File(args[2]));
        hmm = HMMER3bParser.readModel(new File(args[0]));

        prot = (hmm.getAlphabet() == SequenceType.Protein);

        if (prot) {
            protSeqOut = new FastaWriter(new File("prot_merged.fasta"));
        } else {
            protSeqOut = null;
        }
        nuclSeqOut = new FastaWriter(new File("nucl_merged.fasta"));

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: ContigMerger [options] <hmm> <hmmgs_file> <nucl_contig>",
                options);
        System.err.println("Error: " + e.getMessage());
        System.exit(1);
        throw new RuntimeException("I hate you javac");
    }

    String line;
    SearchDirection lastDir = SearchDirection.left; //So this has an assumption built in
    //It depends on hmmgs always outputting left fragments, then right
    //We can't just use the kmer to figure out if we've switched to another starting point
    //because we allow multiple starting model pos, so two different starting
    //positions can have the same starting kmer

    Map<String, Sequence> leftContigs = new HashMap();
    Map<String, Sequence> rightContigs = new HashMap();

    int contigsMerged = 0;
    int writtenMerges = 0;
    long startTime = System.currentTimeMillis();
    String kmer = null;
    String geneName = null;

    while ((line = hmmgsResultReader.readLine()) != null) {
        if (line.startsWith("#")) {
            continue;
        }

        String[] lexemes = line.trim().split("\t");
        if (lexemes.length != 12 || lexemes[0].equals("-")) {
            System.err.println("Skipping line: " + line);
            continue;
        }
        //contig_53493   nirk   1500:6:35:16409:3561/1   ADV15048   tcggcgctctacacgttcctgcagcccggg   40   210   70   left   -44.692   184   0
        int index = 0;

        String seqid = lexemes[0];
        geneName = lexemes[1];
        String readid = lexemes[2];
        String refid = lexemes[3];
        kmer = lexemes[4];
        int modelStart = Integer.valueOf(lexemes[5]);

        int nuclLength = Integer.valueOf(lexemes[6]);
        int protLength = Integer.valueOf(lexemes[7]);

        SearchDirection dir = SearchDirection.valueOf(lexemes[8]);
        if (dir != lastDir) {
            if (dir == SearchDirection.left) {
                List<MergedContig> mergedContigs = all
                        ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm)
                        : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm);

                contigsMerged++;

                for (MergedContig mc : mergedContigs) {
                    String mergedId = shortSampleName + geneName + "_" + mc.leftContig + "_" + mc.rightContig;
                    out.println(mergedId + "\t" + mc.length + "\t" + mc.score);

                    if (mc.score > minBits && mc.length > minProtLength) {
                        if (prot) {
                            protSeqOut.writeSeq(mergedId, mc.protSeq);
                        }
                        nuclSeqOut.writeSeq(mergedId, mc.nuclSeq);

                        writtenMerges++;
                    }
                }
                leftContigs.clear();
                rightContigs.clear();
            }

            lastDir = dir;
        }

        Sequence seq = nuclContigReader.readSeq(seqid);

        if (dir == SearchDirection.left) {
            leftContigs.put(seqid, seq);
        } else if (dir == SearchDirection.right) {
            rightContigs.put(seqid, seq);
        } else {
            throw new IOException("Cannot handle search direction " + dir);
        }
    }

    if (!leftContigs.isEmpty() || !rightContigs.isEmpty()) {
        List<MergedContig> mergedContigs = all ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm)
                : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm);

        for (MergedContig mc : mergedContigs) {
            String mergedId = shortSampleName + mc.gene + "_" + mc.leftContig + "_" + mc.rightContig;
            out.println(mergedId + "\t" + mc.length + "\t" + mc.score);
            contigsMerged++;

            if (mc.score > minBits && mc.length > minProtLength) {
                if (prot) {
                    protSeqOut.writeSeq(mergedId, mc.protSeq);
                }
                nuclSeqOut.writeSeq(mergedId, mc.nuclSeq);
                writtenMerges++;
            }
        }
    }

    out.close();
    if (prot) {
        protSeqOut.close();
    }
    nuclSeqOut.close();

    System.err.println("Read in " + contigsMerged + " contigs, wrote out " + writtenMerges
            + " merged contigs in " + ((double) (System.currentTimeMillis() - startTime) / 1000) + "s");
}

From source file:Main.java

public static boolean isETC1Supported() {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static final void throwInternal() {
    throw new RuntimeException("Internal error: this code path should never get executed");
}

From source file:Main.java

public static <T> T[] arrayOf(T... views) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static long currentAnimationTimeMillis() {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static final boolean isNonSeparator(char c) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static int toaFromString(java.lang.String s) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static final boolean isStartsPostDial(char c) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static final boolean isReallyDialable(char c) {
    throw new RuntimeException("Stub!");
}