Skip to content

Commit 86617a0

Browse files
committed
Changed syntax a bit to handle blank input/output
1 parent cb11369 commit 86617a0

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

src/main/groovy/com/milaboratory/migec/Assemble.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import groovyx.gpars.GParsPool
2121
import java.util.concurrent.LinkedBlockingQueue
2222
import java.util.concurrent.atomic.AtomicInteger
2323

24+
import static com.milaboratory.migec.Util.BLANK_PATH
25+
2426
//========================
2527
// CLI
2628
//========================
2729
def DEFAULT_ASSEMBLE_MASK = "1:1", DEFAULT_MIN_COUNT = "10", DEFAULT_PARENT_CHILD_RATIO = "0.1"
2830
def cli = new CliBuilder(usage:
29-
'Assemble [options] R1.fastq[.gz] [R2.fastq[.gz] or -] output_dir/')
31+
"Assemble [options] R1.fastq[.gz] [R2.fastq[.gz] or ${BLANK_PATH}] output_dir/")
3032
cli.q(args: 1, argName: 'read quality (phred)',
3133
"barcode region quality threshold. Default: $Util.DEFAULT_UMI_QUAL_THRESHOLD")
3234
cli._(longOpt: 'assembly-mask', args: 1, argName: 'X:Y, X=0/1, Y=0/1',
@@ -91,7 +93,7 @@ if (!(inputFileName1.endsWith(".fastq") || inputFileName1.endsWith(".fastq.gz"))
9193
outputFilePrefix1 = Util.getFastqPrefix(inputFileName1) + ".t" + minMigSize + (filterCollisions ? ".cf" : "")
9294
}
9395

94-
if (inputFileName2 != "-") {
96+
if (inputFileName2 != BLANK_PATH) {
9597
if (!(inputFileName2.endsWith(".fastq") || inputFileName2.endsWith(".fastq.gz"))) {
9698
println "[ERROR] Bad file extension $inputFileName2. Either .fastq, .fastq.gz or \'-\' should be provided as R2 file."
9799
System.exit(-1)
@@ -106,7 +108,7 @@ def offsetRange = Integer.parseInt(opt.'assembly-offset' ?: '5'),
106108
anchorRegion = Integer.parseInt(opt.'assembly-anchor' ?: '10')
107109

108110
// I/O parameters
109-
boolean paired = inputFileName2 != "-"
111+
boolean paired = inputFileName2 != BLANK_PATH
110112
def assemblyIndices = [true, false]
111113
boolean bothReads = false
112114
if (paired) {

src/main/groovy/com/milaboratory/migec/CdrBlast.groovy

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ TMP_FOLDER_FILE.mkdirs()
147147
//if (!DEBUG)
148148
// TMP_FOLDER_FILE.deleteOnExit()
149149

150-
if (new File(outputFileName).parentFile)
151-
new File(outputFileName).parentFile.mkdirs()
150+
def outputFile = null
151+
if (outputFileName != "-" && (outputFile = new File(outputFileName)).parentFile)
152+
outputFile.parentFile.mkdirs()
152153

153154
// BLAST SETTINGS
154155
int ALLELE_TAIL_INNER = 10, ALLELE_TAIL_OUTER = 6,
@@ -758,22 +759,23 @@ uniqueClonotypes.keySet().each {
758759
}
759760
}
760761

761-
println "${timestamp()} Writing output"
762-
def outputFile = new File(outputFileName)
763-
outputFile.withPrintWriter { pw ->
764-
pw.println("Count\tPercentage\t" +
765-
"CDR3 nucleotide sequence\tCDR3 amino acid sequence\t" +
766-
"V segments\tJ segments\tD segments\t" +
767-
"Last V nucleotide position\t" +
768-
"First D nucleotide position\tLast D nucleotide position\t" +
769-
"First J nucleotide position\t" +
770-
"Good events\tTotal events\tGood reads\tTotal reads")
771-
772-
(doSort ? cloneMap.sort { -it.value[0] } : cloneMap).each {
773-
if (it.value[0] > 0)
774-
pw.println(it.value[0] + "\t" + (it.value[0] / goodEvents) + // percentage from good events only
775-
"\t" + it.key +
776-
"\t" + it.value.collect().join("\t"))
762+
if (outputFile) {
763+
println "${timestamp()} Writing output"
764+
outputFile.withPrintWriter { pw ->
765+
pw.println("Count\tPercentage\t" +
766+
"CDR3 nucleotide sequence\tCDR3 amino acid sequence\t" +
767+
"V segments\tJ segments\tD segments\t" +
768+
"Last V nucleotide position\t" +
769+
"First D nucleotide position\tLast D nucleotide position\t" +
770+
"First J nucleotide position\t" +
771+
"Good events\tTotal events\tGood reads\tTotal reads")
772+
773+
(doSort ? cloneMap.sort { -it.value[0] } : cloneMap).each {
774+
if (it.value[0] > 0)
775+
pw.println(it.value[0] + "\t" + (it.value[0] / goodEvents) + // percentage from good events only
776+
"\t" + it.key +
777+
"\t" + it.value.collect().join("\t"))
778+
}
777779
}
778780
}
779781

@@ -783,8 +785,10 @@ if (!DEBUG)
783785
//TMP_FOLDER_FILE.listFiles().each { it.deleteOnExit() }
784786

785787
// Append to log and report to batch runner
786-
def logLine = [(assembledInput ? "asm" : "raw"), outputFile.absolutePath, inputFileNames.join(","),
787-
goodEvents, mappedEvents, totalEvents, goodReads, mappedReads, totalReads].join("\t")
788+
def logLine = [(assembledInput ? "asm" : "raw"), outputFile ? outputFile.absolutePath : "-",
789+
inputFileNames.join(","),
790+
goodEvents, mappedEvents, totalEvents,
791+
goodReads, mappedReads, totalReads].join("\t")
788792

789793
if (logFileName) {
790794
def logFile = new File(logFileName)

src/main/groovy/com/milaboratory/migec/CdrBlastBatch.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.milaboratory.migec
22

3+
import static com.milaboratory.migec.Util.BLANK_PATH
4+
35
/**
46
Copyright 2014 Mikhail Shugay (mikhail.shugay@gmail.com)
57
@@ -18,7 +20,8 @@ package com.milaboratory.migec
1820

1921
def scriptName = getClass().canonicalName
2022

21-
def cli = new CliBuilder(usage: "$scriptName [options] [checkout_dir/ or -] [assemble_dir/ or -] output_dir/\n" +
23+
def cli = new CliBuilder(usage: "$scriptName [options] " +
24+
"[checkout_dir/ or ${BLANK_PATH}] [assemble_dir/ or ${BLANK_PATH}] output_dir/\n" +
2225
"Either --sample-metadata or -R argument is required.")
2326
cli.p(args: 1, "Number of threads to use")
2427
cli._(longOpt: "sample-metadata", args: 1, argName: "file",
@@ -85,7 +88,7 @@ if (!sampleInfoFileName && !opt.R) {
8588
System.exit(-1)
8689
}
8790

88-
boolean processRaw = checkoutDir != "-", processAssembled = assembleDir != "-"
91+
boolean processRaw = checkoutDir != BLANK_PATH, processAssembled = assembleDir != BLANK_PATH
8992
if (!processRaw && !processAssembled) {
9093
println "[ERROR] At least one of assembled or raw (checkout) data directories should be specified"
9194
System.exit(-1)

src/main/groovy/com/milaboratory/migec/Checkout.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import java.util.concurrent.LinkedBlockingQueue
2222
import java.util.concurrent.atomic.AtomicLong
2323
import java.util.regex.Pattern
2424

25+
import static com.milaboratory.migec.Util.BLANK_PATH
26+
2527
def mm = "15:0.2:0.05", rcm = "0:1", mtrim = "10", omf = "5", oss = "5", oms = "10"
2628
def cli = new CliBuilder(usage:
27-
'Checkout [options] barcode_file R1.fastq[.gz] [R2.fastq[.gz] or -] output_dir/')
29+
"Checkout [options] barcode_file R1.fastq[.gz] [R2.fastq[.gz] or ${BLANK_PATH}] output_dir/'")
2830
cli.o('Oriented reads, so master barcode has to be in R1. ' +
2931
'Default: scans both reads (if pair-end) for master barcode')
3032
cli.u('Save UMI region specified by capital N\'s in barcode sequence to the header')
@@ -158,7 +160,7 @@ def addBarcode = { String barcode, int slave ->
158160
new File(barcodesFileName).splitEachLine("[\t ]") { sl ->
159161
// filter by input file name
160162
if (
161-
(inputFileName2 == "-" && (sl.size() < 4 || sl[3] == "." || (inputFileName1.contains(sl[3])))) ||
163+
(inputFileName2 == BLANK_PATH && (sl.size() < 4 || sl[3] == "." || (inputFileName1.contains(sl[3])))) ||
162164
(sl.size() < 5 ||
163165
((sl[3] == "." || inputFileName1.contains(sl[3])) && (sl[4] == "." || inputFileName2.contains(sl[4]))))
164166
) {
@@ -646,7 +648,7 @@ new HashSet(sampleIds).each { String sampleId -> // only unique
646648
(paired ? new File("$outputDir/${sampleId}_R1.$fastqPrefix").absolutePath :
647649
new File("$outputDir/${sampleId}_R0.$fastqPrefix").absolutePath)
648650
+ "\t" +
649-
(paired ? new File("$outputDir/${sampleId}_R2.$fastqPrefix").absolutePath : "-"))
651+
(paired ? new File("$outputDir/${sampleId}_R2.$fastqPrefix").absolutePath : BLANK_PATH))
650652
if (overlap)
651653
filelistWriter.println(sampleId + "\toverlapped\t" +
652654
new File("$outputDir/${sampleId}_R12.$fastqPrefix").absolutePath + "\t-")

src/main/groovy/com/milaboratory/migec/Util.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class Util {
3333
script.binding.setVariable("args", argArray)
3434
script.run()
3535
}
36+
37+
static final String BLANK_PATH = "_"
3638

3739
static final List<String> FILE_TYPES = ["paired", "unpaired", "overlapped"],
3840
MASKS = ["0:1", "1:0", "1:1", "0:0"]

0 commit comments

Comments
 (0)