<commit_before>var bwa = require('../')
var fs = require('fs')
var crypto = require('crypto')
var request = require('request')
var tool = require('tool-stream')
var through = require('through2')
var async = require('async')
var test = require('tape')

test("Align reads to reference with BWA", function (t) {
  t.plan(2)
  var referencePath = 'test/reference.fasta.gz'
  var readsPath = 'test/reads.fastq.gz'
  var alignmentPath = 'test/alignment.sam'
  var referenceURL = 'http://ftp.ncbi.nlm.nih.gov/genbank/genomes/Eukaryotes/protozoa/Guillardia_theta/Guith1/Primary_Assembly/unplaced_scaffolds/FASTA/unplaced.scaf.fa.gz'
  var readsURL = 'http://ftp.sra.ebi.ac.uk//vol1/fastq/SRR070/SRR070675/SRR070675.fastq.gz'

  var downloads = [
    download(referenceURL, referencePath),
    download(readsURL, readsPath)
  ]
  async.series(downloads, alignReadsToRef)

  function alignReadsToRef() {
    var msg = "should take paths for reference, reads and aligment. Reference should be indexed first."
    var mem = bwa() // default to mem
    mem([referencePath, readsPath, alignmentPath])
    .on('data', function(data) { checksum(data, '3dae171586e8f5fda2737795ff2e39df711701cb', msg, t) })

    var msg = "should align using a Stream that takes arrays of paths for reference and reads."
    var mem = bwa('mem -x pacbio')
    var memStream = mem() // we will pass arguments with write
    memStream.write([referencePath, readsPath])
    memStream.end()
    memStream.on('data', function(data) { checksum(data, 'a2ac465ac0d9e0879a9f9a43108e36b682f2e018', msg, t) })
  }
})

function download(url, path) {
  return function task(callback) {
    var read = request(url)
    var write = fs.createWriteStream(path)
    read.pipe(write)
    write
    .on('finish', callback)
    .on('error', function (error) {
      console.warn(error)
    })
  }
}
<commit_msg>Fix test random error (2nd try)<commit_after>var bwa = require('../')
var fs = require('fs')
var crypto = require('crypto')
var request = require('request')
var tool = require('tool-stream')
var through = require('through2')
var async = require('async')
var test = require('tape')

test("Align reads to reference with BWA", function (t) {
  t.plan(2)
  var referencePath = 'test/reference.fasta.gz'
  var readsPath = 'test/reads.fastq.gz'
  var alignmentPath = 'test/alignment.sam'
  var referenceURL = 'http://ftp.ncbi.nlm.nih.gov/genbank/genomes/Eukaryotes/protozoa/Guillardia_theta/Guith1/Primary_Assembly/unplaced_scaffolds/FASTA/unplaced.scaf.fa.gz'
  var readsURL = 'http://ftp.sra.ebi.ac.uk//vol1/fastq/SRR070/SRR070675/SRR070675.fastq.gz'

  var asyncFuncs = [
    download(referenceURL, referencePath),
    download(readsURL, readsPath),
    alignReadsToRef1,
    alignReadsToRef2
  ]
  async.series(asyncFuncs)

  function alignReadsToRef1(cb) {
    var msg = "should take paths for reference, reads and aligment. Reference should be indexed first."
    var mem = bwa() // default to mem
    mem([referencePath, readsPath, alignmentPath])
    .on('data', function(data) {
      checksum(data, '3dae171586e8f5fda2737795ff2e39df711701cb', msg, t)
      cb()
    })
  }
  function alignReadsToRef2(cb) {
    var msg = "should align using a Stream that takes arrays of paths for reference and reads."
    var mem = bwa('mem -x pacbio')
    var memStream = mem() // we will pass arguments with write
    memStream.write([referencePath, readsPath])
    memStream.end()
    memStream.on('data', function(data) {
      checksum(data, 'a2ac465ac0d9e0879a9f9a43108e36b682f2e018', msg, t)
      cb()
    })
  }
})

function download(url, path) {
  return function task(callback) {
    var read = request(url)
    var write = fs.createWriteStream(path)
    read.pipe(write)
    write
    .on('finish', callback)
    .on('error', function (error) {
      console.warn(error)
    })
  }
}

{'fraction_non_alphanumeric': 0.1319968758135902, 'fraction_numerical': 0.037750585784951836, 'mean_word_length': 3.9130434782608696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7088302', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1314, 'n_words': 304}