galaxy-dist commit 428ce38ba8e9: Fixed issue #345 - Incorporated Brad's patch which handles skipping of order checking for join version >=7, which would otherwise end in an error. Also modified sort command to better handle cases with duplicate keys. A new test-case to test these scenarios has been added as well.
# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User guru # Date 1277915778 14400 # Node ID 428ce38ba8e92af0d2099a381e38863e09b46cd1 # Parent ddddd07724227dadeb37ffa2528a87e361787d8f Fixed issue #345 - Incorporated Brad's patch which handles skipping of order checking for join version >=7, which would otherwise end in an error. Also modified sort command to better handle cases with duplicate keys. A new test-case to test these scenarios has been added as well. --- a/tools/filters/joinWrapper.py +++ b/tools/filters/joinWrapper.py @@ -3,7 +3,7 @@ """ This tool provides the UNIX "join" functionality. """ -import sys, os, tempfile +import sys, os, tempfile, subprocess def stop_err(msg): sys.stderr.write(msg) @@ -22,8 +22,8 @@ def main(): try: #Sort the two files based on specified fields - os.system("sort -t $'\t' -k %d -o %s %s" %(field1, tmpfile1.name, infile1)) - os.system("sort -t $'\t' -k %d -o %s %s" %(field2, tmpfile2.name, infile2)) + os.system("sort -t $'\t' -k %d,%d -o %s %s" %(field1, field1, tmpfile1.name, infile1)) + os.system("sort -t $'\t' -k %d,%d -o %s %s" %(field2, field2, tmpfile2.name, infile2)) except Exception, exc: stop_err( 'Initialization error -> %s' %str(exc) ) @@ -39,10 +39,28 @@ def main(): option = option + ",1." + str(j) break + #check if join has --version option. BSD join doens't have this option, while GNU join does. + #The return value in the latter case will be 0, and non-zero in the latter case. + ret = subprocess.call('join --version 2>/dev/null', shell=True) + # check if we are a version later than 7 of join. If so, we want to skip + # checking the order since join will raise an error with duplicated items in + # the two files being joined. + if ret == 0: + cl = subprocess.Popen(["join", "--version"], stdout=subprocess.PIPE) + (stdout, _) = cl.communicate() + version_line = stdout.split("\n")[0] + (version, _) = version_line.split()[-1].split(".") + if int(version) >= 7: + flags = "--nocheck-order" + else: + flags = "" + else: + flags = "" + if mode == "V": - cmdline = "join -t $'\t' -v 1 -o %s -1 %d -2 %d %s %s > %s" %(option, field1, field2, tmpfile1.name, tmpfile2.name, outfile) + cmdline = "join %s -t $'\t' -v 1 -o %s -1 %d -2 %d %s %s > %s" %(flags, option, field1, field2, tmpfile1.name, tmpfile2.name, outfile) else: - cmdline = "join -t $'\t' -o %s -1 %d -2 %d %s %s > %s" %(option, field1, field2, tmpfile1.name, tmpfile2.name, outfile) + cmdline = "join %s -t $'\t' -o %s -1 %d -2 %d %s %s > %s" %(flags, option, field1, field2, tmpfile1.name, tmpfile2.name, outfile) try: os.system(cmdline) --- /dev/null +++ b/test-data/fs-compare-2.dat @@ -0,0 +1,40 @@ +chr10 55251623 55253124 CCDS7248.1_cds_0_0_chr10_55251624_r 0 - +chr11 116124407 116124501 CCDS8374.1_cds_0_0_chr11_116124408_r 0 - +chr11 116206508 116206563 CCDS8377.1_cds_0_0_chr11_116206509_f 0 + +chr11 116211733 116212337 CCDS8378.1_cds_0_0_chr11_116211734_r 0 - +chr11 1812377 1812407 CCDS7726.1_cds_0_0_chr11_1812378_f 0 + +chr12 38440094 38440321 CCDS8736.1_cds_0_0_chr12_38440095_r 0 - +chr13 112381694 112381953 CCDS9526.1_cds_0_0_chr13_112381695_f 0 + +chr14 98710240 98712285 CCDS9949.1_cds_0_0_chr14_98710241_r 0 - +chr15 41486872 41487060 CCDS10096.1_cds_0_0_chr15_41486873_r 0 - +chr15 41673708 41673857 CCDS10097.1_cds_0_0_chr15_41673709_f 0 + +chr15 41679161 41679250 CCDS10098.1_cds_0_0_chr15_41679162_r 0 - +chr15 41826029 41826196 CCDS10101.1_cds_0_0_chr15_41826030_f 0 + +chr16 142908 143003 CCDS10397.1_cds_0_0_chr16_142909_f 0 + +chr16 179963 180135 CCDS10401.1_cds_0_0_chr16_179964_r 0 - +chr16 244413 244681 CCDS10402.1_cds_0_0_chr16_244414_f 0 + +chr16 259268 259383 CCDS10403.1_cds_0_0_chr16_259269_r 0 - +chr18 23786114 23786321 CCDS11891.1_cds_0_0_chr18_23786115_r 0 - +chr18 59406881 59407046 CCDS11985.1_cds_0_0_chr18_59406882_f 0 + +chr18 59455932 59456337 CCDS11986.1_cds_0_0_chr18_59455933_r 0 - +chr18 59600586 59600754 CCDS11988.1_cds_0_0_chr18_59600587_f 0 + +chr19 59068595 59069564 CCDS12866.1_cds_0_0_chr19_59068596_f 0 + +chr19 59236026 59236146 CCDS12872.1_cds_0_0_chr19_59236027_r 0 - +chr19 59297998 59298008 CCDS12877.1_cds_0_0_chr19_59297999_f 0 + +chr19 59302168 59302288 CCDS12878.1_cds_0_0_chr19_59302169_r 0 - +chr20 33330413 33330423 CCDS13249.1_cds_0_0_chr20_33330414_r 0 - +chr20 33513606 33513792 CCDS13255.1_cds_0_0_chr20_33513607_f 0 + +chr20 33579500 33579527 CCDS13256.1_cds_0_0_chr20_33579501_r 0 - +chr20 33593260 33593348 CCDS13257.1_cds_0_0_chr20_33593261_f 0 + +chr21 32707032 32707192 CCDS13614.1_cds_0_0_chr21_32707033_f 0 + +chr21 32869641 32870022 CCDS13615.1_cds_0_0_chr21_32869642_r 0 - +chr21 33321040 33322012 CCDS13620.1_cds_0_0_chr21_33321041_f 0 + +chr21 33744994 33745040 CCDS13625.1_cds_0_0_chr21_33744995_r 0 - +chr22 30120223 30120265 CCDS13897.1_cds_0_0_chr22_30120224_f 0 + +chr22 30160419 30160661 CCDS13898.1_cds_0_0_chr22_30160420_r 0 - +chr22 30665273 30665360 CCDS13901.1_cds_0_0_chr22_30665274_f 0 + +chr22 30939054 30939266 CCDS13903.1_cds_0_0_chr22_30939055_r 0 - +chrX 122745047 122745924 CCDS14606.1_cds_0_0_chrX_122745048_f 0 + +chrX 152648964 152649196 CCDS14733.1_cds_0_0_chrX_152648965_r 0 - +chrX 152691446 152691471 CCDS14735.1_cds_0_0_chrX_152691447_f 0 + +chrX 152694029 152694263 CCDS14736.1_cds_0_0_chrX_152694030_r 0 - --- a/tools/filters/compare.xml +++ b/tools/filters/compare.xml @@ -1,4 +1,4 @@ -<tool id="comp1" name="Compare two Queries" version="1.0.1"> +<tool id="comp1" name="Compare two Queries" version="1.0.2"><description>to find common or distinct rows</description><command interpreter="python">joinWrapper.py $input1 $input2 $field1 $field2 $mode $out_file1</command><inputs> @@ -27,6 +27,15 @@ <param name="mode" value="N"/><output name="out_file1" file="fs-compare.dat"/></test> + <!--test case with duplicated key values--> + <test> + <param name="input1" value="1.bed"/> + <param name="input2" value="3.bed"/> + <param name="field1" value="1"/> + <param name="field2" value="1"/> + <param name="mode" value="V"/> + <output name="out_file1" file="fs-compare-2.dat"/> + </test></tests><help>
participants (1)
-
commits-noreply@bitbucket.org