/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 */
package org.biojava.nbio.structure.cluster;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.List;

import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.StructureIO;
import org.junit.Test;

/**
 * Test the {@link SubunitExtractor} correctness on different real structures
 * with different types of difficulties.
 * 
 * @author Aleix Lafita
 *
 */
public class TestSubunitExtractor {

	/**
	 * Some collagen structures have very short Chains, so the minimum sequence
	 * length is adjusted: 1A3I.
	 * 
	 * @see SubunitClustererParameters#getMinimumSequenceLengthFraction()
	 */
	@Test
	public void testCollagen() throws StructureException, IOException {

		Structure s = StructureIO.getStructure("1A3I");
		SubunitClustererParameters params = new SubunitClustererParameters();

		List<Subunit> subunits = SubunitExtractor.extractSubunits(s, params);

		// We expect all 3 subunits to be returned
		assertEquals(subunits.size(), 3);
		
		params.setMinimumSequenceLength(9);
		params.setAbsoluteMinimumSequenceLength(8);
		
		subunits = SubunitExtractor.extractSubunits(s, params);
		
		// Now we expect only the long Subunit to be returned
		assertEquals(subunits.size(), 1);
		assertEquals(subunits.get(0).size(), 9);
	}
	
	/**
	 * Make sure that only aminoacid chains are extracted: 5B2I.
	 */
	@Test
	public void testHistone() throws StructureException, IOException {

		Structure s = StructureIO.getStructure("5B2I");
		SubunitClustererParameters params = new SubunitClustererParameters();

		List<Subunit> subunits = SubunitExtractor.extractSubunits(s, params);

		// We expect all 8 histone subunits to be returned
		assertEquals(subunits.size(), 8);
		assertEquals(subunits.get(0).size(), 99);
		assertEquals(subunits.get(1).size(), 82);
		assertEquals(subunits.get(2).size(), 106);
	}
	
}

@@ -870,16 +870,72 @@
 tureIO;%0A
+import org.biojava.nbio.structure.align.util.AtomCache;%0A
 import o
@@ -949,16 +949,16 @@
 t.Test;%0A
-
 %0A/**%0A * 
@@ -1692,19 +1692,17 @@
 (), 3);%0A
-%09%09
 %0A
+
 %09%09params
@@ -1777,19 +1777,17 @@
 gth(8);%0A
-%09%09
 %0A
+
 %09%09subuni
@@ -1840,11 +1840,9 @@
 s);%0A
-%09%09
 %0A
+
 %09%09//
@@ -1975,18 +1975,17 @@
  9);%0A%09%7D%0A
-%09
 %0A
+
 %09/**%0A%09 *
@@ -2545,12 +2545,659 @@
 06);%0A%09%7D%0A
-%09
+%0A%09/**%0A%09 * Test that all chains from biological assemblies are extracted.%0A%09 */%0A%09@Test%0A%09public void testBioAssembly() throws StructureException, IOException %7B%0A%0A%09%09AtomCache cache = new AtomCache(); //TODO change to StructureIO%0A%09%09cache.setUseMmCif(true);%0A%09%09Structure s = cache.getStructure(%22BIO:4E3E:1%22);%0A%09%09%0A%09%09SubunitClustererParameters params = new SubunitClustererParameters();%0A%0A%09%09List%3CSubunit%3E subunits = SubunitExtractor.extractSubunits(s, params);%0A%0A%09%09// We expect all 3 equal double hot-dog subunits to be returned%0A%09%09assertEquals(subunits.size(), 3);%0A%09%09assertEquals(subunits.get(0).size(), subunits.get(1).size(), subunits%0A%09%09%09%09.get(2).size());%0A%09%7D%0A
 %0A%7D%0A

Test for bio assemblies in Subunit Extractor