<commit_before>package org.opencb.opencga.storage.variant;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.apache.commons.lang.StringUtils;
import org.opencb.commons.bioformats.variant.json.VariantAnalysisInfo;
import org.opencb.commons.bioformats.variant.json.VariantControl;
import org.opencb.commons.bioformats.variant.json.VariantInfo;
import org.opencb.commons.bioformats.variant.utils.effect.VariantEffect;
import org.opencb.commons.bioformats.variant.utils.stats.VariantStats;

//import javax.ws.rs.client.Client;
//import javax.ws.rs.client.ClientBuilder;
//import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.sql.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: aaleman
 * Date: 10/30/13
 * Time: 12:14 PM
 * To change this template use File | Settings | File Templates.
 */
public class VariantSqliteQueryMaker implements VariantQueryMaker {

    public VariantSqliteQueryMaker() {
        System.out.println("Variant Query Maker");
    }

    @Override
    public List<VariantInfo> getRecords(Map<String, String> options) {

        Connection con;
        Statement stmt;
        List<VariantInfo> list = new ArrayList<>(100);

        String dbName = options.get("db_name");
        showDb(dbName);

        try {
            Class.forName("org.sqlite.JDBC");
            con = DriverManager.getConnection("jdbc:sqlite:" + dbName);

            List<String> whereClauses = new ArrayList<>(10);

            Map<String, List<String>> sampleGenotypes;
            Map<String, String> controlsMAFs = new LinkedHashMap<>();
            sampleGenotypes = processSamplesGT(options);

            if (options.containsKey("region_list") && !options.get("region_list").equals("")) {

                StringBuilder regionClauses = new StringBuilder("(");
                String[] regions = options.get("region_list").split(",");
                Pattern pattern = Pattern.compile("(\\w+):(\\d+)-(\\d+)");
                Matcher matcher;


                for (int i = 0; i < regions.length; i++) {
                    String region = regions[i];
                    matcher = pattern.matcher(region);
                    if (matcher.find()) {
                        String chr = matcher.group(1);
                        int start = Integer.valueOf(matcher.group(2));
                        int end = Integer.valueOf(matcher.group(3));

                        regionClauses.append("( variant_stats.chromosome='").append(chr).append("' AND ");
                        regionClauses.append("variant_stats.position>=").append(start).append(" AND ");
                        regionClauses.append("variant_stats.position<=").append(end).append(" )");


                        if (i < (regions.length - 1)) {
                            regionClauses.append(" OR ");

                        }

                    }
                }
                regionClauses.append(" ) ");
                whereClauses.add(regionClauses.toString());
            }
<commit_msg>Added new region parser to sqliteQM<commit_after>package org.opencb.opencga.storage.variant;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.apache.commons.lang.StringUtils;
import org.opencb.commons.bioformats.variant.json.VariantAnalysisInfo;
import org.opencb.commons.bioformats.variant.json.VariantControl;
import org.opencb.commons.bioformats.variant.json.VariantInfo;
import org.opencb.commons.bioformats.variant.utils.effect.VariantEffect;
import org.opencb.commons.bioformats.variant.utils.stats.VariantStats;

//import javax.ws.rs.client.Client;
//import javax.ws.rs.client.ClientBuilder;
//import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.sql.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: aaleman
 * Date: 10/30/13
 * Time: 12:14 PM
 * To change this template use File | Settings | File Templates.
 */
public class VariantSqliteQueryMaker implements VariantQueryMaker {

    public VariantSqliteQueryMaker() {
        System.out.println("Variant Query Maker");
    }

    @Override
    public List<VariantInfo> getRecords(Map<String, String> options) {

        Connection con;
        Statement stmt;
        List<VariantInfo> list = new ArrayList<>(100);

        String dbName = options.get("db_name");
        showDb(dbName);

        try {
            Class.forName("org.sqlite.JDBC");
            con = DriverManager.getConnection("jdbc:sqlite:" + dbName);

            List<String> whereClauses = new ArrayList<>(10);

            Map<String, List<String>> sampleGenotypes;
            Map<String, String> controlsMAFs = new LinkedHashMap<>();
            sampleGenotypes = processSamplesGT(options);

            if (options.containsKey("region_list") && !options.get("region_list").equals("")) {

                StringBuilder regionClauses = new StringBuilder("(");
                String[] regions = options.get("region_list").split(",");
                Pattern patternReg = Pattern.compile("(\\w+):(\\d+)-(\\d+)");
                Matcher matcherReg, matcherChr;

                for (int i = 0; i < regions.length; i++) {
                    String region = regions[i];
                    matcherReg = patternReg.matcher(region);
                    if (matcherReg.find()) {
                        String chr = matcherReg.group(1);
                        int start = Integer.valueOf(matcherReg.group(2));
                        int end = Integer.valueOf(matcherReg.group(3));

                        regionClauses.append("( variant_stats.chromosome='").append(chr).append("' AND ");
                        regionClauses.append("variant_stats.position>=").append(start).append(" AND ");
                        regionClauses.append("variant_stats.position<=").append(end).append(" )");

                        if (i < (regions.length - 1)) {
                            regionClauses.append(" OR ");

                        }
                    } else {
                        Pattern patternChr = Pattern.compile("(\\w+)");
                        matcherChr = patternChr.matcher(region);

                        if (matcherChr.find()) {
                            String chr = matcherChr.group();
                            regionClauses.append("( variant_stats.chromosome='").append(chr).append("')");

                            if (i < (regions.length - 1)) {
                                regionClauses.append(" OR ");
                            }
                        } else {
                            System.err.println("ERROR: Region (" + region + ")");
                        }
                    }
                }
                regionClauses.append(" ) ");
                whereClauses.add(regionClauses.toString());
            }

{'fraction_non_alphanumeric': 0.12836067833999723, 'fraction_numerical': 0.005652833310354336, 'mean_word_length': 2.1294219154443486, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6894132', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1928, 'n_words': 347}