Search in sources :

Example 6 with XReadLines

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.");
    }
}
Also used : XReadLines(org.broadinstitute.hellbender.utils.text.XReadLines) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with XReadLines

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;
}
Also used : XReadLines(org.broadinstitute.hellbender.utils.text.XReadLines)

Example 8 with XReadLines

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;
}
Also used : XReadLines(org.broadinstitute.hellbender.utils.text.XReadLines) UserException(org.broadinstitute.hellbender.exceptions.UserException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Aggregations

XReadLines (org.broadinstitute.hellbender.utils.text.XReadLines)8 File (java.io.File)4 UserException (org.broadinstitute.hellbender.exceptions.UserException)3 Test (org.testng.annotations.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 QueryInterval (htsjdk.samtools.QueryInterval)1 ReferenceSequenceFile (htsjdk.samtools.reference.ReferenceSequenceFile)1 Interval (htsjdk.samtools.util.Interval)1 IntervalList (htsjdk.samtools.util.IntervalList)1 DefaultedMap (org.apache.commons.collections4.map.DefaultedMap)1 CommandLineException (org.broadinstitute.barclay.argparser.CommandLineException)1 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)1 CachingIndexedFastaSequenceFile (org.broadinstitute.hellbender.utils.fasta.CachingIndexedFastaSequenceFile)1 ArgumentsBuilder (org.broadinstitute.hellbender.utils.test.ArgumentsBuilder)1