<commit_before>// ---------------------------------------------------------------------
// The Great Computer Language Shootout
// http://shootout.alioth.debian.org/
//
// Redesigned [though minimally, and 'spirit' of original maintained as
// far as possible] by <NAME> based on code originally contributed
// by <NAME>.
//
// Use of string concatenation for segment creation could prove a
// performance bottleneck under heavy loads and may need replacing with
// a StringBuffer-based approach 
// ---------------------------------------------------------------------

def complement = ['A':'T', 'C':'G', 'G':'C', 'T':'A', 'M':'K', 'R':'Y', 'W':'W', 'S':'S', 'Y':'R', 'K':'M', 'V':'B', 'H':'D', 'D':'H', 'B':'V', 'N':'N']

// --------------

def revcomp(sequence)
{
  def compseq = ""

  sequence.reverse().toUpperCase().each()
  {
    compseq += complement[it]
  }

  compseq
}

// --------------

def dumpSegment(segment, length)
{
  def segsize = segment.size() ; if (segsize < 1) return

  def start = 0 ; def end = length - 1

  while (true)
  {
    println segment[start .. end]

    if (end + length < segsize - 1)
    {
      start += length ; end += length
    }
    else
    {
      println segment[end + 1 .. segsize - 1] ; break
    }
  }
}

// --------------------------------

def main()
{
  System.in.newReader().withReader { reader ->

    def segment = "" ; def sequence = ""

    while ((sequence = reader.readLine()) != null)
    {
      if (sequence.startsWith('>'))
      {
        dumpSegment(segment, 60) ; segment = "" ; println sequence
      }
      else
      {
        segment = revcomp(sequence) + segment
      }<commit_msg>*** empty log message ***<commit_after>// ---------------------------------------------------------------------
// The Great Computer Language Shootout
// http://shootout.alioth.debian.org/
//
// Redesigned [though minimally, and 'spirit' of original maintained as
// far as possible] by <NAME> based on code originally contributed
// by <NAME>.
//
// Original redesign used string concatenation to create segments but this
// proved extremely inefficient and slow, so modified code to utilise a
// StringBuffer
// ---------------------------------------------------------------------

def complement = ['A':'T', 'C':'G', 'G':'C', 'T':'A', 'M':'K', 'R':'Y', 'W':'W', 'S':'S', 'Y':'R', 'K':'M', 'V':'B', 'H':'D', 'D':'H', 'B':'V', 'N':'N']

// --------------

def revcomp(sequence)
{
  def compseq = ""

  sequence.reverse().toUpperCase().each()
  {
    compseq += complement[it]
  }

  compseq
}

// --------------

def dumpSegment(segment, length)
{
  def segsize = segment.size() ; if (segsize < 1) return

  def start = 0 ; def end = length - 1

  while (true)
  {
    println segment[start .. end]

    if (end + length < segsize - 1)
    {
      start += length ; end += length
    }
    else
    {
      println segment[end + 1 .. segsize - 1] ; break
    }
  }

  segment.setLength(0)
}

// --------------------------------

def main()
{
  System.in.newReader().withReader { reader ->

    def segment = new StringBuffer(); def sequence = ""

    while ((sequence = reader.readLine()) != null)
    {
      if (sequence.startsWith('>'))
      {
        dumpSegment(segment, 60) ; println sequence
      }
      else
      {
        segment.insert(0, revcomp(sequence))
      }
{'fraction_non_alphanumeric': 0.27890952666267227, 'fraction_numerical': 0.005392450569203115, 'mean_word_length': 1.743631881676253, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4199639', 'n_tokens_mistral': 1045, 'n_tokens_neox': 967, 'n_words': 278}