diff filter.py @ 2:7a68005de299 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
author iuc
date Sun, 27 Nov 2016 15:01:21 -0500
parents 4e4e4093d65d
children 9b9ae5963d3c
line wrap: on
line diff
--- a/filter.py	Sun Dec 06 05:03:12 2015 -0500
+++ b/filter.py	Sun Nov 27 15:01:21 2016 -0500
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
-## category General
-## desc Removes reads from a BAM file based on criteria
+# category General
+# desc Removes reads from a BAM file based on criteria
 """
 Removes reads from a BAM file based on criteria
 
@@ -17,7 +17,7 @@
     -maxlen val                Remove reads that are larger than {val}
     -mapped                    Keep only mapped reads
     -unmapped                  Keep only unmapped reads
-    -properpair                Keep only properly paired reads (both mapped, 
+    -properpair                Keep only properly paired reads (both mapped,
                                correct orientation, flag set in BAM)
     -noproperpair              Keep only not-properly paired reads
 
@@ -110,11 +110,11 @@
 
 import os
 import sys
+
 import pysam
-from ngsutils.bam import bam_iter
+from ngsutils.bam import bam_iter, read_calc_mismatches, read_calc_mismatches_gen, read_calc_mismatches_ref, read_calc_variations
+from ngsutils.bed import BedFile
 from ngsutils.support.dbsnp import DBSNP
-from ngsutils.bam import read_calc_mismatches, read_calc_mismatches_ref, read_calc_mismatches_gen, read_calc_variations
-from ngsutils.bed import BedFile
 
 
 def usage():
@@ -207,7 +207,7 @@
                 for k in del_list:
                     self.rev_pos.remove(k)
 
-            if not start_pos in self.rev_pos:
+            if start_pos not in self.rev_pos:
                 self.rev_pos.add(start_pos)
                 return True
             return False
@@ -344,6 +344,7 @@
     def close(self):
         pass
 
+
 class IncludeRef(object):
     def __init__(self, ref):
         self.ref = ref
@@ -645,7 +646,7 @@
 
 class MaskFlag(object):
     def __init__(self, value):
-        if type(value) == type(1):
+        if isinstance(value, int):
             self.flag = value
         else:
             if value[0:2] == '0x':
@@ -710,7 +711,7 @@
         return "maximum mismatch ratio: %s" % self.val
 
     def filter(self, bam, read):
-        return read_calc_mismatches(read) <= self.ratio*len(read.seq)
+        return read_calc_mismatches(read) <= self.ratio * len(read.seq)
 
     def close(self):
         pass
@@ -826,6 +827,7 @@
             return True
         return False
 
+
 _criteria = {
     'mapped': Mapped,
     'unmapped': Unmapped,
@@ -895,7 +897,7 @@
                 failed += 1
                 if failed_out:
                     failed_out.write('%s\t%s\n' % (read.qname, criterion))
-                #outfile.write(read_to_unmapped(read))
+                # outfile.write(read_to_unmapped(read))
                 break
         if p:
             passed += 1
@@ -930,6 +932,7 @@
     read.mapq = 0
     return read
 
+
 if __name__ == '__main__':
     infile = None
     outfile = None