Mercurial > repos > iuc > ngsutils_bam_filter
comparison filter.py @ 3:9b9ae5963d3c draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
author | iuc |
---|---|
date | Mon, 23 Oct 2017 13:27:02 -0400 |
parents | 7a68005de299 |
children | 49bf71fbc574 |
comparison
equal
deleted
inserted
replaced
2:7a68005de299 | 3:9b9ae5963d3c |
---|---|
105 MAPQ Mapping quality (defined as part of SAM spec) | 105 MAPQ Mapping quality (defined as part of SAM spec) |
106 | 106 |
107 The tag type (:i, :f, :Z) is optional. | 107 The tag type (:i, :f, :Z) is optional. |
108 | 108 |
109 """ | 109 """ |
110 from __future__ import print_function | |
110 | 111 |
111 import os | 112 import os |
112 import sys | 113 import sys |
113 | 114 |
114 import pysam | 115 import pysam |
116 from ngsutils.bed import BedFile | 117 from ngsutils.bed import BedFile |
117 from ngsutils.support.dbsnp import DBSNP | 118 from ngsutils.support.dbsnp import DBSNP |
118 | 119 |
119 | 120 |
120 def usage(): | 121 def usage(): |
121 print __doc__ | 122 print(__doc__) |
122 print """ | 123 print(""" |
123 Usage: bamutils filter in.bam out.bam {-failed out.txt} criteria... | 124 Usage: bamutils filter in.bam out.bam {-failed out.txt} criteria... |
124 | 125 |
125 Options: | 126 Options: |
126 -failed fname A text file containing the read names of all reads | 127 -failed fname A text file containing the read names of all reads |
127 that were removed with filtering | 128 that were removed with filtering |
129 Example: | 130 Example: |
130 bamutils filter filename.bam output.bam -mapped -gte AS:i 1000 | 131 bamutils filter filename.bam output.bam -mapped -gte AS:i 1000 |
131 | 132 |
132 This will remove all unmapped reads, as well as any reads that have an AS:i | 133 This will remove all unmapped reads, as well as any reads that have an AS:i |
133 value less than 1000. | 134 value less than 1000. |
134 """ | 135 """) |
135 sys.exit(1) | 136 sys.exit(1) |
136 | 137 |
137 | 138 |
138 class Unique(object): | 139 class Unique(object): |
139 def __init__(self, length=None): | 140 def __init__(self, length=None): |
758 self.tag = tag | 759 self.tag = tag |
759 | 760 |
760 # guess at type... | 761 # guess at type... |
761 try: | 762 try: |
762 self.value = int(value) | 763 self.value = int(value) |
763 except: | 764 except ValueError: |
764 try: | 765 try: |
765 self.value = float(value) | 766 self.value = float(value) |
766 except: | 767 except ValueError: |
767 self.value = value | 768 self.value = value |
768 | 769 |
769 def get_value(self, read): | 770 def get_value(self, read): |
770 if self.tag == 'MAPQ': | 771 if self.tag == 'MAPQ': |
771 return read.mapq | 772 return read.mapq |
958 infile = arg | 959 infile = arg |
959 elif not outfile: | 960 elif not outfile: |
960 outfile = arg | 961 outfile = arg |
961 elif arg[0] == '-': | 962 elif arg[0] == '-': |
962 if not arg[1:] in _criteria: | 963 if not arg[1:] in _criteria: |
963 print "Unknown criterion: %s" % arg | 964 print("Unknown criterion: %s" % arg) |
964 fail = True | 965 fail = True |
965 if crit_args: | 966 if crit_args: |
966 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:])) | 967 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:])) |
967 crit_args = [arg, ] | 968 crit_args = [arg, ] |
968 elif crit_args: | 969 elif crit_args: |
969 crit_args.append(arg) | 970 crit_args.append(arg) |
970 else: | 971 else: |
971 print "Unknown argument: %s" % arg | 972 print("Unknown argument: %s" % arg) |
972 fail = True | 973 fail = True |
973 | 974 |
974 if not fail and crit_args: | 975 if not fail and crit_args: |
975 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:])) | 976 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:])) |
976 | 977 |
977 if fail or not infile or not outfile or not criteria: | 978 if fail or not infile or not outfile or not criteria: |
978 if not infile and not outfile and not criteria: | 979 if not infile and not outfile and not criteria: |
979 usage() | 980 usage() |
980 | 981 |
981 if not infile: | 982 if not infile: |
982 print "Missing: input bamfile" | 983 print("Missing: input bamfile") |
983 if not outfile: | 984 if not outfile: |
984 print "Missing: output bamfile" | 985 print("Missing: output bamfile") |
985 if not criteria: | 986 if not criteria: |
986 print "Missing: filtering criteria" | 987 print("Missing: filtering criteria") |
987 usage() | 988 usage() |
988 else: | 989 else: |
989 bam_filter(infile, outfile, criteria, failed, verbose) | 990 bam_filter(infile, outfile, criteria, failed, verbose) |