<commit_before>package fi.csc.microarray.analyser.bsh;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import fi.csc.microarray.util.IOUtils;

/**
 * Utilities to be used by Java and BeanShell jobs.
 * 
 * 
 * @author hupponen
 *
 */
public class JavaJobUtils {

	/**
	 * Get the gene names from GENELIST type of input file.
	 * 
	 * If there is only one column, use it. If there are many columns,
	 * search for "symbol" column, if not found, search for " " column.
	 * 
	 * @param file
	 * @return the gene names, empty String[] if the file is empty or gene names are not found
	 * @throws IOException
	 */
	public static String[] getGeneNames(File file) throws IOException {

		List<String> names = new LinkedList<String>();
		BufferedReader reader = new BufferedReader(new FileReader(file));
		try {
			String line;
			String[] columns;
			int nameColumnIndex = 0;
			line = reader.readLine();

			// empty file
			if (line == null) {
				return new String[0];
			}
			
			// split first line
			columns = line.split("\t");
			
			// only one column
			if (columns.length == 1) {
				nameColumnIndex = 0;
			} 
				
			// many columns, find the gene names column
			else if ( columns.length > 1) {
				// search for symbol column
				nameColumnIndex = Arrays.asList(columns).indexOf("symbol");

				// symbol not found, search for "" column
				if (nameColumnIndex < 0) {
					nameColumnIndex = Arrays.asList(columns).indexOf(" ");

					// "" not found, give up
					if (nameColumnIndex < 0) {
						return new String[0];
					}
				}
			}				
			
			
			// read in the rest of the file
			for (line = reader.readLine(); line != null; line = reader.readLine()) {
				names.add(line.split("\t")[nameColumnIndex]);
			}
		} finally {
			IOUtils.closeIfPossible(reader);
		}

		return names.toArray(new String[names.size()]);
	}

}<commit_msg>fixed index handling<commit_after>package fi.csc.microarray.analyser.bsh;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import fi.csc.microarray.util.IOUtils;

/**
 * Utilities to be used by Java and BeanShell jobs.
 * 
 * 
 * @author <NAME>, <NAME>
 *
 */
// TODO partly duplicates functionality in Feature API, but do we want to start using DataManager and DataBeans here?
public class JavaJobUtils {

	/**
	 * Get the gene names from GENELIST type of input file.
	 * 
	 * If there is only one column, use it. If there are many columns,
	 * search for "symbol" column, if not found, search for " " and "identifier" columns.
	 * 
	 * @param file
	 * @return the gene names, empty String[] if the file is empty or gene names are not found
	 * @throws IOException
	 */
	public static String[] getGeneNames(File file) throws IOException {

		List<String> names = new LinkedList<String>();
		BufferedReader reader = new BufferedReader(new FileReader(file));
		try {
			String line;
			String[] columns;
			int nameColumnIndex = 0;
			line = reader.readLine();

			// empty file
			if (line == null) {
				return new String[0];
			}
			
			// split first line
			columns = line.split("\t");
			
			// only one column
			if (columns.length == 1) {
				nameColumnIndex = 0;
			} 
				
			// many columns, find the gene names column
			else if ( columns.length > 1) {
				// search for symbol column
				nameColumnIndex = Arrays.asList(columns).indexOf("symbol");

				// symbol not found, search for "" column
				if (nameColumnIndex < 0) {
					nameColumnIndex = Arrays.asList(columns).indexOf(" ");

					if (nameColumnIndex < 0) {
						nameColumnIndex = Arrays.asList(columns).indexOf("identifier");

						// "" not found, give up
						if (nameColumnIndex < 0) {
							return new String[0];
						}
					}
				}
			}				
			
			
			// read in the rest of the file
			boolean firstLine = true;
			for (line = reader.readLine(); line != null; line = reader.readLine()) {
				if (firstLine) {
					// check that column count is not different from header due to invisible row name column
					if (line.split("\t").length == (columns.length + 1)) {
						// if it is, correct for it
						nameColumnIndex++;
					}
				}
				firstLine = false;
				names.add(line.split("\t")[nameColumnIndex]);
			}
		} finally {
			IOUtils.closeIfPossible(reader);
		}

		return names.toArray(new String[names.size()]);
	}
}
{'fraction_non_alphanumeric': 0.11994698475811796, 'fraction_numerical': 0.003976143141153081, 'mean_word_length': 2.8405428329092453, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, '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': '1563573', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1376, 'n_words': 443}