use of org.broadinstitute.hellbender.utils.text.XReadLines in project gatk by broadinstitute.
the class GitLfsTest method testLargeFilesAreDownloaded.
@Test(groups = "large")
public void testLargeFilesAreDownloaded() throws IOException {
File exampleLargeFile = new File(publicTestDir, "large/exampleLargeFile.txt");
Assert.assertTrue(exampleLargeFile.exists(), "Expected file:" + exampleLargeFile.getAbsoluteFile() + " to exist but it didn't");
try (XReadLines lines = new XReadLines(exampleLargeFile)) {
Assert.assertEquals(lines.next(), "This is a file to test if git-lfs is working. Please don't change this text.");
}
}
use of org.broadinstitute.hellbender.utils.text.XReadLines in project gatk by broadinstitute.
the class Tranche method readTranches.
/**
* Returns a list of tranches, sorted from most to least specific, read in from file f.
* @throws IOException if there are problems reading the file.
*/
public static List<Tranche> readTranches(final File f) throws IOException {
String[] header = null;
List<Tranche> tranches = new ArrayList<>();
try (XReadLines xrl = new XReadLines(f)) {
for (final String line : xrl) {
if (line.startsWith(COMMENT_STRING)) {
continue;
}
final String[] vals = line.split(VALUE_SEPARATOR);
if (header == null) {
//reading the header
header = vals;
if (header.length != EXPECTED_COLUMN_COUNT) {
throw new UserException.MalformedFile(f, "Expected 11 elements in header line " + line);
}
} else {
if (header.length != vals.length) {
throw new UserException.MalformedFile(f, "Line had too few/many fields. Header = " + header.length + " vals " + vals.length + ". The line was: " + line);
}
Map<String, String> bindings = new LinkedHashMap<>();
for (int i = 0; i < vals.length; i++) {
bindings.put(header[i], vals[i]);
}
tranches.add(new Tranche(getRequiredDouble(bindings, "targetTruthSensitivity"), getRequiredDouble(bindings, "minVQSLod"), getOptionalInteger(bindings, "numKnown", -1), getOptionalDouble(bindings, "knownTiTv", -1.0), getRequiredInteger(bindings, "numNovel"), getRequiredDouble(bindings, "novelTiTv"), getOptionalInteger(bindings, "accessibleTruthSites", -1), getOptionalInteger(bindings, "callsAtTruthSites", -1), VariantRecalibratorArgumentCollection.Mode.valueOf(bindings.get("model")), bindings.get("filterName")));
}
}
}
tranches.sort(TRUTH_SENSITIVITY_ORDER);
return tranches;
}
use of org.broadinstitute.hellbender.utils.text.XReadLines in project gatk by broadinstitute.
the class PedReader method parse.
public final List<Sample> parse(Reader reader, EnumSet<MissingPedField> missingFields, SampleDB sampleDB) {
// Determine field position ordinals
final int familyPos = missingFields.contains(MissingPedField.NO_FAMILY_ID) ? -1 : 0;
final int samplePos = familyPos + 1;
final int paternalPos = missingFields.contains(MissingPedField.NO_PARENTS) ? -1 : samplePos + 1;
final int maternalPos = missingFields.contains(MissingPedField.NO_PARENTS) ? -1 : paternalPos + 1;
final int sexPos = missingFields.contains(MissingPedField.NO_SEX) ? -1 : Math.max(maternalPos, samplePos) + 1;
final int phenotypePos = missingFields.contains(MissingPedField.NO_PHENOTYPE) ? -1 : Math.max(sexPos, Math.max(maternalPos, samplePos)) + 1;
final int nExpectedFields = IntStream.of(samplePos, paternalPos, maternalPos, sexPos, phenotypePos).max().getAsInt() + 1;
List<String> lines;
try (final XReadLines sourceReader = new XReadLines(reader, false, commentMarker)) {
lines = sourceReader.readLines();
} catch (IOException e) {
throw new UserException.CouldNotReadInputFile("Error reading pedigree input");
}
final List<String[]> lineParts = splitLines(reader, lines, nExpectedFields);
boolean isQT = isQT(lineParts, phenotypePos);
int lineNo = 1;
final List<Sample> samples = new ArrayList<>(lineParts.size());
for (final String[] parts : lineParts) {
String individualID = parts[samplePos];
String familyID = familyPos == -1 ? null : maybeMissing(parts[familyPos]);
String paternalID = paternalPos == -1 ? null : maybeMissing(parts[paternalPos]);
String maternalID = maternalPos == -1 ? null : maybeMissing(parts[maternalPos]);
Sex sex = determineSex(parts, sexPos);
Affection affection = Affection.UNKNOWN;
String quantitativePhenotype = null;
if (phenotypePos != -1) {
if (isQT) {
if (parts[phenotypePos].equals(MISSING_VALUE1)) {
affection = Affection.UNKNOWN;
} else {
affection = Affection.OTHER;
quantitativePhenotype = parts[phenotypePos];
}
} else {
switch(parts[phenotypePos]) {
case MISSING_VALUE1:
affection = Affection.UNKNOWN;
break;
case MISSING_VALUE2:
affection = Affection.UNKNOWN;
break;
case PHENOTYPE_UNAFFECTED:
affection = Affection.UNAFFECTED;
break;
case PHENOTYPE_AFFECTED:
affection = Affection.AFFECTED;
break;
default:
throw new GATKException("Unexpected phenotype type " + parts[phenotypePos] + " at line " + lineNo);
}
}
}
final Sample s = new Sample(individualID, familyID, paternalID, maternalID, sex, affection);
samples.add(s);
sampleDB.addSample(s);
lineNo++;
}
for (final Sample sample : new ArrayList<>(samples)) {
final Sample dad = maybeAddImplicitSample(sampleDB, sample.getPaternalID(), sample.getFamilyID(), Sex.MALE);
if (dad != null) {
samples.add(dad);
}
final Sample mom = maybeAddImplicitSample(sampleDB, sample.getMaternalID(), sample.getFamilyID(), Sex.FEMALE);
if (mom != null) {
samples.add(mom);
}
}
return samples;
}
Aggregations