Search in sources :

Example 1 with Status

use of com.github.lindenb.jvarkit.pedigree.Status in project jvarkit by lindenb.

the class SwingVCFGenotypesTableModel method setRows.

@Override
public synchronized void setRows(final List<Genotype> genotypes) {
    if (genotypes == null) {
        setRows(Collections.emptyList());
    }
    this.columns.clear();
    final Vector<ColumnInfo> columns = new Vector<>();
    ColumnInfo ci = new ColumnInfo();
    ci.clazz = String.class;
    ci.name = "Sample";
    ci.extractor = GT -> GT.getSampleName();
    columns.add(ci);
    if (this.pedigree != null) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = "Status";
        ci.extractor = GT -> {
            final Sample sn = this.pedigree.getSampleById(GT.getSampleName());
            if (sn == null || !sn.isStatusSet())
                return null;
            if (sn.getStatus().equals(Status.affected))
                return "[*]";
            if (sn.getStatus().equals(Status.unaffected))
                return "[ ]";
            return null;
        };
        columns.add(ci);
    }
    if (genotypes.stream().anyMatch(G -> G.isAvailable())) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = VCFConstants.GENOTYPE_KEY;
        ci.extractor = GT -> GT.getAlleles().stream().map(A -> A.getDisplayString()).collect(Collectors.joining(GT.isPhased() ? Genotype.PHASED_ALLELE_SEPARATOR : Genotype.UNPHASED_ALLELE_SEPARATOR));
        columns.add(ci);
    }
    ci = new ColumnInfo();
    ci.clazz = String.class;
    ci.name = "Type";
    ci.extractor = GT -> GT.getType().name();
    columns.add(ci);
    if (genotypes.stream().anyMatch(G -> G.hasDP())) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = VCFConstants.DEPTH_KEY;
        ci.extractor = GT -> GT.hasDP() ? GT.getDP() : null;
        columns.add(ci);
    }
    if (genotypes.stream().anyMatch(G -> G.hasGQ())) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = VCFConstants.GENOTYPE_QUALITY_KEY;
        ci.extractor = GT -> GT.hasGQ() ? GT.getGQ() : null;
        columns.add(ci);
    }
    if (genotypes.stream().anyMatch(G -> G.hasAD())) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = VCFConstants.GENOTYPE_ALLELE_DEPTHS;
        ci.extractor = GT -> GT.hasAD() ? Arrays.stream(GT.getAD()).mapToObj(P -> String.valueOf(P)).collect(Collectors.joining(",")) : null;
        columns.add(ci);
    }
    if (genotypes.stream().anyMatch(G -> G.hasPL())) {
        ci = new ColumnInfo();
        ci.clazz = String.class;
        ci.name = VCFConstants.GENOTYPE_PL_KEY;
        ci.extractor = GT -> GT.hasPL() ? Arrays.stream(GT.getPL()).mapToObj(P -> String.valueOf(P)).collect(Collectors.joining(",")) : null;
        columns.add(ci);
    }
    for (final String att : genotypes.stream().flatMap(G -> G.getExtendedAttributes().keySet().stream()).collect(Collectors.toSet())) {
        ci = new ColumnInfo();
        ci.clazz = Object.class;
        ci.name = att;
        ci.extractor = GT -> GT.hasExtendedAttribute(att) ? GT.getExtendedAttribute(att) : null;
        columns.add(ci);
    }
    this.columns.addAll(columns);
    super.rows.clear();
    super.rows.addAll(genotypes);
    fireTableStructureChanged();
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) AbstractGenericTable(com.github.lindenb.jvarkit.util.swing.AbstractGenericTable) Arrays(java.util.Arrays) Pedigree(com.github.lindenb.jvarkit.pedigree.Pedigree) Status(com.github.lindenb.jvarkit.pedigree.Status) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) List(java.util.List) Vector(java.util.Vector) VariantContext(htsjdk.variant.variantcontext.VariantContext) Collections(java.util.Collections) Sample(com.github.lindenb.jvarkit.pedigree.Sample) VCFConstants(htsjdk.variant.vcf.VCFConstants) Sample(com.github.lindenb.jvarkit.pedigree.Sample) Vector(java.util.Vector)

Aggregations

Pedigree (com.github.lindenb.jvarkit.pedigree.Pedigree)1 Sample (com.github.lindenb.jvarkit.pedigree.Sample)1 Status (com.github.lindenb.jvarkit.pedigree.Status)1 AbstractGenericTable (com.github.lindenb.jvarkit.util.swing.AbstractGenericTable)1 Genotype (htsjdk.variant.variantcontext.Genotype)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1 VCFConstants (htsjdk.variant.vcf.VCFConstants)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Vector (java.util.Vector)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1