Mercurial > repos > devteam > substitutions
changeset 1:385a5c3d7244 draft default tip
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/substitutions commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
author | devteam |
---|---|
date | Mon, 06 Jul 2020 18:13:37 +0000 |
parents | 190735ce4c2b |
children | |
files | substitutions.py substitutions.xml |
diffstat | 2 files changed, 54 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/substitutions.py Tue Apr 01 09:12:31 2014 -0400 +++ b/substitutions.py Mon Jul 06 18:13:37 2020 +0000 @@ -1,36 +1,32 @@ #!/usr/bin/env python -#Guruprasad ANanda """ Fetches substitutions from pairwise alignments. -""" -from galaxy import eggs +Guruprasad ANanda +""" +from __future__ import print_function -from galaxy.tools.util import maf_utilities +import sys import bx.align.maf -import sys - -def stop_err(msg): - sys.stderr.write(msg) - sys.exit() if len(sys.argv) < 3: - stop_err("Incorrect number of arguments.") + sys.exit("Incorrect number of arguments.") inp_file = sys.argv[1] out_file = sys.argv[2] fout = open(out_file, 'w') + def fetchSubs(block): src1 = block.components[0].src sequence1 = block.components[0].text start1 = block.components[0].start end1 = block.components[0].end len1_withgap = len(sequence1) - - for seq in range (1, len(block.components)): + + for seq in range(1, len(block.components)): src2 = block.components[seq].src sequence2 = block.components[seq].text start2 = block.components[seq].start @@ -38,7 +34,7 @@ sub_begin = None sub_end = None begin = False - + for nt in range(len1_withgap): if sequence1[nt] not in '-#$^*?' and sequence2[nt] not in '-#$^*?': # Not a gap or masked character if sequence1[nt].upper() != sequence2[nt].upper(): @@ -48,13 +44,21 @@ sub_end = nt else: if begin: - print >> fout, "%s\t%s\t%s" % ( src1, start1+sub_begin-sequence1[0:sub_begin].count('-'), start1+sub_end-sequence1[0:sub_end].count('-') ) - print >> fout, "%s\t%s\t%s" % ( src2, start2+sub_begin-sequence2[0:sub_begin].count('-'), start2+sub_end-sequence2[0:sub_end].count('-') ) + fout.write("%s\t%s\t%s\n" % (src1, + start1 + sub_begin - sequence1[0:sub_begin].count('-'), + start1 + sub_end - sequence1[0:sub_end].count('-'))) + fout.write("%s\t%s\t%s\n" % (src2, + start2 + sub_begin - sequence2[0:sub_begin].count('-'), + start2 + sub_end - sequence2[0:sub_end].count('-'))) begin = False else: if begin: - print >> fout, "%s\t%s\t%s" % ( src1, start1+sub_begin-sequence1[0:sub_begin].count('-'), end1+sub_end-sequence1[0:sub_end].count('-') ) - print >> fout, "%s\t%s\t%s" % ( src2, start2+sub_begin-sequence2[0:sub_begin].count('-'), end2+sub_end-sequence2[0:sub_end].count('-') ) + fout.write("%s\t%s\t%s\n" % (src1, + start1 + sub_begin - sequence1[0:sub_begin].count('-'), + end1 + sub_end - sequence1[0:sub_end].count('-'))) + fout.write("%s\t%s\t%s\n" % (src2, + start2 + sub_begin - sequence2[0:sub_begin].count('-'), + end2 + sub_end - sequence2[0:sub_end].count('-'))) begin = False @@ -62,23 +66,23 @@ skipped = 0 not_pairwise = 0 try: - maf_reader = bx.align.maf.Reader( open(inp_file, 'r') ) - except: - stop_err("Your MAF file appears to be malformed.") - print >> fout, "#Chr\tStart\tEnd" + maf_reader = bx.align.maf.Reader(open(inp_file, 'r')) + except Exception: + sys.exit("Your MAF file appears to be malformed.") + fout.write("#Chr\tStart\tEnd\n") for block in maf_reader: if len(block.components) != 2: not_pairwise += 1 continue try: fetchSubs(block) - except: + except Exception: skipped += 1 - + if not_pairwise: - print "Skipped %d non-pairwise blocks" % (not_pairwise) + print("Skipped %d non-pairwise blocks" % (not_pairwise)) if skipped: - print "Skipped %d blocks" % (skipped) + print("Skipped %d blocks" % (skipped)) if __name__ == "__main__":
--- a/substitutions.xml Tue Apr 01 09:12:31 2014 -0400 +++ b/substitutions.xml Mon Jul 06 18:13:37 2020 +0000 @@ -1,24 +1,26 @@ -<tool id="substitutions1" name="Fetch substitutions " version="1.0.0"> - <description> from pairwise alignments</description> - <command interpreter="python"> - substitutions.py - $input - $out_file1 - </command> - <inputs> - <param format="maf" name="input" type="data" label="Select pair-wise alignment data"/> - </inputs> - <outputs> - <data format="tabular" name="out_file1" metadata_source="input"/> - </outputs> - - <tests> - <test> - <param name="input" value="Interval2Maf_pairwise_out.maf"/> - <output name="out_file1" file="subs.out"/> - </test> - </tests> - <help> +<tool id="substitutions1" name="Fetch substitutions " version="1.0.1"> + <description> from pairwise alignments</description> + <requirements> + <requirement type="package" version="0.8.8">bx-python</requirement> + </requirements> + <command> + python '$__tool_directory__/substitutions.py' + '$input' + '$out_file1' + </command> + <inputs> + <param format="maf" name="input" type="data" label="Select pair-wise alignment data"/> + </inputs> + <outputs> + <data format="tabular" name="out_file1" metadata_source="input"/> + </outputs> + <tests> + <test> + <param name="input" value="Interval2Maf_pairwise_out.maf"/> + <output name="out_file1" file="subs.out"/> + </test> + </tests> + <help> .. class:: infomark @@ -34,5 +36,5 @@ Any block/s not containing exactly two sequences, will be omitted. - </help> -</tool> \ No newline at end of file + </help> +</tool>