Updated to the new readHeader(..) api
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3391 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
984c51efd3
commit
46ba88018d
|
|
@ -1,15 +1,17 @@
|
||||||
package org.broadinstitute.sting.gatk.refdata.features.sampileup;
|
package org.broadinstitute.sting.gatk.refdata.features.sampileup;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.broad.tribble.FeatureCodec;
|
import org.broad.tribble.FeatureCodec;
|
||||||
|
import org.broad.tribble.util.AsciiLineReader;
|
||||||
|
import org.broad.tribble.util.LineReader;
|
||||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||||
import org.broadinstitute.sting.utils.Utils;
|
import org.broadinstitute.sting.utils.Utils;
|
||||||
import org.broadinstitute.sting.utils.text.XReadLines;
|
|
||||||
|
|
||||||
public class AnnotatorInputTableCodec implements FeatureCodec<AnnotatorInputTableFeature> {
|
public class AnnotatorInputTableCodec implements FeatureCodec<AnnotatorInputTableFeature> {
|
||||||
|
|
||||||
|
|
@ -19,24 +21,20 @@ public class AnnotatorInputTableCodec implements FeatureCodec<AnnotatorInputTabl
|
||||||
|
|
||||||
private ArrayList<String> header;
|
private ArrayList<String> header;
|
||||||
|
|
||||||
private File file;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use this to parse out the header.
|
* Parses the header.
|
||||||
*
|
*
|
||||||
* @param f the file
|
* @param reader
|
||||||
*
|
*
|
||||||
* @return 0. Since we just read the header, the number of lines left to skip is 0.
|
* @return The # of header lines for this file.
|
||||||
*/
|
*/
|
||||||
public int headerLineCount(File f) {
|
public int readHeader(LineReader reader)
|
||||||
this.file = f;
|
{
|
||||||
|
|
||||||
int[] lineCounter = new int[1];
|
int[] lineCounter = new int[1];
|
||||||
try {
|
try {
|
||||||
|
header = readHeader(reader, lineCounter);
|
||||||
header = readHeader(f, lineCounter);
|
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new IllegalArgumentException("Unable to read from file " + f, e);
|
throw new IllegalArgumentException("Unable to read from file.", e);
|
||||||
}
|
}
|
||||||
return lineCounter[0];
|
return lineCounter[0];
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +77,12 @@ public class AnnotatorInputTableCodec implements FeatureCodec<AnnotatorInputTabl
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static ArrayList<String> readHeader(final File source) throws IOException {
|
public static ArrayList<String> readHeader(final File source) throws IOException {
|
||||||
return readHeader(source, null);
|
FileInputStream is = new FileInputStream(source);
|
||||||
|
try {
|
||||||
|
return readHeader(new AsciiLineReader(is), null);
|
||||||
|
} finally {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -90,28 +93,23 @@ public class AnnotatorInputTableCodec implements FeatureCodec<AnnotatorInputTabl
|
||||||
* @return The header fields.
|
* @return The header fields.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static ArrayList<String> readHeader(final File source, int[] lineCounter) throws IOException {
|
private static ArrayList<String> readHeader(final LineReader source, int[] lineCounter) throws IOException {
|
||||||
|
|
||||||
ArrayList<String> header = null;
|
ArrayList<String> header = null;
|
||||||
int numLines = 0;
|
int numLines = 0;
|
||||||
|
|
||||||
final XReadLines reader = new XReadLines(source);
|
//find the 1st line that's non-empty and not a comment
|
||||||
try {
|
String line = null;
|
||||||
//find the 1st line that's non-empty and not a comment
|
while( (line = source.readLine()) != null ) {
|
||||||
for ( String line : reader ) {
|
numLines++;
|
||||||
numLines++;
|
line = line.trim();
|
||||||
line = line.trim();
|
if ( line.isEmpty() || line.startsWith("#") ) {
|
||||||
if ( line.isEmpty() || line.startsWith("#") ) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//parse the header
|
|
||||||
header = Utils.split(line, DELIMITER);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally {
|
//parse the header
|
||||||
reader.close();
|
header = Utils.split(line, DELIMITER);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that we found the header
|
// check that we found the header
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue