Add an InputStream constructor, which is immensely useful for various reasons.
Also a minor performance optimization. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2201 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
e581cceab6
commit
adf8f1f8b3
|
|
@ -38,8 +38,26 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
|
||||||
else
|
else
|
||||||
openTextVersion(vcfFile);
|
openTextVersion(vcfFile);
|
||||||
|
|
||||||
String line = null;
|
this.parseHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a VCF reader, given a stream.
|
||||||
|
*
|
||||||
|
* @param stream the stream file read
|
||||||
|
*/
|
||||||
|
public VCFReader (InputStream stream)
|
||||||
|
{
|
||||||
|
mReader = new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
|
stream,
|
||||||
|
Charset.forName("UTF-8")));
|
||||||
|
this.parseHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseHeader()
|
||||||
|
{
|
||||||
|
String line = null;
|
||||||
// try and parse the header
|
// try and parse the header
|
||||||
try {
|
try {
|
||||||
ArrayList<String> lines = new ArrayList<String>();
|
ArrayList<String> lines = new ArrayList<String>();
|
||||||
|
|
@ -53,7 +71,7 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("VCFReader: Failed to parse VCF File on line: " + line, e);
|
throw new RuntimeException("VCFReader: Failed to parse VCF File on line: " + line, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* open a g-zipped version of the VCF format
|
* open a g-zipped version of the VCF format
|
||||||
|
|
@ -190,9 +208,10 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
|
||||||
String mFormatString = tokens[index];
|
String mFormatString = tokens[index];
|
||||||
List<VCFGenotypeRecord> genotypeRecords = new ArrayList<VCFGenotypeRecord>();
|
List<VCFGenotypeRecord> genotypeRecords = new ArrayList<VCFGenotypeRecord>();
|
||||||
index++;
|
index++;
|
||||||
|
String[] alt_alleles = values.get(VCFHeader.HEADER_FIELDS.ALT).split(",");
|
||||||
for (String str : mHeader.getGenotypeSamples()) {
|
for (String str : mHeader.getGenotypeSamples()) {
|
||||||
if (!tokens[index].equalsIgnoreCase(VCFGenotypeRecord.EMPTY_GENOTYPE))
|
if (!tokens[index].equalsIgnoreCase(VCFGenotypeRecord.EMPTY_GENOTYPE))
|
||||||
genotypeRecords.add(getVCFGenotype(str, mFormatString, tokens[index], values.get(VCFHeader.HEADER_FIELDS.ALT).split(","), values.get(VCFHeader.HEADER_FIELDS.REF).charAt(0)));
|
genotypeRecords.add(getVCFGenotype(str, mFormatString, tokens[index], alt_alleles, values.get(VCFHeader.HEADER_FIELDS.REF).charAt(0)));
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return new VCFRecord(values, mFormatString, genotypeRecords);
|
return new VCFRecord(values, mFormatString, genotypeRecords);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue