Example usage for java.io PrintStream println

List of usage examples for java.io PrintStream println

Introduction

In this page you can find the example usage for java.io PrintStream println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminate the line.

Usage

From source file:edu.msu.cme.rdp.alignment.errorcheck.CompareErrorType.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    options.addOption("s", "stem", true, "Output stem (default <query_nucl.fasta>)");

    final SeqReader queryReader;
    final List<Sequence> refSeqList;
    final PrintStream alignOutStream;
    final CompareErrorType errorProcessor;
    Sequence seq;/*from w ww  . j a  v  a  2 s.  c o  m*/
    Map<String, PAObject> matchMap = new HashMap();

    try {
        CommandLine line = new PosixParser().parse(options, args);

        String stem;

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

        File refFile = new File(args[0]);
        File queryFile = new File(args[1]);

        if (line.hasOption("stem")) {
            stem = line.getOptionValue("stem");
        } else {
            stem = queryFile.getName();
        }

        File alignOutFile = new File(stem + "_alignments.txt");
        File mismatchOutFile = new File(stem + "_mismatches.txt");
        File indelOutFile = new File(stem + "_indels.txt");
        File qualOutFile = null;

        refSeqList = SequenceReader.readFully(refFile);
        if (args.length == 3) {
            queryReader = new QSeqReader(queryFile, new File(args[2]));
        } else {
            queryReader = new SequenceReader(queryFile);
        }

        seq = queryReader.readNextSequence();
        if (seq instanceof QSequence) {
            qualOutFile = new File(stem + "_qual.txt");
        }

        errorProcessor = new CompareErrorType(mismatchOutFile, indelOutFile, qualOutFile);
        alignOutStream = new PrintStream(alignOutFile);

        System.err.println("Starting CompareErrorType");
        System.err.println("*  Time:              " + new Date());
        System.err.println("*  Reference File:    " + refFile);
        System.err.println("*  Query File:        " + queryFile);
        if (args.length == 3) {
            System.err.println("*  Qual File:         " + args[2]);
        }
        System.err.println("*  Query format:      " + queryReader.getFormat());
        System.err.println("*  Alignment Output:  " + alignOutFile);
        System.err.println("*  Mismatches Output: " + mismatchOutFile);
        System.err.println("*  Alignment Output:  " + indelOutFile);
        if (qualOutFile != null) {
            System.err.println("*  Quality Output:    " + qualOutFile);
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp(
                "CompareErrorType [options] <ref_nucl> (<query_nucl> | <query_nucl.fasta> <query_nucl.qual>)",
                options);
        System.err.println("ERROR: " + e.getMessage());
        throw new RuntimeException(e);
        //System.exit(1);
        //return;
    }

    //ScoringMatrix scoringMatrix = ScoringMatrix.getDefaultNuclMatrix();
    // use a simple scoring function, match score 0, mismatch -1, gap opening -1, gap extension -1.
    ScoringMatrix scoringMatrix = new ScoringMatrix(
            ScoringMatrix.class.getResourceAsStream("/data/simple_scoringmatrix.txt"), -1, -1);

    do {
        try {
            PairwiseAlignment bestResult = null;
            Sequence bestSeq = null;
            boolean bestReversed = false;
            String querySeqStr = seq.getSeqString().toLowerCase();
            String reversedQuery = IUBUtilities.reverseComplement(querySeqStr);
            PAObject bestMatch = null;

            //checking if sequence has been seen before
            if (matchMap.containsKey(seq.getSeqString())) {
                bestMatch = matchMap.get(seq.getSeqString());
            } else {
                for (Sequence refSeq : refSeqList) {
                    String refSeqStr = refSeq.getSeqString().toLowerCase();
                    PairwiseAlignment result = PairwiseAligner.align(refSeqStr, querySeqStr, scoringMatrix,
                            AlignmentMode.global);
                    PairwiseAlignment reversedResult = PairwiseAligner.align(refSeqStr,
                            IUBUtilities.reverseComplement(querySeqStr), scoringMatrix, AlignmentMode.global);

                    PairwiseAlignment currBest = (result.getScore() > reversedResult.getScore()) ? result
                            : reversedResult;

                    if (bestResult == null || currBest.getScore() > bestResult.getScore()) {
                        bestResult = currBest;
                        bestSeq = refSeq;
                        if (currBest == reversedResult) {
                            bestReversed = true;
                        } else {
                            bestReversed = false;
                        }

                    }

                    //Since this is a new sequence, make a new PAObject to put into the map to compare against later
                    bestMatch = new PAObject(bestResult, bestReversed, bestSeq);
                    matchMap.put(seq.getSeqString(), bestMatch);
                }
            }
            int refStart = bestMatch.getPA().getStarti();
            int refEnd = bestMatch.getPA().getEndi();
            bestSeq = bestMatch.getRefSeq();
            bestReversed = bestMatch.getReversed();
            bestResult = bestMatch.getPA();

            //output information
            alignOutStream.println(">\t" + seq.getSeqName() + "\t" + bestSeq.getSeqName() + "\t"
                    + seq.getSeqString().length() + "\t" + refStart + "\t" + refEnd + "\t"
                    + bestResult.getScore() + "\t" + ((bestReversed) ? "\treversed" : ""));
            alignOutStream.println(bestResult.getAlignedSeqj() + "\n");
            alignOutStream.println(bestResult.getAlignedSeqi() + "\n");

            //seqi is reference seq, seqj is the refseq
            errorProcessor.processSequence(seq, bestResult.getAlignedSeqj(), bestSeq.getSeqName(),
                    bestResult.getAlignedSeqi(), refStart, bestReversed);

        } catch (Exception e) {
            throw new RuntimeException("Failed while processing seq " + seq.getSeqName(), e);
        }
    } while ((seq = queryReader.readNextSequence()) != null);
    queryReader.close();
    alignOutStream.close();
    errorProcessor.close();
}

From source file:Main.java

public static void saveFile(final String fileName, final String str) {
    try {/*  www .j  a  va  2  s.  com*/
        File f = new File(fileName);
        if (new File(f.getParent()).exists() == false) {
            f.getParentFile().mkdirs();
        }
        f.createNewFile();
        PrintStream p = new PrintStream(new FileOutputStream(f, false));
        p.println(str);
        p.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(fileName);
    }
}

From source file:Main.java

public static void htmlLineBreak(java.io.PrintStream stream) {
    stream.println("<BR>");
}

From source file:Main.java

public static void append(File aFile, String content) {
    try {//from  www.ja  v a  2s.co m
        PrintStream p = new PrintStream(new BufferedOutputStream(new FileOutputStream(aFile, true)));
        p.println(content);
        p.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(aFile);
    }
}

From source file:Main.java

public static void printStackTrace(StackTraceElement[] trace, PrintStream out) {
    for (StackTraceElement el : trace)
        out.println(el.toString());
}

From source file:VarArgsDemo.java

static void process(PrintStream out, int... args) {
    for (int i = 0; i < args.length; i++) {
        out.println("Argument " + i + " is " + args[i]);
    }//from  ww  w .  ja  v  a  2  s .  c  om
}

From source file:com.aliyun.openservices.odps.console.pub.WhoamiCommand.java

public static void printUsage(PrintStream stream) {
    stream.println("Usage: whoami");
}

From source file:Main.java

/**
 * Prints a sentence to a stream. It expect a string array with tokens.
 * /*w  ww .  j  a v  a 2  s  . c o  m*/
 * Each token will be one line and after all tokens are printed there will be one empty line marking the ending of sentence.
 * @param inTokens a string array with tokens
 * @param stream a print stream
 */
public static void printTokens(String[] inTokens, PrintStream stream) {
    for (int i = 0; i < inTokens.length; i++) {
        stream.println(inTokens[i]);
    }
    stream.println();
}

From source file:Main.java

public static void htmlWriteJavascript(java.io.PrintStream stream, String js) {
    {/*from w w w . j a v a  2s. co  m*/
        stream.println("<SCRIPT LANGUAGE=\"JAVASCRIPT\"><!-- Hide from old browsers");
        stream.println(js);
        stream.println("// end hiding from old browsers -->");
        stream.println("</SCRIPT>");
    }
    ;
    return;
}

From source file:com.difference.historybook.importer.crawler.Crawler.java

private static HistoryRecord printUrl(HistoryRecord record, PrintStream output) {
    output.println(record.getUrl());
    return record;
}