Search in sources :

Example 6 with Config

use of coloring.Config in project ASCIIGenome by dariober.

the class TrackTest method canPrintVcfWithClippedSeq.

@Test
public void canPrintVcfWithClippedSeq() throws InvalidGenomicCoordsException, IOException, InvalidColourException, InvalidCommandLineException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidConfigException {
    new Config(null);
    GenomicCoords gc = new GenomicCoords("1:1019492-1019672", 160, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature("test_data/ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf", gc);
    tif.setNoFormat(true);
    tif.setPrintMode(PrintRawLine.CLIP);
    assertTrue(tif.printLines().contains(" GTCAC["));
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Config(coloring.Config) Test(org.junit.Test)

Example 7 with Config

use of coloring.Config in project ASCIIGenome by dariober.

the class InteractiveInput method setConfigOpt.

private void setConfigOpt(List<String> cmdTokens) throws IOException, InvalidConfigException, InvalidCommandLineException, InvalidColourException {
    List<String> args = new ArrayList<String>(cmdTokens);
    args.remove(0);
    if (args.size() == 0) {
        throw new InvalidCommandLineException();
    }
    if (args.size() == 1) {
        ConfigKey key = ConfigKey.getConfigKeyFromShort(args.get(0));
        if (ConfigKey.booleanKeys().contains(key)) {
            // If configkey is a type boolean, just flip the boolean
            key = ConfigKey.valueOf(key.toString());
            boolean value = !Utils.asBoolean(Config.get(key));
            Config.set(key, String.valueOf(value));
        } else {
            // configKey is expected to be the name of a configuration file
            new Config(args.get(0));
        }
    } else {
        ConfigKey key = ConfigKey.getConfigKeyFromShort(args.get(0));
        String value = args.get(1);
        try {
            Config.set(key, value);
        } catch (Exception e) {
            throw new InvalidConfigException();
        }
    }
}
Also used : ConfigKey(coloring.ConfigKey) Config(coloring.Config) ArrayList(java.util.ArrayList) InvalidCommandLineException(exceptions.InvalidCommandLineException) InvalidConfigException(exceptions.InvalidConfigException) InvalidCommandLineException(exceptions.InvalidCommandLineException) InvalidColourException(exceptions.InvalidColourException) InvalidRecordException(exceptions.InvalidRecordException) SQLException(java.sql.SQLException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) InvalidConfigException(exceptions.InvalidConfigException) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) InvalidGenomicCoordsException(exceptions.InvalidGenomicCoordsException)

Example 8 with Config

use of coloring.Config in project ASCIIGenome by dariober.

the class Main method main.

public static void main(String[] args) throws IOException, InvalidGenomicCoordsException, InvalidCommandLineException, InvalidRecordException, BamIndexNotFoundException, ClassNotFoundException, SQLException, DocumentException, UnindexableFastaFileException, InvalidColourException, InvalidConfigException {
    /* Start parsing arguments * 
		 * *** If you change something here change also in console input ***/
    Namespace opts = ArgParse.argParse(args);
    List<String> initFileList = opts.getList("input");
    String region = opts.getString("region");
    final String fasta = opts.getString("fasta");
    String exec = opts.getString("exec");
    String config = opts.getString("config");
    exec = parseExec(exec);
    int debug = opts.getInt("debug");
    // Get configuration. Note that we don't need to assign this to a variable.
    new Config(config);
    new Xterm256();
    ASCIIGenomeHistory asciiGenomeHistory = new ASCIIGenomeHistory();
    // Init console right at start so if something goes wrong the user's terminal is reset to
    // initial defaults with the shutdown hook. This could be achieved in cleaner way probably.
    ConsoleReader console = initConsole();
    messageVersion(opts.getBoolean("noFormat"));
    /* Set up console */
    Utils.checkFasta(fasta, debug);
    /* Test input files exist */
    List<String> inputFileList = new ArrayList<String>();
    Utils.addSourceName(inputFileList, initFileList, debug);
    if (region == null || region.isEmpty()) {
        region = initRegion(inputFileList, fasta, null, debug);
    }
    int terminalWidth = Utils.getTerminalWidth();
    GenomicCoords initGc = new GenomicCoords(region, terminalWidth, null, null);
    List<String> initGenomeList = new ArrayList<String>();
    for (String x : inputFileList) {
        initGenomeList.add(x);
    }
    initGenomeList.add(fasta);
    initGc.setGenome(initGenomeList, false);
    // ----------------------------
    // Genomic positions start here:
    final GenomicCoordsHistory gch = new GenomicCoordsHistory();
    GenomicCoords start = new GenomicCoords(initGc.toStringRegion(), terminalWidth, initGc.getSamSeqDict(), initGc.getFastaFile());
    gch.readHistory(asciiGenomeHistory.getFileName(), start);
    gch.add(start);
    final TrackSet trackSet = new TrackSet(inputFileList, gch.current());
    trackSet.addHistoryFiles(asciiGenomeHistory.getFiles());
    setDefaultTrackHeights(console.getTerminal().getHeight(), trackSet.getTrackList());
    final TrackProcessor proc = new TrackProcessor(trackSet, gch);
    proc.setShowMem(opts.getBoolean("showMem"));
    proc.setShowTime(opts.getBoolean("showTime"));
    proc.setNoFormat(opts.getBoolean("noFormat"));
    // Put here the previous command so that it is re-issued if no input is given
    // You have to initialize this var outside the while loop that processes input files.
    String currentCmdConcatInput = "";
    if (!proc.isNoFormat()) {
        String str = String.format("\033[48;5;%sm", Config.get256Color(ConfigKey.background));
        System.out.print(str);
    }
    // Batch processing file of regions
    final String batchFile = opts.getString("batchFile");
    if (batchFile != null && !batchFile.isEmpty()) {
        console.clearScreen();
        console.flush();
        BufferedReader br = batchFileReader(batchFile);
        String line = null;
        while ((line = br.readLine()) != null) {
            // Start processing intervals one by one
            IntervalFeature target = new IntervalFeature(line, TrackFormat.BED, null);
            String reg = target.getChrom() + ":" + target.getFrom() + "-" + target.getTo();
            String gotoAndExec = ("goto " + reg + " && " + exec).trim().replaceAll("&&$", "");
            InteractiveInput itr = new InteractiveInput(console);
            itr.processInput(gotoAndExec, proc, debug);
            if (itr.getInteractiveInputExitCode().equals(ExitCode.ERROR)) {
                System.err.println("Error processing '" + gotoAndExec + "' at line '" + line + "'");
                System.exit(1);
            }
        }
        br.close();
        return;
    }
    // See if we need to process the exec arg before going to interactive mode.
    // Also if we are in non-interactive mode, we process the track set now and later exit
    console.clearScreen();
    console.flush();
    proc.iterateTracks();
    if (!exec.isEmpty() || opts.getBoolean("nonInteractive")) {
        InteractiveInput itr = new InteractiveInput(console);
        itr.processInput(exec, proc, debug);
        if (opts.getBoolean("nonInteractive")) {
            System.out.print("\033[0m");
            return;
        }
    }
    /* Set up done, start processing */
    /* ============================= */
    console.setHistory(asciiGenomeHistory.getCommandHistory());
    writeYamlHistory(asciiGenomeHistory, console.getHistory(), trackSet, gch);
    while (true) {
        // keep going until quit or if no interactive input set
        // *** START processing interactive input
        // String like "zi && -F 16 && mapq 10"
        String cmdConcatInput = "";
        InteractiveInput interactiveInput = new InteractiveInput(console);
        ExitCode currentExitCode = ExitCode.NULL;
        interactiveInput.setInteractiveInputExitCode(currentExitCode);
        while (!interactiveInput.getInteractiveInputExitCode().equals(ExitCode.ERROR) || interactiveInput.getInteractiveInputExitCode().equals(ExitCode.NULL)) {
            console.setPrompt(StringUtils.repeat(' ', proc.getWindowSize()) + '\r' + "[h] for help: ");
            cmdConcatInput = console.readLine().trim();
            if (cmdConcatInput.isEmpty()) {
                // Empty input: User only issued <ENTER>
                if (interactiveInput.getInteractiveInputExitCode().equals(ExitCode.CLEAN)) {
                    // User only issued <ENTER>: Repeat previous command if the exit code was not an error.
                    cmdConcatInput = currentCmdConcatInput;
                } else {
                    // Refresh screen if the exit code was not CLEAN.
                    cmdConcatInput = "+0";
                }
            }
            interactiveInput.processInput(cmdConcatInput, proc, debug);
            currentCmdConcatInput = cmdConcatInput;
        }
    // *** END processing interactive input
    }
}
Also used : Xterm256(coloring.Xterm256) TrackSet(tracks.TrackSet) ConsoleReader(jline.console.ConsoleReader) Config(coloring.Config) ArrayList(java.util.ArrayList) Namespace(net.sourceforge.argparse4j.inf.Namespace) BufferedReader(java.io.BufferedReader) IntervalFeature(tracks.IntervalFeature)

Example 9 with Config

use of coloring.Config in project ASCIIGenome by dariober.

the class TrackTest method canConcatTitleAndTrackWithNoFeatures.

@Test
public void canConcatTitleAndTrackWithNoFeatures() throws ClassNotFoundException, IOException, InvalidGenomicCoordsException, InvalidRecordException, SQLException, InvalidConfigException, InvalidColourException {
    new Config(null);
    GenomicCoords gc = new GenomicCoords("1:1-1000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature("test_data/CHD.exon.2010_03.sites.vcf", gc);
    tif.setNoFormat(true);
    tif.setTrackTag("title.bed");
    String[] lines = tif.concatTitleAndTrack().split("\n");
    assertEquals(1, lines.length);
    assertTrue(!tif.concatTitleAndTrack().contains("\n"));
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Config(coloring.Config) Test(org.junit.Test)

Example 10 with Config

use of coloring.Config in project ASCIIGenome by dariober.

the class TrackTest method canParsePrintBAM.

@Test
public void canParsePrintBAM() throws InvalidGenomicCoordsException, IOException, InvalidColourException, InvalidCommandLineException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidConfigException {
    new Config(null);
    // BAM
    GenomicCoords gc = new GenomicCoords("chr7:5566733-5566903", 80, null, null);
    TrackReads tif = new TrackReads("test_data/ds051.short.bam", gc);
    tif.setNoFormat(true);
    tif.setPrintMode(PrintRawLine.FULL);
    tif.setSystemCommandForPrint("grep NCNNTCCC");
    assertEquals(2, tif.printLines().split("\n").length);
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Config(coloring.Config) Test(org.junit.Test)

Aggregations

Config (coloring.Config)11 Test (org.junit.Test)9 GenomicCoords (samTextViewer.GenomicCoords)8 ArrayList (java.util.ArrayList)4 TrackSet (tracks.TrackSet)2 ConfigKey (coloring.ConfigKey)1 Xterm256 (coloring.Xterm256)1 InvalidColourException (exceptions.InvalidColourException)1 InvalidCommandLineException (exceptions.InvalidCommandLineException)1 InvalidConfigException (exceptions.InvalidConfigException)1 InvalidGenomicCoordsException (exceptions.InvalidGenomicCoordsException)1 InvalidRecordException (exceptions.InvalidRecordException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ConsoleReader (jline.console.ConsoleReader)1 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)1 Namespace (net.sourceforge.argparse4j.inf.Namespace)1 IntervalFeature (tracks.IntervalFeature)1