<commit_before>package net.maizegenetics.pal.alignment;

import net.maizegenetics.pal.site.Chromosome;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Pattern;
import net.maizegenetics.pal.alignment.genotype.Genotype;
import net.maizegenetics.pal.alignment.genotype.GenotypeBuilder;

import net.maizegenetics.pal.taxa.TaxaList;
import net.maizegenetics.pal.taxa.TaxaListBuilder;
import net.maizegenetics.util.Utils;

public class ReadPolymorphismUtils {

    private static Pattern WHITESPACE = Pattern.compile("\\s+");

    //prevents instantiation
    private ReadPolymorphismUtils() {
    }

    public static Alignment readPolymorphismFile(String inFile) throws IOException {
        BufferedReader br = Utils.getBufferedReader(inFile);
        String inline = br.readLine();
        String[] markerNames = null;
        ArrayList<String[]> dataList = new ArrayList<String[]>();
        int nTaxa = 0;
        int nMarkers = 0;

        if (!inline.startsWith("#") && !inline.startsWith("<")) {
            String[] data = inline.split("[:\\s]+");
            nTaxa = Integer.parseInt(data[0]);
            nMarkers = Integer.parseInt(data[1]);
            markerNames = WHITESPACE.split(br.readLine());
            if (markerNames.length != nMarkers) {
                throw new IllegalStateException("ReadPolymorphismUtils: readPolymorphismFile: Number markers: " + markerNames.length + " doesn't match declaration: " + nMarkers);
            }
            for (int i = 0; i < nTaxa; i++) {
                inline = br.readLine();
                data = WHITESPACE.split(inline);
                dataList.add(data);
            }
        } else {
            while (inline != null) {
                if (!inline.startsWith("#")) {
                    if (inline.startsWith("<")) {
                        String[] data = inline.split("[<>\\s]+");
                        if (data[1].toLowerCase().startsWith("marker")) {
                            nMarkers = data.length - 2;
                            markerNames = new String[nMarkers];
                            System.arraycopy(data, 2, markerNames, 0, nMarkers);
                        }
                    } else {
                        dataList.add(WHITESPACE.split(inline));
                    }
                }
                inline = br.readLine();
            }
            nTaxa = dataList.size();
        }

        String[][] finalData = new String[nTaxa][nMarkers];
        String[] taxa = new String[nTaxa];
        for (int t = 0; t < nTaxa; t++) {
            String[] taxonData = dataList.get(t);
            taxa[t] = taxonData[0];
            for (int s = 0; s < nMarkers; s++) {
                if (taxonData[s + 1].equals("?")) {
                    finalData[t][s] = Alignment.UNKNOWN_ALLELE_STR;
                } else if (taxonData[s + 1].equals("?:?")) {
                    finalData[t][s] = Alignment.UNKNOWN_DIPLOID_ALLELE_STR;
                } else {
                    finalData[t][s] = taxonData[s + 1];
                }
            }
        }

        Chromosome[] myLoci = new Chromosome[]{Chromosome.UNKNOWN};
        Genotype genotype = GenotypeBuilder.getUnphasedNucleotideGenotypeBuilder(nTaxa, nMarkers)
                .setBases(finalData)
                .build();

        TaxaList taxaList = new TaxaListBuilder().addAll(taxa).build();

        return new CoreAlignment(genotype, null, taxaList, null, null);

    }

    public static GeneticMap readGeneticMapFile(String filename) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(filename));
        String inline = br.readLine();
        while (inline != null && inline.startsWith("#")) {
            inline = br.readLine();
        }
        if (!inline.trim().toLowerCase().equals("<map>")) {
            br.close();
            throw new IOException("Expected <Map> as first line of file.");
        }

        GeneticMap theMap = new GeneticMap("Genetic Map: " + filename);
<commit_msg>In ReadPolymorphismUtils using AlignmentBuilder instead of CoreAlignment constructor<commit_after>package net.maizegenetics.pal.alignment;

import net.maizegenetics.pal.site.Chromosome;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Pattern;
import net.maizegenetics.pal.alignment.genotype.Genotype;
import net.maizegenetics.pal.alignment.genotype.GenotypeBuilder;

import net.maizegenetics.pal.taxa.TaxaList;
import net.maizegenetics.pal.taxa.TaxaListBuilder;
import net.maizegenetics.util.Utils;

public class ReadPolymorphismUtils {

    private static Pattern WHITESPACE = Pattern.compile("\\s+");

    //prevents instantiation
    private ReadPolymorphismUtils() {
    }

    public static Alignment readPolymorphismFile(String inFile) throws IOException {
        BufferedReader br = Utils.getBufferedReader(inFile);
        String inline = br.readLine();
        String[] markerNames = null;
        ArrayList<String[]> dataList = new ArrayList<String[]>();
        int nTaxa = 0;
        int nMarkers = 0;

        if (!inline.startsWith("#") && !inline.startsWith("<")) {
            String[] data = inline.split("[:\\s]+");
            nTaxa = Integer.parseInt(data[0]);
            nMarkers = Integer.parseInt(data[1]);
            markerNames = WHITESPACE.split(br.readLine());
            if (markerNames.length != nMarkers) {
                throw new IllegalStateException("ReadPolymorphismUtils: readPolymorphismFile: Number markers: " + markerNames.length + " doesn't match declaration: " + nMarkers);
            }
            for (int i = 0; i < nTaxa; i++) {
                inline = br.readLine();
                data = WHITESPACE.split(inline);
                dataList.add(data);
            }
        } else {
            while (inline != null) {
                if (!inline.startsWith("#")) {
                    if (inline.startsWith("<")) {
                        String[] data = inline.split("[<>\\s]+");
                        if (data[1].toLowerCase().startsWith("marker")) {
                            nMarkers = data.length - 2;
                            markerNames = new String[nMarkers];
                            System.arraycopy(data, 2, markerNames, 0, nMarkers);
                        }
                    } else {
                        dataList.add(WHITESPACE.split(inline));
                    }
                }
                inline = br.readLine();
            }
            nTaxa = dataList.size();
        }

        String[][] finalData = new String[nTaxa][nMarkers];
        String[] taxa = new String[nTaxa];
        for (int t = 0; t < nTaxa; t++) {
            String[] taxonData = dataList.get(t);
            taxa[t] = taxonData[0];
            for (int s = 0; s < nMarkers; s++) {
                if (taxonData[s + 1].equals("?")) {
                    finalData[t][s] = Alignment.UNKNOWN_ALLELE_STR;
                } else if (taxonData[s + 1].equals("?:?")) {
                    finalData[t][s] = Alignment.UNKNOWN_DIPLOID_ALLELE_STR;
                } else {
                    finalData[t][s] = taxonData[s + 1];
                }
            }
        }

        Chromosome[] myLoci = new Chromosome[]{Chromosome.UNKNOWN};
        Genotype genotype = GenotypeBuilder.getUnphasedNucleotideGenotypeBuilder(nTaxa, nMarkers)
                .setBases(finalData)
                .build();

        TaxaList taxaList = new TaxaListBuilder().addAll(taxa).build();

        return AlignmentBuilder.getInstance(genotype, null, taxaList);

    }

    public static GeneticMap readGeneticMapFile(String filename) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(filename));
        String inline = br.readLine();
        while (inline != null && inline.startsWith("#")) {
            inline = br.readLine();
        }
        if (!inline.trim().toLowerCase().equals("<map>")) {
            br.close();
            throw new IOException("Expected <Map> as first line of file.");
        }

        GeneticMap theMap = new GeneticMap("Genetic Map: " + filename);

{'fraction_non_alphanumeric': 0.12475704567541303, 'fraction_numerical': 0.0036443148688046646, 'mean_word_length': 1.9851341551849166, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 13, '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': '3833880', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2296, 'n_words': 468}