Last active
July 15, 2018 20:07
-
-
Save jdurbin/b12e2377c5af0b7899267386cc605e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import grapnel.util.* | |
// Combine multiple URSA outputs into a single tab file, removing header text along the way. | |
dirname = args[0] | |
matchStr = args[1] | |
pattern = "${matchStr}*.*" | |
// Table that automatically grows as add elements. | |
table = new DynamicTable() | |
new File(dirname).eachFileMatch(~/${pattern}/){f-> | |
print "Processing ${f.name}...." | |
f.withReader{r-> | |
iterator = r.iterator() | |
def line | |
while(iterator.hasNext()){ | |
line = iterator.next() | |
if (!line.startsWith("#")) break; | |
} | |
heading = line | |
headings = heading.split("\t",-1) | |
headings = headings[1..-1] // headings[0] is empty | |
r.splitEachLine("\t"){fields-> | |
cellType = fields[0] | |
// see if there are any values that exceed our | |
// threshold. If so, save the whole line. | |
bSaveLine = false; | |
headings.eachWithIndex{h,i-> | |
value = fields[i+1] as double | |
if (value >= 0.5) bSaveLine = true; | |
} | |
if (bSaveLine){ | |
headings.eachWithIndex{h,i-> | |
value = fields[i+1] as double | |
table.put(cellType,h,value) | |
} | |
} | |
} | |
} | |
println "done." | |
} | |
print "Writing ${matchStr}.combined..." | |
table.write("${matchStr}.combined","\t") | |
println "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment