<commit_before>package com.binatechnologies.varsim;

import org.apache.log4j.Logger;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import java.io.*;
import java.util.Random;

/**
 *
 */

/**
 * @author johnmu
 */

public class RandBED2VCF extends randVCFgenerator {
    private final static Logger log = Logger.getLogger(RandBED2VCF.class.getName());

    SimpleReference ref;
    int num_novel_added = 0;
    int var_idx = 0;
    byte[] insert_seq = null;

    // parameters
    static final int MIN_LEN_ARG = 50;
    @Option(name = "-min_len", usage = "Minimum variant length ["+MIN_LEN_ARG+"], inclusive")
    int min_length_lim = MIN_LEN_ARG;

    static final int MAX_LEN_ARG = 1000000;
    @Option(name = "-max_len", usage = "Maximum variant length ["+MAX_LEN_ARG+"], inclusive")
    int max_length_lim = MAX_LEN_ARG;

    static final long SEED_ARG = 333;
    @Option(name = "-seed", usage = "Seed for random sampling ["+SEED_ARG+"]")
    static long seed = 333;

    @Option(name = "-ref", usage = "Reference Genome [Required]",metaVar = "file",required = true)
    String reference_filename;

    @Option(name = "-ins", usage = "Known Insertion Sequences [Required]",metaVar = "file",required = true)
    String insert_filename;

    @Option(name = "-ins_bed", usage = "Known Insertion BED file [Required]",metaVar = "BED_file",required = true)
    String ins_bed_filename;

    @Option(name = "-del_bed", usage = "Known Deletion BED file [Required]",metaVar = "BED_file",required = true)
    String del_bed_filename;

    @Option(name = "-dup_bed", usage = "Known Duplication BED file [Required]",metaVar = "BED_file",required = true)
    String dup_bed_filename;

    RandBED2VCF() {
        super();
        num_novel_added = 0;
        var_idx = 0;
    }

    RandBED2VCF(long seed) {
        super(seed);
        num_novel_added = 0;
        var_idx = 0;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        RandBED2VCF runner = new RandBED2VCF();
        runner.run(args);
    }


    // outputs VCF record with random phase
    void rand_output_vcf_record(BufferedWriter bw, Variant var) throws IOException {

        // this is ok if both the same genotype
        // the second call will return
        fill_in_seq(var, insert_seq, var.getGeno().geno[0]);
        fill_in_seq(var, insert_seq, var.getGeno().geno[1]);

        output_vcf_record(bw, var);

    }

    // remember BED is 0-based
    Variant parse_bed_line(String line, Variant.Type type) {
        String[] ll = line.split("\t");
        if (ll.length < 4) return new Variant(_rand);

        int chr_idx = variantFileParser.getChromIndex(ll[0]);

        if(chr_idx <= 0){
            return null;
        }

        int pos = Integer.parseInt(ll[1]);
        //int end = Integer.parseInt(ll[2]);
        String[] meta = ll[3].split(",");
        byte[] ins_seq = null;
        int len = 1;
        if(meta[0].equals("seq")){
            // this is an insertion and we have the insertion sequence
            try {
                ins_seq = meta[1].getBytes("US-ASCII");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }else{
            len = Integer.parseInt(meta[0]);
        }

        if (pos == 0 || len > max_length_lim || len < min_length_lim) return null;

        FlexSeq[] alts = new FlexSeq[1];
        String var_idx_str = "";<commit_msg>parse BED properly<commit_after>package com.binatechnologies.varsim;

import org.apache.log4j.Logger;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import java.io.*;
import java.util.Random;

/**
 *
 */

/**
 * @author johnmu
 */

public class RandBED2VCF extends randVCFgenerator {
    private final static Logger log = Logger.getLogger(RandBED2VCF.class.getName());

    SimpleReference ref;
    int num_novel_added = 0;
    int var_idx = 0;
    byte[] insert_seq = null;

    // parameters
    static final int MIN_LEN_ARG = 50;
    @Option(name = "-min_len", usage = "Minimum variant length ["+MIN_LEN_ARG+"], inclusive")
    int min_length_lim = MIN_LEN_ARG;

    static final int MAX_LEN_ARG = 1000000;
    @Option(name = "-max_len", usage = "Maximum variant length ["+MAX_LEN_ARG+"], inclusive")
    int max_length_lim = MAX_LEN_ARG;

    static final long SEED_ARG = 333;
    @Option(name = "-seed", usage = "Seed for random sampling ["+SEED_ARG+"]")
    static long seed = 333;

    @Option(name = "-ref", usage = "Reference Genome [Required]",metaVar = "file",required = true)
    String reference_filename;

    @Option(name = "-ins", usage = "Known Insertion Sequences [Required]",metaVar = "file",required = true)
    String insert_filename;

    @Option(name = "-ins_bed", usage = "Known Insertion BED file [Required]",metaVar = "BED_file",required = true)
    String ins_bed_filename;

    @Option(name = "-del_bed", usage = "Known Deletion BED file [Required]",metaVar = "BED_file",required = true)
    String del_bed_filename;

    @Option(name = "-dup_bed", usage = "Known Duplication BED file [Required]",metaVar = "BED_file",required = true)
    String dup_bed_filename;

    RandBED2VCF() {
        super();
        num_novel_added = 0;
        var_idx = 0;
    }

    RandBED2VCF(long seed) {
        super(seed);
        num_novel_added = 0;
        var_idx = 0;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        RandBED2VCF runner = new RandBED2VCF();
        runner.run(args);
    }


    // outputs VCF record with random phase
    void rand_output_vcf_record(BufferedWriter bw, Variant var) throws IOException {

        // this is ok if both the same genotype
        // the second call will return
        fill_in_seq(var, insert_seq, var.getGeno().geno[0]);
        fill_in_seq(var, insert_seq, var.getGeno().geno[1]);

        output_vcf_record(bw, var);

    }

    // remember BED is 0-based
    Variant parse_bed_line(String line, Variant.Type type) {
        String[] ll = line.split("\t");
        if (ll.length < 4) return new Variant(_rand);

        int chr_idx = variantFileParser.getChromIndex(ll[0]);

        if(chr_idx <= 0){
            return null;
        }

        int pos = Integer.parseInt(ll[1]) + 1; //0-indexed
        //int end = Integer.parseInt(ll[2]);
        String[] meta = ll[3].split(",");
        byte[] ins_seq = null;
        int len = 1;
        if(meta[0].equals("seq")){
            // this is an insertion and we have the insertion sequence
            try {
                ins_seq = meta[1].getBytes("US-ASCII");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }else{
            len = Integer.parseInt(meta[0]);
        }

        if (pos == 0 || len > max_length_lim || len < min_length_lim) return null;

        FlexSeq[] alts = new FlexSeq[1];
        String var_idx_str = "";
{'fraction_non_alphanumeric': 0.12650687845695646, 'fraction_numerical': 0.013331442348603034, 'mean_word_length': 2.6444444444444444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '4227696', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2241, 'n_words': 564}