// Path: uk/ac/bbsrc/babraham/FastQC/Utilities/CasavaBasename.java
// public class CasavaBasename {
// 
// 	/**
// 	 * This method finds the core name from a CASAVA 1.8 fastq file.  It strips off the
// 	 * part which indicates that this file is one of a set and returns the base name with
// 	 * this part removed.
// 	 * 
// 	 * If the filename does not conform to standard CASAVA naming then a NameFormatException
// 	 * is thrown.
// 	 * 
// 	 * @param originalName
// 	 * @return
// 	 * @throws NameFormatException
// 	 */
// 	
// 	public static String getCasavaBasename (String originalName) throws NameFormatException {
// 		
// 		// Find the base name.  We need to remove the 123 numbers from
// 		// files of the form:
// 		//
// 		// anyold_text_123.fastq.gz
// 		//
// 		// where the base name will be
// 		//
// 		// anyoldtext.fastq.gz
// 		
// 		// The file must end with .fastq.gz
// 
// 		
// 		if (originalName.endsWith(".fastq.gz")) {
// 			
// 			// They must have an _ 13 chars before the end
// 			if (originalName.substring(originalName.length()-13, originalName.length()-12).equals("_")) {
// 				
// 				// They must have numbers for the 3 positions before .fastq
// 				try {
// 					Integer.parseInt(originalName.substring(originalName.length()-12, originalName.length()-9));
// 					
// 					// If we get here then everything is OK to use the base name from this file
// 					String baseName = originalName.substring(0,originalName.length()-13)+".fastq.gz";
// 					return baseName;
// 				}
// 				catch (NumberFormatException nfe) {}
// 			}
// 		}
// 		
// 		throw new NameFormatException();
// 	}
// 	
// 	public static File [][] getCasavaGroups (File [] files) {
// 		Hashtable<String, Vector<File>> fileBases = new Hashtable<String, Vector<File>>();
// 		
// 		for (int f=0;f<files.length;f++) {
// 
// 			// If a file forms part of a CASAVA group then put it into that
// 			// group.
// 			try {
// 				String baseName = CasavaBasename.getCasavaBasename(files[f].getName());
// 				if (! fileBases.containsKey(baseName)) {
// 					fileBases.put(baseName,new Vector<File>());
// 				}
// 				fileBases.get(baseName).add(files[f]);
// 
// 			}
// 			
// 			// If the file name doesn't appear to be part of a CASAVA group
// 			// then add it as a singleton
// 			catch (NameFormatException nfe) {
// 				
// 				System.err.println("File '"+files[f].getName()+"' didn't look like part of a CASAVA group");
// 				Vector<File> newVector = new Vector<File>();
// 				newVector.add(files[f]);
// 				fileBases.put(files[f].getName(), newVector);				
// 			}
// 			
// 		}
// 		
// 		String [] baseNames = fileBases.keySet().toArray(new String [0]);
// 		
// 		File [][] fileGroups = new File[baseNames.length][];
// 		
// 		for (int i=0;i<baseNames.length;i++) {
// 			fileGroups[i] = fileBases.get(baseNames[i]).toArray(new File[0]);
// 		}
// 		
// 		return fileGroups;		
// 	}
// 	
// }
// 
// Path: uk/ac/bbsrc/babraham/FastQC/Utilities/NameFormatException.java
// public class NameFormatException extends Exception {
// 
// }


import java.io.File;
import uk.ac.bbsrc.babraham.FastQC.Utilities.CasavaBasename;
import uk.ac.bbsrc.babraham.FastQC.Utilities.NameFormatException;

package uk.ac.bbsrc.babraham.FastQC.Sequence;



public class SequenceFileGroup implements SequenceFile {

	private SequenceFile [] files;
	private File groupFile;
	private int currentIndex = 0;
	
	public SequenceFileGroup (SequenceFile [] files) {
		this.files = files;
		try {

// Path: uk/ac/bbsrc/babraham/FastQC/Utilities/CasavaBasename.java
// public class CasavaBasename {
// 
// 	/**
// 	 * This method finds the core name from a CASAVA 1.8 fastq file.  It strips off the
// 	 * part which indicates that this file is one of a set and returns the base name with
// 	 * this part removed.
// 	 * 
// 	 * If the filename does not conform to standard CASAVA naming then a NameFormatException
// 	 * is thrown.
// 	 * 
// 	 * @param originalName
// 	 * @return
// 	 * @throws NameFormatException
// 	 */
// 	
// 	public static String getCasavaBasename (String originalName) throws NameFormatException {
// 		
// 		// Find the base name.  We need to remove the 123 numbers from
// 		// files of the form:
// 		//
// 		// anyold_text_123.fastq.gz
// 		//
// 		// where the base name will be
// 		//
// 		// anyoldtext.fastq.gz
// 		
// 		// The file must end with .fastq.gz
// 
// 		
// 		if (originalName.endsWith(".fastq.gz")) {
// 			
// 			// They must have an _ 13 chars before the end
// 			if (originalName.substring(originalName.length()-13, originalName.length()-12).equals("_")) {
// 				
// 				// They must have numbers for the 3 positions before .fastq
// 				try {
// 					Integer.parseInt(originalName.substring(originalName.length()-12, originalName.length()-9));
// 					
// 					// If we get here then everything is OK to use the base name from this file
// 					String baseName = originalName.substring(0,originalName.length()-13)+".fastq.gz";
// 					return baseName;
// 				}
// 				catch (NumberFormatException nfe) {}
// 			}
// 		}
// 		
// 		throw new NameFormatException();
// 	}
// 	
// 	public static File [][] getCasavaGroups (File [] files) {
// 		Hashtable<String, Vector<File>> fileBases = new Hashtable<String, Vector<File>>();
// 		
// 		for (int f=0;f<files.length;f++) {
// 
// 			// If a file forms part of a CASAVA group then put it into that
// 			// group.
// 			try {
// 				String baseName = CasavaBasename.getCasavaBasename(files[f].getName());
// 				if (! fileBases.containsKey(baseName)) {
// 					fileBases.put(baseName,new Vector<File>());
// 				}
// 				fileBases.get(baseName).add(files[f]);
// 
// 			}
// 			
// 			// If the file name doesn't appear to be part of a CASAVA group
// 			// then add it as a singleton
// 			catch (NameFormatException nfe) {
// 				
// 				System.err.println("File '"+files[f].getName()+"' didn't look like part of a CASAVA group");
// 				Vector<File> newVector = new Vector<File>();
// 				newVector.add(files[f]);
// 				fileBases.put(files[f].getName(), newVector);				
// 			}
// 			
// 		}
// 		
// 		String [] baseNames = fileBases.keySet().toArray(new String [0]);
// 		
// 		File [][] fileGroups = new File[baseNames.length][];
// 		
// 		for (int i=0;i<baseNames.length;i++) {
// 			fileGroups[i] = fileBases.get(baseNames[i]).toArray(new File[0]);
// 		}
// 		
// 		return fileGroups;		
// 	}
// 	
// }
// 
// Path: uk/ac/bbsrc/babraham/FastQC/Utilities/NameFormatException.java
// public class NameFormatException extends Exception {
// 
// }


// Path: uk/ac/bbsrc/babraham/FastQC/Sequence/SequenceFileGroup.java
import java.io.File;
import uk.ac.bbsrc.babraham.FastQC.Utilities.CasavaBasename;
import uk.ac.bbsrc.babraham.FastQC.Utilities.NameFormatException;

package uk.ac.bbsrc.babraham.FastQC.Sequence;



public class SequenceFileGroup implements SequenceFile {

	private SequenceFile [] files;
	private File groupFile;
	private int currentIndex = 0;
	
	public SequenceFileGroup (SequenceFile [] files) {
		this.files = files;
		try {

			String baseName = CasavaBasename.getCasavaBasename(files[0].name());
