mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
modified mergeCols to take advantage of repeat tag. Looks foolproof now.
This commit is contained in:
@@ -5,9 +5,19 @@ def stop_err( msg ):
|
||||
sys.exit()
|
||||
|
||||
def __main__():
|
||||
infile = open ( sys.argv[1], 'r')
|
||||
cols = ( re.sub( '\s*','',sys.argv[2] ) ).split( ',' )
|
||||
outfile = open ( sys.argv[3], 'w')
|
||||
try:
|
||||
infile = open ( sys.argv[1], 'r')
|
||||
# cols = ( re.sub( '\s*','',sys.argv[2] ) ).split( ',' )
|
||||
outfile = open ( sys.argv[2], 'w')
|
||||
except:
|
||||
stop_err( 'Cannot open or create a file\n' )
|
||||
|
||||
if len( sys.argv ) < 4:
|
||||
stop_err( 'No columns to merge' )
|
||||
else:
|
||||
cols = sys.argv[3:]
|
||||
|
||||
skipped_lines = 0
|
||||
|
||||
for line in infile:
|
||||
line = line.rstrip( '\r\n' )
|
||||
@@ -16,10 +26,13 @@ def __main__():
|
||||
line += '\t'
|
||||
for col in cols:
|
||||
try:
|
||||
line += fields[ int( col.lstrip( 'c' ) ) -1 ]
|
||||
line += fields[ int( col ) -1 ]
|
||||
except:
|
||||
stop_err( 'Column %s does not appear in the input file' % str( col ) )
|
||||
skipped_lines += 1
|
||||
|
||||
print >>outfile, line
|
||||
|
||||
if skipped_lines > 0:
|
||||
print 'Skipped %d invalid lines' % skipped_lines
|
||||
|
||||
if __name__ == "__main__" : __main__()
|
||||
+40
-24
@@ -1,29 +1,46 @@
|
||||
<tool id="mergeCols1" name="Merge columns">
|
||||
<description>together</description>
|
||||
<command interpreter="python">mergeCols.py $input "$columnList" $out_file1</command>
|
||||
<inputs>
|
||||
<param name="columnList" size="10" type="text" value="c1,c2" label="Merge columns"/>
|
||||
<param format="tabular" name="input" type="data" label="In"/>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data format="tabular" name="out_file1" />
|
||||
</outputs>
|
||||
<tests>
|
||||
<tool id="mergeCols1" name="Merge Columns" version="1.0.1">
|
||||
<description>together</description>
|
||||
<command interpreter="python">
|
||||
mergeCols.py
|
||||
$input1
|
||||
$out_file1
|
||||
$col1
|
||||
$col2
|
||||
#for $col in $columns
|
||||
${col.datacol}
|
||||
#end for
|
||||
</command>
|
||||
<inputs>
|
||||
<param format="tabular" name="input1" type="data" label="Select data" help="Query missing? See TIP below."/>
|
||||
<param name="col1" label="Merge column" type="data_column" data_ref="input1" />
|
||||
<param name="col2" label="with column" type="data_column" data_ref="input1" help="Need to add more columns? Use controls below."/>
|
||||
<repeat name="columns" title="Columns">
|
||||
<param name="datacol" label="Add column" type="data_column" data_ref="input1" />
|
||||
</repeat>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data format="tabular" name="out_file1" />
|
||||
</outputs>
|
||||
<tests>
|
||||
<test>
|
||||
<param name="columnList" value="c4, c1"/>
|
||||
<param name="input" value="1.bed"/>
|
||||
<param name="input1" value="1.bed"/>
|
||||
<param name="col1" value="4" />
|
||||
<param name="col2" value="1" />
|
||||
<param name="datacol" value="6" />
|
||||
<output name="out_file1" file="mergeCols.dat"/>
|
||||
</test>
|
||||
</tests>
|
||||
<help>
|
||||
|
||||
<help>
|
||||
|
||||
.. class:: infomark
|
||||
|
||||
**TIP:** If your data is not TAB delimited, use *Text Manipulation->Convert*
|
||||
|
||||
-----
|
||||
|
||||
**What it does**
|
||||
|
||||
This tool merges columns together
|
||||
|
||||
- Columns are specified as **c1**, **c2**, and so on. Column count begins with **1**
|
||||
- Columns can be specified in any order (e.g., **c2,c1,c6**)
|
||||
|
||||
This tool merges columns together. Any number of valid columns can be merged in any order.
|
||||
|
||||
-----
|
||||
|
||||
@@ -39,9 +56,8 @@ merging columns "**c5,c1**" will return::
|
||||
1 10 1000 gene1 chr chr1
|
||||
2 100 1500 gene2 chr chr2
|
||||
|
||||
.. class:: infomark
|
||||
.. class:: warningmark
|
||||
|
||||
Note that all original columns are preserved and the result of merge is added as the rightmost column.
|
||||
|
||||
</help>
|
||||
</tool>
|
||||
</help>
|
||||
</tool>
|
||||
|
||||
Reference in New Issue
Block a user