Search in sources :

Example 1 with ACGLogReader

use of bacter.util.ACGLogReader in project bacter by tgvaughan.

the class DifferenceFromTrueACG method main.

public static void main(String[] args) throws IOException, XMLStreamException {
    Options options = processArguments(args);
    // Load true ARG
    BacterACGLogReader truthReader = new BacterACGLogReader(options.truthFile, 0);
    if (truthReader.getACGCount() != 1) {
        System.out.println("Expected exactly 1 ACG in truth file. Found " + truthReader.getACGCount());
        System.exit(1);
    }
    ConversionGraph trueACG = null;
    for (ConversionGraph acg : truthReader) trueACG = acg;
    // Determine clades present in truth
    Clade[] trueClades = new Clade[trueACG.getNodeCount()];
    getClades(trueClades, trueACG.getRoot());
    Set<Clade> trueCladeSet = new HashSet<>(Arrays.asList(trueClades));
    // Set up histograms
    Map<Clade, Integer> cladeHist = new HashMap<>();
    for (Clade clade : trueClades) cladeHist.put(clade, 0);
    Map<Conversion, Integer> convHist = new HashMap<>();
    for (Conversion conv : trueACG.getConversions(trueACG.getLoci().get(0))) convHist.put(conv, 0);
    // Set up ARG log file reader
    ACGLogReader logReader;
    if (options.useCOFormat) {
        logReader = new COACGLogFileReader(options.logFile, options.burninPerc);
    } else {
        logReader = new BacterACGLogReader(options.logFile, options.burninPerc);
    }
    try (PrintStream ps = new PrintStream(options.outFile)) {
        ps.println("trueCladeCount sampledTrueCladeCount trueConvCount sampledConvCount sampledTrueConvCount");
        for (ConversionGraph acg : logReader) {
            Clade[] clades = new Clade[acg.getNodeCount()];
            getClades(clades, acg.getRoot());
            List<Double> timeErrors = new ArrayList<>();
            int sampledTrueClades = countSampledTrueClades(trueClades, clades, options.ageTol, cladeHist);
            int sampledTrueConvs = countSampledTrueConversions(trueACG, trueClades, acg, clades, options.boundaryTol, options.ageTol, convHist);
            ps.println(trueACG.getNodeCount() + "\t" + sampledTrueClades + "\t" + trueACG.getConvCount(trueACG.getLoci().get(0)) + "\t" + acg.getConvCount(acg.getLoci().get(0)) + "\t" + sampledTrueConvs);
        }
    }
    try (PrintStream ps = new PrintStream(options.summaryFile)) {
        ps.println("trueCladeCount recoveredCladeCount trueConvCount recoveredConvCount");
        int recoveredTrueClades = countRecoveredTrueClades(cladeHist, logReader.getCorrectedACGCount(), 0.5);
        int recoveredTrueConvs = countRecoveredTrueConvs(convHist, logReader.getCorrectedACGCount(), 0.5);
        ps.println(trueACG.getNodeCount() + "\t" + recoveredTrueClades + "\t" + trueACG.getConvCount(trueACG.getLoci().get(0)) + "\t" + recoveredTrueConvs);
    }
}
Also used : PrintStream(java.io.PrintStream) COACGLogFileReader(bacter.util.COACGLogFileReader) BacterACGLogReader(bacter.util.BacterACGLogReader) ConversionGraph(bacter.ConversionGraph) Conversion(bacter.Conversion) BacterACGLogReader(bacter.util.BacterACGLogReader) ACGLogReader(bacter.util.ACGLogReader)

Aggregations

Conversion (bacter.Conversion)1 ConversionGraph (bacter.ConversionGraph)1 ACGLogReader (bacter.util.ACGLogReader)1 BacterACGLogReader (bacter.util.BacterACGLogReader)1 COACGLogFileReader (bacter.util.COACGLogFileReader)1 PrintStream (java.io.PrintStream)1