Esempio n. 1
0
  private Collection<VariantContext> getVariantContexts(
      RefMetaDataTracker tracker, ReferenceContext ref) {

    List<Feature> features = tracker.getValues(variants, ref.getLocus());
    List<VariantContext> VCs = new ArrayList<VariantContext>(features.size());

    for (Feature record : features) {
      if (VariantContextAdaptors.canBeConvertedToVariantContext(record)) {
        // we need to special case the HapMap format because indels aren't handled correctly
        if (record instanceof RawHapMapFeature) {

          // is it an indel?
          RawHapMapFeature hapmap = (RawHapMapFeature) record;
          if (hapmap.getAlleles()[0].equals(RawHapMapFeature.NULL_ALLELE_STRING)
              || hapmap.getAlleles()[1].equals(RawHapMapFeature.NULL_ALLELE_STRING)) {
            // get the dbsnp object corresponding to this record (needed to help us distinguish
            // between insertions and deletions)
            VariantContext dbsnpVC = getDbsnp(hapmap.getName());
            if (dbsnpVC == null || dbsnpVC.isMixed()) continue;

            Map<String, Allele> alleleMap = new HashMap<String, Allele>(2);
            alleleMap.put(
                RawHapMapFeature.DELETION,
                Allele.create(ref.getBase(), dbsnpVC.isSimpleInsertion()));
            alleleMap.put(
                RawHapMapFeature.INSERTION,
                Allele.create(
                    (char) ref.getBase() + ((RawHapMapFeature) record).getAlleles()[1],
                    !dbsnpVC.isSimpleInsertion()));
            hapmap.setActualAlleles(alleleMap);

            // also, use the correct positioning for insertions
            hapmap.updatePosition(dbsnpVC.getStart());

            if (hapmap.getStart() < ref.getWindow().getStart()) {
              logger.warn(
                  "Hapmap record at "
                      + ref.getLocus()
                      + " represents an indel too large to be converted; skipping...");
              continue;
            }
          }
        }

        // ok, we might actually be able to turn this record in a variant context
        VariantContext vc =
            VariantContextAdaptors.toVariantContext(variants.getName(), record, ref);

        if (vc != null) // sometimes the track has odd stuff in it that can't be converted
        VCs.add(vc);
      }
    }

    return VCs;
  }
  // decide whether we are currently processing SNPs, indels, neither, or both
  private List<GenotypeLikelihoodsCalculationModel.Model> getGLModelsToUse(
      final RefMetaDataTracker tracker,
      final ReferenceContext refContext,
      final AlignmentContext rawContext) {

    final List<GenotypeLikelihoodsCalculationModel.Model> models =
        new ArrayList<GenotypeLikelihoodsCalculationModel.Model>(2);
    String modelPrefix = "";
    if (UAC.GLmodel.name().toUpperCase().contains("BOTH"))
      modelPrefix = UAC.GLmodel.name().toUpperCase().replaceAll("BOTH", "");

    if (!UAC.GLmodel.name().contains(GPSTRING)
        && UAC.samplePloidy != VariantContextUtils.DEFAULT_PLOIDY)
      modelPrefix = GPSTRING + modelPrefix;

    // if we're genotyping given alleles and we have a requested SNP at this position, do SNP
    if (UAC.GenotypingMode
        == GenotypeLikelihoodsCalculationModel.GENOTYPING_MODE.GENOTYPE_GIVEN_ALLELES) {
      final VariantContext vcInput =
          getVCFromAllelesRod(
              tracker, refContext, rawContext.getLocation(), false, logger, UAC.alleles);
      if (vcInput == null) return models;

      if (vcInput.isSNP()) {
        // ignore SNPs if the user chose INDEL mode only
        if (UAC.GLmodel.name().toUpperCase().contains("BOTH")
            || UAC.GLmodel.name().toUpperCase().contains("SNP"))
          models.add(GenotypeLikelihoodsCalculationModel.Model.valueOf(modelPrefix + "SNP"));
      } else if (vcInput.isIndel() || vcInput.isMixed()) {
        // ignore INDELs if the user chose SNP mode only
        if (UAC.GLmodel.name().toUpperCase().contains("BOTH")
            || UAC.GLmodel.name().toUpperCase().contains("INDEL"))
          models.add(GenotypeLikelihoodsCalculationModel.Model.valueOf(modelPrefix + "INDEL"));
      }
      // No support for other types yet
    } else {
      if (UAC.GLmodel.name().toUpperCase().contains("BOTH")) {
        models.add(GenotypeLikelihoodsCalculationModel.Model.valueOf(modelPrefix + "SNP"));
        models.add(GenotypeLikelihoodsCalculationModel.Model.valueOf(modelPrefix + "INDEL"));
      } else {
        models.add(
            GenotypeLikelihoodsCalculationModel.Model.valueOf(
                modelPrefix + UAC.GLmodel.name().toUpperCase()));
      }
    }

    return models;
  }