VcfUtils.scala 723 Bytes
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
package nl.lumc.sasc.biopet.utils
Peter van 't Hof's avatar
Peter van 't Hof committed
2
3
4
5
6
7
8
9
10
11

import htsjdk.variant.variantcontext.VariantContext
import scala.collection.JavaConversions._

/** Utility object for general vcf file/records functions. */
object VcfUtils {
  /**
   * Return longest allele of VariantContext.
   *
   * @param vcfRecord record to check
Peter van 't Hof's avatar
Peter van 't Hof committed
12
   * @return allele with most nucleotides
Peter van 't Hof's avatar
Peter van 't Hof committed
13
14
15
16
17
18
   */
  def getLongestAllele(vcfRecord: VariantContext) = {
    val alleles = vcfRecord.getAlleles
    val longestAlleleId = alleles.map(_.getBases.length).zipWithIndex.maxBy(_._1)._2
    alleles(longestAlleleId)
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
19
20
21
22

  def fillAllele(bases: String, newSize: Int, fillWith: Char = 'N'): String = {
    bases + (Array.fill[Char](newSize - bases.size)(fillWith)).mkString
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
23
}