@@ -0,0 +1,2570 @@
+package org.opencb.biodata.models.variant;%0A%0Aimport org.opencb.biodata.models.variant.stats.VariantStats;%0A%0A/**%0A * @author Alejandro Aleman Ramos %3Caaleman@cipf.es%3E%0A * @author Cristina Yenyxe Gonzalez Garcia %3Ccyenyxe@ebi.ac.uk%3E%0A */%0Apublic class VariantAggregatedVcfFactory extends VariantVcfFactory %7B%0A%0A%0A    @Override%0A    protected void setOtherFields(Variant variant, VariantSource source, String id, float quality, String filter, String info, String format, int numAllele, String%5B%5D alternateAlleles) %7B%0A        // Fields not affected by the structure of REF and ALT fields%0A        variant.setId(id);%0A        if (quality %3E -1) %7B%0A            variant.getFile(source.getFileId(), source.getStudyId()).addAttribute(%22QUAL%22, String.valueOf(quality));%0A        %7D%0A        if (!filter.isEmpty()) %7B%0A            variant.getFile(source.getFileId(), source.getStudyId()).addAttribute(%22FILTER%22, filter);%0A        %7D%0A        if (!info.isEmpty()) %7B%0A            parseInfo(variant, source.getFileId(), source.getStudyId(), info);%0A        %7D%0A        variant.getFile(source.getFileId(), source.getStudyId()).setFormat(format);%0A%0A        addStats(variant, source, numAllele, alternateAlleles);%0A    %7D%0A%0A    private void addStats(Variant variant, VariantSource source, int numAllele, String%5B%5D alternateAlleles) %7B%0A%0A        ArchivedVariantFile file = variant.getFile(source.getFileId(), source.getStudyId());%0A%0A        if (file.hasAttribute(%22AN%22) && file.hasAttribute(%22AC%22)) %7B%0A            int total = Integer.parseInt(file.getAttribute(%22AN%22));%0A            String%5B%5D alleleCountString = file.getAttribute(%22AC%22).split(%22,%22);%0A%0A            if (alleleCountString.length != alternateAlleles.length) %7B%0A                return;%0A            %7D%0A%0A            int%5B%5D alleleCount = new int%5BalleleCountString.length%5D;%0A%0A            String mafAllele = variant.getReference();%0A            int referenceCount = total;%0A%0A            for (int i = 0; i %3C alleleCountString.length; i++) %7B%0A                alleleCount%5Bi%5D = Integer.parseInt(alleleCountString%5Bi%5D);%0A                referenceCount -= alleleCount%5Bi%5D;%0A            %7D%0A%0A            float maf = (float) referenceCount / total;%0A%0A            for (int i = 0; i %3C alleleCount.length; i++) %7B%0A                float auxMaf = (float) alleleCount%5Bi%5D / total;%0A                if (auxMaf %3C maf) %7B%0A                    maf = auxMaf;%0A                    mafAllele = alternateAlleles%5Bi%5D;%0A                %7D%0A            %7D%0A%0A            VariantStats vs = new VariantStats();%0A%0A            vs.setMaf(maf);%0A            vs.setMafAllele(mafAllele);%0A%0A            file.setStats(vs);%0A        %7D%0A%0A%0A    %7D%0A%0A%7D%0A

Create new VariantAggregatedFactory for aggregated Vcfs. This factory loads Maf/AlleleMAf (from attributes) into stats