# HG changeset patch # User earlhaminst # Date 1484910803 18000 # Node ID 17aa68582a05a9abec03525a41312f23d8e8d8a0 # Parent dbc49bd1a3e9eb636dc5b8f7ab2f3cce5c835833 planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b diff -r dbc49bd1a3e9 -r 17aa68582a05 hcluster_sg_parser.pl --- a/hcluster_sg_parser.pl Mon Dec 12 07:12:23 2016 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#!/usr/bin/perl -# -use strict; -use warnings; -# A simple perl parser to convert hcluster_sg 3-column output into list of ids in separate files -# hcluster_sg_parser.pl - -my $file1 = $ARGV[0]; -open my $fh1, '<', $file1; - -while (my $line = <$fh1>) { - chomp $line; - my @row = split(/\t/, $line); - - my $cluster_id = $row[0]; - my $id_list = $row[2]; - # Change commas to newlines - $id_list =~ s/\,/\n/g; - - my $outfile = $cluster_id."_output.txt"; - open(my $fh, '>', $outfile) or die "Could not open file '$outfile' for writing: $!"; - print $fh $id_list; - close $fh; -} -close $fh1; diff -r dbc49bd1a3e9 -r 17aa68582a05 hcluster_sg_parser.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hcluster_sg_parser.py Fri Jan 20 06:13:23 2017 -0500 @@ -0,0 +1,36 @@ +""" +A simple parser to convert the hcluster_sg 3-column output into lists of IDs, one list for each cluster. + +When a minimum and/or maximum number of cluster elements are specified, the IDs contained in the filtered-out clusters are collected in the "discarded IDS" output dataset. + +Usage: + +python hcluster_sg_parser.py [-m ] [-M ] +""" +import optparse +import sys + + +def main(): + parser = optparse.OptionParser() + parser.add_option('-m', '--min', type='int', default=0, help='Minimum number of cluster elements') + parser.add_option('-M', '--max', type='int', default=sys.maxsize, help='Maximum number of cluster elements') + options, args = parser.parse_args() + + with open(args[1], 'w') as discarded_out: + with open(args[0]) as fh: + for line in fh: + line = line.rstrip() + (cluster_id, n_ids, id_list) = line.split('\t') + n_ids = int(n_ids) + id_list = id_list.replace(',', '\n') + if n_ids >= options.min and n_ids <= options.max: + outfile = cluster_id + '_output.txt' + with open(outfile, 'w') as f: + f.write(id_list) + else: + discarded_out.write(id_list) + + +if __name__ == "__main__": + main() diff -r dbc49bd1a3e9 -r 17aa68582a05 hcluster_sg_parser.xml --- a/hcluster_sg_parser.xml Mon Dec 12 07:12:23 2016 -0500 +++ b/hcluster_sg_parser.xml Fri Jan 20 06:13:23 2017 -0500 @@ -1,18 +1,27 @@ - - Converts hcluster_sg 3-column output into lists of ids + + converts hcluster_sg 3-column output into lists of IDs + + + @@ -23,11 +32,23 @@ + + + + + + + + + + diff -r dbc49bd1a3e9 -r 17aa68582a05 test-data/discarded.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/discarded.txt Fri Jan 20 06:13:23 2017 -0500 @@ -0,0 +1,10 @@ +74 +68 +2 +24 +58 +82 +18 +9 +12 +39 diff -r dbc49bd1a3e9 -r 17aa68582a05 test-data/empty.txt