org.broadinstitute.gatk.utils.Utils.dupString()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(15.9k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.broadinstitute.gatk.utils.Utils.dupString()方法的一些代码示例,展示了Utils.dupString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.dupString()方法的具体详情如下:
包路径:org.broadinstitute.gatk.utils.Utils
类名称:Utils
方法名:dupString

Utils.dupString介绍

[英]Create a new string thats a n duplicate copies of s
[中]创建一个新字符串,它是s的n个副本

代码示例

代码示例来源:origin: broadgsa/gatk

public String toString() {
    StringBuilder s = new StringBuilder();
    s.append(Utils.dupString('-', 80) + "\n");
    s.append(String.format("Number of examined reads              %d%n", nTotalReads));
    s.append(String.format("Number of clipped reads               %d%n", nClippedReads));
    s.append(String.format("Percent of clipped reads              %.2f%n", (100.0 * nClippedReads) / nTotalReads));
    s.append(String.format("Number of examined bases              %d%n", nTotalBases));
    s.append(String.format("Number of clipped bases               %d%n", nClippedBases));
    s.append(String.format("Percent of clipped bases              %.2f%n", (100.0 * nClippedBases) / nTotalBases));
    s.append(String.format("Number of quality-score clipped bases %d%n", nQClippedBases));
    s.append(String.format("Number of range clipped bases         %d%n", nRangeClippedBases));
    s.append(String.format("Number of sequence clipped bases      %d%n", nSeqClippedBases));
    for (Map.Entry<String, Long> elt : seqClipCounts.entrySet()) {
      s.append(String.format("  %8d clip sites matching %s%n", elt.getValue(), elt.getKey()));
    }
    s.append(Utils.dupString('-', 80) + "\n");
    return s.toString();
  }
}

代码示例来源:origin: broadgsa/gatk

@Override
public String toString(int offset) {
  String off = offset > 0 ? Utils.dupString(' ', offset) : "";
  StringBuilder b = new StringBuilder();
  b.append("(").append("\n");
  Collection<DiffElement> atomicElts = getAtomicElements();
  for ( DiffElement elt : atomicElts ) {
    b.append(elt.toString(offset + 2)).append('\n');
  }
  for ( DiffElement elt : getCompoundElements() ) {
    b.append(elt.toString(offset + 4)).append('\n');
  }
  b.append(off).append(")").append("\n");
  return b.toString();
}

代码示例来源:origin: broadgsa/gatk

@Test
public void testDupStringNoChars() {
  String duped = Utils.dupString('a',0);
  Assert.assertEquals(duped.length(), 0, "dupString did not produce zero-length string");
}

代码示例来源:origin: broadgsa/gatk

@Test
public void testDupStringMultiChar() {
  String duped = Utils.dupString('c',5);
  Assert.assertEquals(duped.length(), 5, "dupString did not produce five character string");
  Assert.assertEquals(duped,"ccccc","dupString string was incorrect");
}

代码示例来源:origin: broadgsa/gatk

@Test
public void testDupStringOneChar() {
  String duped = Utils.dupString('b',1);
  Assert.assertEquals(duped.length(), 1, "dupString did not produce single character string");
  Assert.assertEquals(duped.charAt(0), 'b', "dupString character was incorrect");
}

代码示例来源:origin: broadgsa/gatk-protected

private String generateSeq(final int len) {
  final List<String> root = Arrays.asList("A", "C", "G", "T");
  String seq = "";
  for ( int i = 0; true; i++ ) {
    final String base = root.get(i % root.size());
    final int copies = i / root.size() + 1;
    seq += Utils.dupString(base, copies);
    if ( seq.length() >= len )
      return seq.substring(0, len);
  }
}

代码示例来源:origin: broadgsa/gatk

@Override protected void setUp() {
  final StringBuilder ref = new StringBuilder();
  final StringBuilder hap = new StringBuilder();
  ref.append(Utils.dupString('A', sizeOfEndRegions));
  hap.append(Utils.dupString('A', sizeOfEndRegions));
  // introduce a SNP
  ref.append("X");
  hap.append("Y");
  ref.append(Utils.dupString('A', sizeOfMiddleRegion));
  hap.append(Utils.dupString('A', sizeOfMiddleRegion));
  // introduce a SNP
  ref.append("X");
  hap.append("Y");
  ref.append(Utils.dupString('A', sizeOfEndRegions));
  hap.append(Utils.dupString('A', sizeOfEndRegions));
  refString = ref.toString();
  hapString = hap.toString();
}

代码示例来源:origin: broadgsa/gatk

public String toString(int offset) {
  return (offset > 0 ? Utils.dupString(' ', offset) : 0) + getName() + "=" + getValue().toString(offset);
}

代码示例来源:origin: broadgsa/gatk-protected

@DataProvider(name = "HMMProviderWithBigReads")
public Object[][] makeBigReadHMMProvider() {
  List<Object[]> tests = new ArrayList<Object[]>();
  final String read1 = "ACCAAGTAGTCACCGT";
  final String ref1  = "ACCAAGTAGTCACCGTAACG";
  for ( final int nReadCopies : Arrays.asList(1, 2, 10, 20, 50) ) {
    for ( final int nRefCopies : Arrays.asList(1, 2, 10, 20, 100) ) {
      if ( nRefCopies > nReadCopies ) {
        for ( final PairHMM hmm : getHMMs() ) {
          final String read = Utils.dupString(read1, nReadCopies);
          final String ref  = Utils.dupString(ref1, nRefCopies);
          tests.add(new Object[]{hmm, read, ref});
        }
      }
    }
  }
  return tests.toArray(new Object[][]{});
}

代码示例来源:origin: broadgsa/gatk-protected

@DataProvider(name = "R2MergerData")
public Object[][] makeR2MergerData() {
  List<Object[]> tests = new ArrayList<Object[]>();
  // this functionality can be adapted to provide input data for whatever you might want in your data
  final double thres = LDMerger.MERGE_EVENTS_PROB_PHASED_THRESHOLD;
  for ( final double r2 : Arrays.asList(0.0, thres - 0.01, thres + 0.01, 1.0) ) {
    tests.add(new Object[]{"ACGT", "CCGC", 2, "4M", "ACGT", "CCGC", r2, r2 >= thres});
    tests.add(new Object[]{"ACGT", "AGGC", 2, "4M", "CGT", "GGC", r2, r2 >= thres});
    tests.add(new Object[]{"ACGT", "ACCC", 2, "4M", "GT", "CC", r2, r2 >= thres});
    tests.add(new Object[]{"ACGT", "ACCGTT", 2, "2M1I1M1I1M", "CG", "CCGT", r2, r2 >= thres});
    tests.add(new Object[]{"ACGT", "AGCT", 2, "4M", "CG", "GC", r2, r2 >= thres});
    tests.add(new Object[]{"ACAGT", "AAGC", 2, "1M1D3M", "ACAGT", "AAGC", r2, r2 >= thres});
    tests.add(new Object[]{"ACAGT", "AAT", 2, "1M1D1M1D1M", "ACAG", "AA", r2, r2 >= thres});
    // cannot be merged -- only 1 event
    tests.add(new Object[]{"AAA", "ACA", 1, "3M", null, null, r2, false});
    final int dist = LDMerger.MAX_DISTANCE_BETWEEN_SNPS_TO_MERGE + 2;
    tests.add(new Object[]{Utils.dupString("A", dist), "C" + Utils.dupString("A", dist - 2) + "C", 2, dist + "M", null, null, r2, false});
  }
  return tests.toArray(new Object[][]{});
}

代码示例来源:origin: broadgsa/gatk

private static String formatArguments( ArgumentMatch invalidValues ) {
    StringBuilder sb = new StringBuilder();
    for( ArgumentMatchSite site: invalidValues.sites.keySet() )
      for( ArgumentMatchValue value: invalidValues.sites.get(site) ) {
        switch (site.getSource().getType()) {
          case CommandLine:
            sb.append( String.format("%nInvalid argument value '%s' at position %d.",
                value.asString(), site.getIndex()) );
            break;
          case Provider:
            sb.append( String.format("%nInvalid argument value '%s' in %s at position %d.",
                value.asString(), site.getSource().getDescription(), site.getIndex()) );
            break;
          default:
            throw new RuntimeException( String.format("Unexpected argument match source type: %s",
                site.getSource().getType()));
        }
        if(value.asString() != null && Utils.dupString(' ',value.asString().length()).equals(value.asString()))
          sb.append("  Please make sure any line continuation backslashes on your command line are not followed by whitespace.");
      }
    return sb.toString();
  }
}

代码示例来源:origin: broadgsa/gatk-protected

@DataProvider(name = "getIndexesOfRelevantAllelesData")
  public Object[][] makeGetIndexesOfRelevantAllelesData() {
    final int totalAlleles = 5;
    final List<Allele> alleles = new ArrayList<>(totalAlleles);
    alleles.add(Allele.create("A", true));
    for ( int i = 1; i < totalAlleles; i++ )
      alleles.add(Allele.create(Utils.dupString('A', i + 1), false));

    final List<Object[]> tests = new ArrayList<>();

    for ( int alleleIndex = 0; alleleIndex < totalAlleles; alleleIndex++ ) {
      tests.add(new Object[]{alleleIndex, alleles});
    }

    return tests.toArray(new Object[][]{});
  }
}

代码示例来源:origin: broadgsa/gatk

@DataProvider(name = "BlockSubstitutionsData")
public Object[][] makeBlockSubstitutionsData() {
  List<Object[]> tests = new ArrayList<Object[]>();
  for ( int size = EventMap.MIN_NUMBER_OF_EVENTS_TO_COMBINE_INTO_BLOCK_SUBSTITUTION; size < 10; size++ ) {
    final String ref = Utils.dupString("A", size);
    final String alt = Utils.dupString("C", size);
    tests.add(new Object[]{ref, alt, size + "M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1, Arrays.asList(ref, alt))});
  }
  tests.add(new Object[]{"AAAAAA", "GAGAGA", "6M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1, Arrays.asList("AAAAA", "GAGAG"))});
  tests.add(new Object[]{"AAAAAA", "GAGAGG", "6M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1, Arrays.asList("AAAAAA", "GAGAGG"))});
  for ( int len = 0; len < 10; len++ ) {
    final String s = len == 0 ? "" : Utils.dupString("A", len);
    tests.add(new Object[]{s + "AACCCCAA", s + "GAAG", len + 2 + "M4D2M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1 + len,   Arrays.asList("AACCCCAA", "GAAG"))});
    tests.add(new Object[]{s + "AAAA", s + "GACCCCAG", len + 2 + "M4I2M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1 + len, Arrays.asList("AAAA", "GACCCCAG"))});
    tests.add(new Object[]{"AACCCCAA" + s, "GAAG" + s, "2M4D" + (len + 2) + "M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1,   Arrays.asList("AACCCCAA", "GAAG"))});
    tests.add(new Object[]{"AAAA" + s, "GACCCCAG" + s, "2M4I" + (len + 2) + "M", GATKVariantContextUtils.makeFromAlleles(NAME, CHR, 1, Arrays.asList("AAAA", "GACCCCAG"))});
  }
  return tests.toArray(new Object[][]{});
}

代码示例来源:origin: broadgsa/gatk-protected

@Test(enabled=true)
public void testTooManyAlleles() {
  for ( Integer numAltAlleles = 0; numAltAlleles < 100; numAltAlleles++ )  {
    final Set<Allele> alleles = new HashSet<>();
    alleles.add(Allele.create("A", true));        // ref allele
    for (int len = 1; len <=numAltAlleles; len++) {
      // add alt allele of length len+1
      alleles.add(Allele.create(Utils.dupString('A', len + 1), false));
    }
    final VariantContext vc = new VariantContextBuilder("test", "chr1", 1000, 1000, alleles).make();
    final boolean result = ugEngine.hasTooManyAlternativeAlleles(vc);
    Assert.assertTrue(result == (vc.getNAlleles() > GenotypeLikelihoods.MAX_DIPLOID_ALT_ALLELES_THAT_CAN_BE_GENOTYPED));
  }
}

代码示例来源:origin: broadgsa/gatk-protected

@Test(dataProvider = "PcrErrorModelTestProvider", enabled = true)
public void createPcrErrorModelTest(final String repeat, final int repeatLength) {
  final PairHMMLikelihoodCalculationEngine engine = new PairHMMLikelihoodCalculationEngine((byte)0,
      PairHMM.HMM_IMPLEMENTATION.ORIGINAL, null, 0.0, true,
      PairHMMLikelihoodCalculationEngine.PCR_ERROR_MODEL.CONSERVATIVE);
  final String readString = Utils.dupString(repeat, repeatLength);
  final byte[] insQuals = new byte[readString.length()];
  final byte[] delQuals = new byte[readString.length()];
  Arrays.fill(insQuals, (byte)PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
  Arrays.fill(delQuals, (byte)PairHMMLikelihoodCalculationEngine.INITIAL_QSCORE);
  engine.applyPCRErrorModel(readString.getBytes(), insQuals, delQuals);
  final RepeatCovariate repeatCovariate = new RepeatLengthCovariate();
  repeatCovariate.initialize(PairHMMLikelihoodCalculationEngine.MAX_STR_UNIT_LENGTH, PairHMMLikelihoodCalculationEngine.MAX_REPEAT_LENGTH);
  for ( int i = 1; i < insQuals.length; i++ ) {
    final int repeatLengthFromCovariate = repeatCovariate.findTandemRepeatUnits(readString.getBytes(), i-1).getSecond();
    final byte adjustedScore = PairHMMLikelihoodCalculationEngine.getErrorModelAdjustedQual(repeatLengthFromCovariate, 3.0);
    Assert.assertEquals(insQuals[i-1], adjustedScore);
    Assert.assertEquals(delQuals[i-1], adjustedScore);
  }
}

代码示例来源:origin: broadgsa/gatk-protected

@Test(dataProvider = "LeftAlignDataProvider")
public void testLeftAlignNoTrimming(final int offset, final int indelSize) {
  if (indelSize == 0)
    return;
  final List<Allele> alleles = new ArrayList<Allele>();
  if (indelSize < 0) { // deletion
    alleles.add(Allele.create(Utils.dupString("A",Math.abs(indelSize)+1),true));
    alleles.add(Allele.create("A", false));
  }
  else {
    alleles.add(Allele.create("A", true));
    alleles.add(Allele.create(Utils.dupString("A",Math.abs(indelSize)+1),false));
  }
  final GenomeLoc loc = genomeLocParser.createGenomeLoc(artificialContig,locStart+offset,locStart+offset);
  final ReferenceContext referenceContext = new ReferenceContext(genomeLocParser,loc,window,windowBases.getBytes());
  final VariantContext vc = new VariantContextBuilder("test", artificialContig, locStart+offset, locStart+offset+alleles.get(0).length()-1, alleles).make();
  final Pair<VariantContext,Integer> result = LeftAlignAndTrimVariants.alignAndWrite(vc,referenceContext);
  Assert.assertTrue(result.second == (offset>0?1:0));
  Assert.assertEquals(result.first.getStart(), locStart);
}

代码示例来源:origin: broadgsa/gatk

public void testBAQ(BAQTest test, boolean lookupWithFasta) {
  BAQ baqHMM = new BAQ(1e-3, 0.1, 7, (byte)4, false);         // matches current samtools parameters
  SAMRecord read = test.createRead();
  BAQ.BAQCalculationResult result;
  if ( lookupWithFasta && test.cigar != null )
    result = baqHMM.calcBAQFromHMM(read, fasta);
  else
    result = baqHMM.calcBAQFromHMM(read, test.refBases.getBytes(), test.refOffset);
  System.out.println(Utils.dupString('-', 40));
  System.out.println("reads   : " + new String(test.readBases));
  printQuals(System.out, "in-quals:", test.quals, false);
  printQuals(System.out, "bq-quals:", result.bq, false);
  for (int i = 0; i < test.quals.length; i++) {
    //result.bq[i] = baqHMM.capBaseByBAQ(result.rawQuals[i], result.bq[i], result.state[i], i);
    Assert.assertTrue(result.bq[i] >= baqHMM.getMinBaseQual() || test.expected[i] < baqHMM.getMinBaseQual(), "BQ < min base quality");
    Assert.assertEquals(result.bq[i], test.expected[i], "Did not see the expected BAQ value at " + i);
  }
}

代码示例来源:origin: broadgsa/gatk-protected

private VariantContext makeDeletion(final String contig, final int start, final int size) {
  final String del = Utils.dupString("A", size);
  final String alt = del.substring(0, 1);
  final VariantContext vc = GATKVariantContextUtils.makeFromAlleles("test", contig, start, Arrays.asList(del, alt));
  final VariantContextBuilder vcb = new VariantContextBuilder(vc);
  final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME, Arrays.asList(vc.getReference(), vc.getAlternateAllele(0)));
  gb.GQ(50);
  gb.DP(10);
  gb.AD(new int[]{1, 2});
  gb.PL(new int[]{0, 10, 100});
  return vcb.genotypes(gb.make()).make();
}

代码示例来源:origin: broadgsa/gatk

@Test(enabled = true)
public void testHardClippingBeforeMergeResultingInCompletelyContainedSecondRead() {
  final String adapter    = "NNNN";
  final int minReadSize   = 7;
  final GATKSAMRecord readLeftAdapter = makeOverlappingRead(adapter, 30, Utils.dupString("A", 10), Utils.dupBytes((byte)30, 10), "", 30, 10);
  final GATKSAMRecord readRightAdapter = makeOverlappingRead("", 30, Utils.dupString("A", minReadSize), Utils.dupBytes((byte)30, minReadSize), adapter, 30, 10);
  readLeftAdapter.setCigarString(adapter.length() + "S10M");
  readLeftAdapter.setProperPairFlag(true);
  readLeftAdapter.setFirstOfPairFlag(true);
  readLeftAdapter.setReadNegativeStrandFlag(true);
  readLeftAdapter.setMateAlignmentStart(10);
  readRightAdapter.setCigarString(minReadSize + "M4S");
  readRightAdapter.setProperPairFlag(true);
  readRightAdapter.setFirstOfPairFlag(false);
  readRightAdapter.setReadNegativeStrandFlag(false);
  final int insertSize = minReadSize;
  readLeftAdapter.setInferredInsertSize(insertSize);
  readRightAdapter.setInferredInsertSize(-insertSize);
  final GATKSAMRecord actual = FragmentUtils.mergeOverlappingPairedFragments(readLeftAdapter, readRightAdapter);
  Assert.assertNull(actual);
}

代码示例来源:origin: broadgsa/gatk-protected

private RefConfData(String ref, int extension) {
  this.ref = ref;
  this.extension = extension;
  refLoc = parser.createGenomeLoc("chr1", getStart(), getEnd());
  paddedRefLoc = parser.createGenomeLoc("chr1", getStart() - extension, getEnd() + extension);
  region = new ActiveRegion(getRefLoc(), parser, extension);
  final String pad = Utils.dupString("N", extension);
  refHap = ReferenceConfidenceModel.createReferenceHaplotype(getActiveRegion(), (pad + ref + pad).getBytes(), getPaddedRefLoc());
}

相关文章