<commit_before>package abra;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;

public class JunctionUtilsTest {
	
	private void assertJunctionEquals(Feature actual, String chr, int start, int end) {
		assertEquals(actual.getSeqname(), chr, "Junction: " + chr + ":" + start + "-" + end);
		assertEquals(actual.getStart(), start, "Junction: " + chr + ":" + start + "-" + end);
		assertEquals(actual.getEnd(), end, "Junction: " + chr + ":" + start + "-" + end);
	}
	
	@Test (groups = "unit")
	public void testLoadJunctionsFromGtf() throws Exception {
		Set<Feature> junctions = JunctionUtils.loadJunctionsFromGtf("test-data/annotation1.gtf");
		assertEquals(junctions.size(), 4);
		assertTrue(junctions.contains(new Feature("chr7", 55087059, 55209978)));
		assertTrue(junctions.contains(new Feature("chr7", 55210131, 55210997)));
		assertTrue(junctions.contains(new Feature("chr7", 55211182, 55218986)));
		assertTrue(junctions.contains(new Feature("chr7", 55211182, 55214298)));
	}

	@Test (groups = "unit")
	public void testGetRegionJunctions() throws Exception {
		
		RegionLoader loader = new RegionLoader();
		List<Feature> junctions = loader.load("test-data/junctions1.tab", false);
		assertEquals(junctions.size(), 29);
		
		Feature region = new Feature("chr4", 1803001, 1803401);
		List<Feature> regions = Arrays.asList(region);
		int readLength = 48;
		int maxRegionLength = 400;
		Map<Feature, List<Feature>> regionJunctionMap = JunctionUtils.getRegionJunctions(regions, junctions, readLength, maxRegionLength);
		
		List<Feature> regionJunctions = regionJunctionMap.get(region);
		
		assertEquals(regionJunctions.size(), 12);
		assertJunctionEquals(regionJunctions.get(0), "chr4", 1800000, 1801530);
		assertJunctionEquals(regionJunctions.get(1), "chr4", 1801540, 1803093);
		assertJunctionEquals(regionJunctions.get(2), "chr4", 1803264, 1803346);
		assertJunctionEquals(regionJunctions.get(3), "chr4", 1803471, 1803561);
		assertJunctionEquals(regionJunctions.get(4), "chr4", 1803471, 1803590);
		assertJunctionEquals(regionJunctions.get(5), "chr4", 1803651, 1808025);
		assertJunctionEquals(regionJunctions.get(6), "chr4", 1803714, 1805418);
		assertJunctionEquals(regionJunctions.get(7), "chr4", 1803753, 1804640);
		assertJunctionEquals(regionJunctions.get(8), "chr4", 1803753, 1805418);
		assertJunctionEquals(regionJunctions.get(9), "chr4", 1803753, 1806056);
		assertJunctionEquals(regionJunctions.get(10), "chr4", 1803753, 1806550);
		assertJunctionEquals(regionJunctions.get(11), "chr4", 1808055, 1808272);
				 
		
//		List<List<Feature>> junctionPerms = JunctionUtils.combineJunctions(regionJunctions, readLength);
//		System.out.println(junctionPerms.size());
	}
	
	@Test (groups = "unit")
	public void testCombineJunctions() throws Exception {
		
		int readLength = 50;
		
		Feature j1 = new Feature("chr1", 10000, 10100);
		Feature j2 = new Feature("chr1", 10110, 10200);
		Feature j3 = new Feature("chr1", 10110, 10300);
		Feature j4 = new Feature("chr1", 10330, 10500);
		
		List<Feature> inputJunctions = Arrays.asList(j1, j2, j3, j4);
		List<List<Feature>> junctionPerms = JunctionUtils.combineJunctions(inputJunctions, readLength);
		assertEquals(junctionPerms.size(), 8);
		
		// Expected permutations<commit_msg>Permute junctions a bit more miserly.<commit_after>package abra;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;

public class JunctionUtilsTest {
	
	private void assertJunctionEquals(Feature actual, String chr, int start, int end) {
		assertEquals(actual.getSeqname(), chr, "Junction: " + chr + ":" + start + "-" + end);
		assertEquals(actual.getStart(), start, "Junction: " + chr + ":" + start + "-" + end);
		assertEquals(actual.getEnd(), end, "Junction: " + chr + ":" + start + "-" + end);
	}
	
	@Test (groups = "unit")
	public void testLoadJunctionsFromGtf() throws Exception {
		Set<Feature> junctions = JunctionUtils.loadJunctionsFromGtf("test-data/annotation1.gtf");
		assertEquals(junctions.size(), 4);
		assertTrue(junctions.contains(new Feature("chr7", 55087059, 55209978)));
		assertTrue(junctions.contains(new Feature("chr7", 55210131, 55210997)));
		assertTrue(junctions.contains(new Feature("chr7", 55211182, 55218986)));
		assertTrue(junctions.contains(new Feature("chr7", 55211182, 55214298)));
	}

	@Test (groups = "unit")
	public void testGetRegionJunctions() throws Exception {
		
		RegionLoader loader = new RegionLoader();
		List<Feature> junctions = loader.load("test-data/junctions1.tab", false);
		assertEquals(junctions.size(), 29);
		
		Feature region = new Feature("chr4", 1803001, 1803401);
		List<Feature> regions = Arrays.asList(region);
		int readLength = 48;
		int maxRegionLength = 400;
		Map<Feature, List<Feature>> regionJunctionMap = JunctionUtils.getRegionJunctions(regions, junctions, readLength, maxRegionLength);
		
		List<Feature> regionJunctions = regionJunctionMap.get(region);
		
		assertEquals(regionJunctions.size(), 12);
		assertJunctionEquals(regionJunctions.get(0), "chr4", 1800000, 1801530);
		assertJunctionEquals(regionJunctions.get(1), "chr4", 1801540, 1803093);
		assertJunctionEquals(regionJunctions.get(2), "chr4", 1803264, 1803346);
		assertJunctionEquals(regionJunctions.get(3), "chr4", 1803471, 1803561);
		assertJunctionEquals(regionJunctions.get(4), "chr4", 1803471, 1803590);
		assertJunctionEquals(regionJunctions.get(5), "chr4", 1803651, 1808025);
		assertJunctionEquals(regionJunctions.get(6), "chr4", 1803714, 1805418);
		assertJunctionEquals(regionJunctions.get(7), "chr4", 1803753, 1804640);
		assertJunctionEquals(regionJunctions.get(8), "chr4", 1803753, 1805418);
		assertJunctionEquals(regionJunctions.get(9), "chr4", 1803753, 1806056);
		assertJunctionEquals(regionJunctions.get(10), "chr4", 1803753, 1806550);
		assertJunctionEquals(regionJunctions.get(11), "chr4", 1808055, 1808272);
				 
		
//		List<List<Feature>> junctionPerms = JunctionUtils.combineJunctions(regionJunctions, readLength);
//		System.out.println(junctionPerms.size());
	}
	
	@Test (groups = "unit")
	public void testCombineJunctions() throws Exception {
		
		int readLength = 50;
		
		Feature j1 = new Feature("chr1", 10000, 10100);
		Feature j2 = new Feature("chr1", 10110, 10200);
		Feature j3 = new Feature("chr1", 10110, 10300);
		Feature j4 = new Feature("chr1", 10330, 10500);
		
		List<Feature> inputJunctions = Arrays.asList(j1, j2, j3, j4);
		List<List<Feature>> junctionPerms = JunctionUtils.combineJunctions(new Feature("chr1", 10000, 10400), inputJunctions, readLength, readLength);
		assertEquals(junctionPerms.size(), 8);
		
		// Expected permutations
{'fraction_non_alphanumeric': 0.1419869470630892, 'fraction_numerical': 0.10137781000725163, 'mean_word_length': 6.094650205761317, 'pattern_counts': {'":': 6, '<': 25, '<?xml version=': 0, '>': 25, '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': '2638162', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2237, 'n_words': 459}