<commit_before>package org.broadinstitute.sting.secondarybase;

import edu.mit.broad.picard.illumina.AbstractBustardFileParser;
import edu.mit.broad.picard.illumina.BustardFileParser;
import edu.mit.broad.picard.illumina.BustardFileParser_1_1;
import edu.mit.broad.picard.illumina.BustardReadData;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMFileWriterFactory;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class FourBaseRecaller extends CommandLineProgram {
    public static FourBaseRecaller Instance = null;
    
    @Argument(fullName="dir",         shortName="D", doc="Illumina Bustard directory")
    public File DIR;
    @Argument(fullName="lane",        shortName="L", doc="Illumina flowcell lane")
    public int LANE;
    @Argument(fullName="run_barcode", shortName="B", doc="Illumina Run Barcode (e.g. 305PJAAXX080716)")
    public String RUN_BARCODE;
    @Argument(fullName="out",         shortName="O", doc="Output path for sam file")
    public File OUT;
    @Argument(fullName="end",         shortName="E", doc="End of read to process (0 = whole read, i.e. unpaired; 1 = first end; 2 = second end)", required=false)
    public int END = 0;
    @Argument(fullName="tlim",        shortName="T", doc="Number of reads to use for parameter initialization", required=false)
    public int TRAINING_LIMIT = 1000000000;
    @Argument(fullName="clim",        shortName="C", doc="Number of reads to basecall", required=false)
    public int CALLING_LIMIT = 1000000000;
    @Argument(fullName="raw",         shortName="R", doc="Use raw intensities?", required=false)
    public Boolean RAW = false;
    @Argument(fullName="old",         shortName="1", doc="Old Bustard 1.1 mode?", required=false)
    public Boolean OLD = false;
    @Argument(fullName="context",     shortName="X", doc="Correct for context?", required=false)
    public Boolean CONTEXT = false;

    public static void main(String[] argv) {
        Instance = new FourBaseRecaller();
        start(Instance, argv);
    }

    protected int execute() {
        boolean isPaired = (END > 0);

        // Set up debugging paths
        File debugdir = new File(OUT.getPath() + ".debug/");
        debugdir.mkdir();
        PrintWriter debugout = null;
        try {
            debugout = new PrintWriter(debugdir.getPath() + "/debug.out");
        } catch (IOException e) {
        }

        AbstractBustardFileParser bfp;
        BustardReadData bread;

        FirecrestFileParser ffp;
        FirecrestReadData fread;

        bfp = OLD ? new BustardFileParser_1_1(DIR, LANE, isPaired, RUN_BARCODE) : new BustardFileParser(DIR, LANE, isPaired, RUN_BARCODE);
        bread = bfp.next();
        ffp = new FirecrestFileParser(DIR.getParentFile(), LANE);
        fread = ffp.next();

        int cycle_offset = (END <= 1) ? 0 : bread.getIntensities().length/2;
        BasecallingReadModel model = new BasecallingReadModel(bread.getFirstReadSequence().length(), CONTEXT);
        int queryid;

        // learn mean parameters
        System.err.println("Computing mean parameters...");

        queryid = 0;
        do {
            assert(bread.getXCoordinate() == fread.getXCoordinate() && bread.getYCoordinate() == fread.getYCoordinate());

            String bases = (END <= 1) ? bread.getFirstReadSequence() : bread.getSecondReadSequence();
            byte[] quals = (END <= 1) ? bread.getFirstReadPhredBinaryQualities() : bread.getSecondReadPhredBinaryQualities();
            double[][] intensities = bread.getIntensities();<commit_msg>Updated to reflect change to BasecallingReadModel constructor.<commit_after>package org.broadinstitute.sting.secondarybase;

import edu.mit.broad.picard.illumina.AbstractBustardFileParser;
import edu.mit.broad.picard.illumina.BustardFileParser;
import edu.mit.broad.picard.illumina.BustardFileParser_1_1;
import edu.mit.broad.picard.illumina.BustardReadData;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMFileWriterFactory;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class FourBaseRecaller extends CommandLineProgram {
    public static FourBaseRecaller Instance = null;
    
    @Argument(fullName="dir",         shortName="D", doc="Illumina Bustard directory")
    public File DIR;
    @Argument(fullName="lane",        shortName="L", doc="Illumina flowcell lane")
    public int LANE;
    @Argument(fullName="run_barcode", shortName="B", doc="Illumina Run Barcode (e.g. 305PJAAXX080716)")
    public String RUN_BARCODE;
    @Argument(fullName="out",         shortName="O", doc="Output path for sam file")
    public File OUT;
    @Argument(fullName="end",         shortName="E", doc="End of read to process (0 = whole read, i.e. unpaired; 1 = first end; 2 = second end)", required=false)
    public int END = 0;
    @Argument(fullName="tlim",        shortName="T", doc="Number of reads to use for parameter initialization", required=false)
    public int TRAINING_LIMIT = 1000000000;
    @Argument(fullName="clim",        shortName="C", doc="Number of reads to basecall", required=false)
    public int CALLING_LIMIT = 1000000000;
    @Argument(fullName="raw",         shortName="R", doc="Use raw intensities?", required=false)
    public Boolean RAW = false;
    @Argument(fullName="old",         shortName="1", doc="Old Bustard 1.1 mode?", required=false)
    public Boolean OLD = false;

    public static void main(String[] argv) {
        Instance = new FourBaseRecaller();
        start(Instance, argv);
    }

    protected int execute() {
        boolean isPaired = (END > 0);

        // Set up debugging paths
        File debugdir = new File(OUT.getPath() + ".debug/");
        debugdir.mkdir();
        PrintWriter debugout = null;
        try {
            debugout = new PrintWriter(debugdir.getPath() + "/debug.out");
        } catch (IOException e) {
        }

        AbstractBustardFileParser bfp;
        BustardReadData bread;

        FirecrestFileParser ffp;
        FirecrestReadData fread;

        bfp = OLD ? new BustardFileParser_1_1(DIR, LANE, isPaired, RUN_BARCODE) : new BustardFileParser(DIR, LANE, isPaired, RUN_BARCODE);
        bread = bfp.next();
        ffp = new FirecrestFileParser(DIR.getParentFile(), LANE);
        fread = ffp.next();

        int cycle_offset = (END <= 1) ? 0 : bread.getIntensities().length/2;
        BasecallingReadModel model = new BasecallingReadModel(bread.getFirstReadSequence().length());
        int queryid;

        // learn mean parameters
        System.err.println("Computing mean parameters...");

        queryid = 0;
        do {
            assert(bread.getXCoordinate() == fread.getXCoordinate() && bread.getYCoordinate() == fread.getYCoordinate());

            String bases = (END <= 1) ? bread.getFirstReadSequence() : bread.getSecondReadSequence();
            byte[] quals = (END <= 1) ? bread.getFirstReadPhredBinaryQualities() : bread.getSecondReadPhredBinaryQualities();
            double[][] intensities = bread.getIntensities();
{'fraction_non_alphanumeric': 0.11860860468157447, 'fraction_numerical': 0.012292402249248071, 'mean_word_length': 3.520094562647754, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4265050', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2280, 'n_words': 526}