<commit_before>package com.bina.varsim.util;

import com.bina.varsim.types.variant.Variant;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;

import java.io.IOException;
import java.rmi.UnexpectedException;

import static junit.framework.TestCase.assertTrue;

/**
 * Created by guoy28 on 10/5/16.
 * some simple tests for VCF parsing
 */
public class VCFparserTest {
    private VCFparser parser;
    @Before
    public void setup() throws UnexpectedException{
        parser = new VCFparser();
        parser.processLine("##fileformat=VCFv4.1");
        parser.processLine("##reference=src/test/resources/DuplicationTest/oneDuplicationTest.fa");
        parser.processLine("##INFO=<ID=SVLEN,Number=.,Type=Integer,Description=\"Length of variant\">");
        parser.processLine("##INFO=<ID=SVTYPE,Number=1,Type=String,Description=\"Type of structural variant\">");
        parser.processLine("##FORMAT=<ID=GT,Number=1,Type=String,Description=\"Genotype\">");
        parser.processLine("##ALT=<ID=DEL,Description=\"Deletion\">");
        parser.processLine("##ALT=<ID=DEL:ME:ALU,Description=\"Deletion of ALU element\">");
        parser.processLine("##ALT=<ID=DEL:ME:L1,Description=\"Deletion of L1 element\">");
        parser.processLine("##ALT=<ID=DUP,Description=\"Duplication\">");
        parser.processLine("##ALT=<ID=DUP:TANDEM,Description=\"Tandem Duplication\">");
        parser.processLine("##ALT=<ID=INS,Description=\"Insertion of novel sequence\">");
        parser.processLine("##ALT=<ID=INS:ME:ALU,Description=\"Insertion of ALU element\">");
        parser.processLine("##ALT=<ID=INS:ME:L1,Description=\"Insertion of L1 element\">");
        parser.processLine("##ALT=<ID=INV,Description=\"Inversion\">");
        parser.processLine("##ALT=<ID=CNV,Description=\"Copy number variable region\">");
        parser.processLine("##ALT=<ID=ITX,Description=\"Intra-chromosomal translocation\">");
        parser.processLine("##ALT=<ID=CTX,Description=\"Inter-chromosomal translocation\">");
        parser.processLine("#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	test");
    }
    @Test
    public void deletionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557989\t.\tACAAAAGAAATGATCATGTTTGTAGGT\tAAAAAGAAATGATCATGTTTGTAGGT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        /*
        ref: A CAAAAGAAATGATCATGTTTGTAGGT
        alt: A A AAAGAAATGATCATGTTTGTAGGT
        */
        assertTrue(v.toString().equals("12\t29557989\t.\tAC\tA\t.\tPASS\tSVLEN=-1\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 1); //[C]
        assertTrue(v.getAlt(1).length() == 0); //""
    }
    @Test
    public void insertionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557990\t.\tCTTT\tCGTTTT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        assertTrue(v.toString().equals("12\t29557990\t.\tC\tCGT\t.\tPASS\tSVLEN=2\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 0); //[]
        assertTrue(v.getAlt(1).length() == 2); //"GT"
    }
    @Test
    public void homopolymerInsertionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557989\t.\tACT\tAAAACT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        assertTrue(v.toString().equals("12\t29557989\t.\tA\tAAAA\t.\tPASS\tSVLEN=3\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 0); //[]
        assertTrue(v.getAlt(1).length() == 3); //"GT"
    }
    @Test(expected = IllegalArgumentException.class)
    public void SymbolicAlleleSVLenTest() throws UnexpectedException {
        parser.processLine("1	3	.	T	<DUP:TANDEM>	.	PASS	SVTYPE=DUP;SVLEN=4,4	GT:CN	1|2:2|3");
    }
    @Test(expected = IllegalArgumentException.class)
    public void SymbolicAlleleMixWithNonSymbolicAlleleTest() throws IOException {
        parser.processLine("1	3	.	T	<DUP:TANDEM>,TTTT	.	PASS	SVTYPE=DUP;SVLEN=4,4	GT:CN	1|2:2|3");
    }
}<commit_msg>bug fix<commit_after>package com.bina.varsim.util;

import com.bina.varsim.types.variant.Variant;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;

import java.io.IOException;
import java.rmi.UnexpectedException;

import static junit.framework.TestCase.assertTrue;

/**
 * Created by guoy28 on 10/5/16.
 * some simple tests for VCF parsing
 */
public class VCFparserTest {
    private VCFparser parser;
    @Before
    public void setup() throws UnexpectedException{
        parser = new VCFparser();
        parser.processLine("##fileformat=VCFv4.1");
        parser.processLine("##reference=src/test/resources/DuplicationTest/oneDuplicationTest.fa");
        parser.processLine("##INFO=<ID=SVLEN,Number=.,Type=Integer,Description=\"Length of variant\">");
        parser.processLine("##INFO=<ID=SVTYPE,Number=1,Type=String,Description=\"Type of structural variant\">");
        parser.processLine("##FORMAT=<ID=GT,Number=1,Type=String,Description=\"Genotype\">");
        parser.processLine("##ALT=<ID=DEL,Description=\"Deletion\">");
        parser.processLine("##ALT=<ID=DEL:ME:ALU,Description=\"Deletion of ALU element\">");
        parser.processLine("##ALT=<ID=DEL:ME:L1,Description=\"Deletion of L1 element\">");
        parser.processLine("##ALT=<ID=DUP,Description=\"Duplication\">");
        parser.processLine("##ALT=<ID=DUP:TANDEM,Description=\"Tandem Duplication\">");
        parser.processLine("##ALT=<ID=INS,Description=\"Insertion of novel sequence\">");
        parser.processLine("##ALT=<ID=INS:ME:ALU,Description=\"Insertion of ALU element\">");
        parser.processLine("##ALT=<ID=INS:ME:L1,Description=\"Insertion of L1 element\">");
        parser.processLine("##ALT=<ID=INV,Description=\"Inversion\">");
        parser.processLine("##ALT=<ID=CNV,Description=\"Copy number variable region\">");
        parser.processLine("##ALT=<ID=ITX,Description=\"Intra-chromosomal translocation\">");
        parser.processLine("##ALT=<ID=CTX,Description=\"Inter-chromosomal translocation\">");
        parser.processLine("#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	test");
    }
    @Test
    public void deletionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557989\t.\tACAAAAGAAATGATCATGTTTGTAGGT\tAAAAAGAAATGATCATGTTTGTAGGT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        /*
        ref: A CAAAAGAAATGATCATGTTTGTAGGT
        alt: A A AAAGAAATGATCATGTTTGTAGGT
        */
        assertTrue(v.toString().equals("12\t29557989\t.\tAC\tA\t.\tPASS\tSVLEN=-1\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 1); //[C]
        assertTrue(v.getAlt(1).getSeq().length() == 0); //""
    }
    @Test
    public void insertionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557990\t.\tCTTT\tCGTTTT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        assertTrue(v.toString().equals("12\t29557990\t.\tC\tCGT\t.\tPASS\tSVLEN=2\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 0); //[]
        assertTrue(v.getAlt(1).getSeq().length() == 2); //"GT"
    }
    @Test
    public void homopolymerInsertionParsingTest() throws UnexpectedException {
        Variant v = parser.processLine("12\t29557989\t.\tACT\tAAAACT\t.\tPASS\tSVLEN=-26\tGT\t1|1");
        assertTrue(v.toString().equals("12\t29557989\t.\tA\tAAAA\t.\tPASS\tSVLEN=3\tGT\t1|1"));
        assertTrue(v.isPhased());
        assertTrue(v.getReference().length == 0); //[]
        assertTrue(v.getAlt(1).getSeq().length() == 3); //"GT"
    }
    @Test(expected = IllegalArgumentException.class)
    public void SymbolicAlleleSVLenTest() throws UnexpectedException {
        parser.processLine("1	3	.	T	<DUP:TANDEM>	.	PASS	SVTYPE=DUP;SVLEN=4,4	GT:CN	1|2:2|3");
    }
    @Test(expected = IllegalArgumentException.class)
    public void SymbolicAlleleMixWithNonSymbolicAlleleTest() throws IOException {
        parser.processLine("1	3	.	T	<DUP:TANDEM>,TTTT	.	PASS	SVTYPE=DUP;SVLEN=4,4	GT:CN	1|2:2|3");
    }
}
{'fraction_non_alphanumeric': 0.17346559206447612, 'fraction_numerical': 0.03000619962802232, 'mean_word_length': 3.9033434650455927, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '5559045', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2779, 'n_words': 363}