annotate filter.py @ 5:8d56004aed6a 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:00:58 -0500
parents 60115871d49e
children 65c2eb88b635
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
1 #!/usr/bin/env python
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
2 # category General
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
3 # desc Removes reads from a BAM file based on criteria
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
4 """
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
5 Removes reads from a BAM file based on criteria
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
6
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
7 Given a BAM file, this script will only allow reads that meet filtering
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
8 criteria to be written to output. The output is another BAM file with the
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
9 reads not matching the criteria removed.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
10
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
11 Note: this does not adjust tag values reflecting any filtering. (for example:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
12 if a read mapped to two locations (IH:i:2), and one was removed by
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
13 filtering, the IH:i tag would still read IH:i:2).
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
14
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
15 Currently, the available filters are:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
16 -minlen val Remove reads that are smaller than {val}
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
17 -maxlen val Remove reads that are larger than {val}
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
18 -mapped Keep only mapped reads
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
19 -unmapped Keep only unmapped reads
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
20 -properpair Keep only properly paired reads (both mapped,
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
21 correct orientation, flag set in BAM)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
22 -noproperpair Keep only not-properly paired reads
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
23
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
24 -mask bitmask Remove reads that match the mask (base 10/hex)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
25 -uniq {length} Remove reads that are have the same sequence
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
26 Note: BAM file should be sorted
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
27 (up to an optional length)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
28 -uniq_start Remove reads that start at the same position
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
29 Note: BAM file should be sorted
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
30 (Use only for low-coverage samples)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
31
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
32 -mismatch num # mismatches or indels
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
33 indel always counts as 1 regardless of length
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
34 (requires NM tag in reads)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
35
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
36 -mismatch_dbsnp num dbsnp.txt.bgz
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
37 # mismatches or indels - not in dbSNP.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
38 Variations are called using the MD tag.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
39 Variations that are found in the dbSNP list are
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
40 not counted as mismatches. The dbSNP list is a
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
41 Tabix-indexed dump of dbSNP (from UCSC Genome
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
42 Browser). Indels in dbSNP are also counted.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
43 Adds a 'ZS:i' tag with the number of found SNPs
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
44 in the read.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
45 (requires NM and MD tags)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
46
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
47 Example command for indexing:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
48 ngsutils tabixindex snp.txt.gz -s 2 -b 3 -e 4 -0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
49
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
50 -mismatch_ref num ref.fa # mismatches or indel - looks up mismatches
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
51 directly in a reference FASTA file
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
52 (use if NM tag not present)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
53
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
54 -mismatch_ref_dbsnp num ref.fa dbsnp.txt.bgz
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
55 # mismatches or indels - looks up mismatches
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
56 directly from a reference FASTA file. (See
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
57 -mismatch_dbsnp for dbSNP matching)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
58 (use if NM or MD tag not present)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
59
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
60 -nosecondary Remove reads that have the 0x100 flag set
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
61 -noqcfail Remove reads that have the 0x200 flag set
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
62 -nopcrdup Remove reads that have the 0x400 flag set
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
63
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
64
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
65 -exclude ref:start-end Remove reads in this region (1-based start)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
66 -excludebed file.bed {nostrand}
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
67 Remove reads that are in any of the regions
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
68 from the given BED file. If 'nostrand' is given,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
69 strand information from the BED file is ignored.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
70
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
71 -include ref:start-end Remove reads NOT in the region (can only be one)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
72 -includebed file.bed {nostrand}
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
73 Remove reads that are NOT any of the regions
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
74 from the given BED file. If 'nostrand' is given,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
75 strand information from the BED file is ignored.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
76
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
77 Note: If this is a large dataset, use
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
78 "bamutils extract" instead.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
79
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
80 -includeref refname Exclude reads NOT mapped to a reference
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
81 -excluderef refname Exclude reads mapped to a particular reference
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
82 (e.g. chrM, or _dup chromosomes)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
83
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
84 -whitelist fname Remove reads that aren't on this list (by name)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
85 -blacklist fname Remove reads that are on this list (by name)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
86 These lists can be whitespace-delimited with
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
87 the read name as the first column.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
88 -maximum_mismatch_ratio val
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
89 Filter by maximum mismatch ratio (fraction of length)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
90
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
91 -eq tag_name value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
92 -lt tag_name value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
93 -lte tag_name value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
94 -gt tag_name value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
95 -gte tag_name value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
96
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
97 As a special case, "MAPQ" can be used as the tag_name and the SAM MAPQ
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
98 value will be used.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
99
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
100 Common tags to filter by:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
101 AS Alignment score
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
102 IH Number of alignments
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
103 NM Edit distance (each indel counts as many as its length)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
104
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
105 MAPQ Mapping quality (defined as part of SAM spec)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
106
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
107 The tag type (:i, :f, :Z) is optional.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
108
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
109 """
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
110
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
111 import os
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
112 import sys
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
113
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
114 import pysam
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
115 from ngsutils.bam import bam_iter, read_calc_mismatches, read_calc_mismatches_gen, read_calc_mismatches_ref, read_calc_variations
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
116 from ngsutils.bed import BedFile
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
117 from ngsutils.support.dbsnp import DBSNP
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
118
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
119
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
120 def usage():
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
121 print __doc__
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
122 print """
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
123 Usage: bamutils filter in.bam out.bam {-failed out.txt} criteria...
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
124
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
125 Options:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
126 -failed fname A text file containing the read names of all reads
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
127 that were removed with filtering
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
128
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
129 Example:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
130 bamutils filter filename.bam output.bam -mapped -gte AS:i 1000
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
131
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
132 This will remove all unmapped reads, as well as any reads that have an AS:i
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
133 value less than 1000.
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
134 """
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
135 sys.exit(1)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
136
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
137
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
138 class Unique(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
139 def __init__(self, length=None):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
140 if length:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
141 self.length = int(length)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
142 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
143 self.length = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
144
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
145 self.last_pos = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
146 self.pos_reads = set()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
147
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
148 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
149 return "uniq"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
150
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
151 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
152 if self.last_pos != (read.tid, read.pos):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
153 self.last_pos = (read.tid, read.pos)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
154 self.pos_reads = set()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
155
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
156 if read.is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
157 seq = read.seq[::-1] # ignore revcomp for now, it isn't needed, just need to compare in the proper order
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
158 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
159 seq = read.seq
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
160
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
161 if self.length:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
162 seq = seq[:self.length]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
163
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
164 if seq in self.pos_reads:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
165 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
166
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
167 self.pos_reads.add(seq)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
168 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
169
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
170 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
171 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
172
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
173
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
174 class UniqueStart(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
175 def __init__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
176 self.last_tid = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
177 self.last_fwd_pos = -1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
178 self.rev_pos_list = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
179
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
180 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
181 return "uniq_start"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
182
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
183 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
184 if self.last_tid is None or self.last_tid != read.tid:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
185 self.last_tid = read.tid
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
186 self.rev_pos = set()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
187 self.last_fwd_pos = -1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
188 self.last_rev_pos = -1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
189
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
190 if read.is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
191 # check reverse reads from their start (3' aend)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
192 # these aren't necessarily in the correct
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
193 # order in the file, so we have to track them in a set
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
194
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
195 start_pos = read.aend
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
196
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
197 # clean up hash if necesary
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
198 # Allow up to 100k over, to balance cleaning up the rev_pos hash
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
199 # and memory
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
200 if read.pos > (self.last_rev_pos + 100000):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
201 self.last_rev_pos = start_pos
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
202 del_list = []
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
203 for k in self.rev_pos:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
204 if k < read.pos:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
205 del_list.append(k)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
206
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
207 for k in del_list:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
208 self.rev_pos.remove(k)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
209
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
210 if start_pos not in self.rev_pos:
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
211 self.rev_pos.add(start_pos)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
212 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
213 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
214 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
215 if read.pos != self.last_fwd_pos:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
216 self.last_fwd_pos = read.pos
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
217 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
218 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
219
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
220 # if self.last_pos != (read.tid, read.pos):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
221 # self.last_pos = (read.tid, read.pos)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
222 # return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
223 # return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
224
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
225 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
226 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
227
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
228
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
229 class Blacklist(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
230 def __init__(self, fname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
231 self.fname = fname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
232 self.notallowed = set()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
233 with open(fname) as f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
234 for line in f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
235 self.notallowed.add(line.strip().split()[0])
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
236
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
237 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
238 return read.qname not in self.notallowed
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
239
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
240 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
241 return 'Blacklist: %s' % (self.fname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
242
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
243 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
244 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
245
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
246
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
247 class Whitelist(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
248 def __init__(self, fname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
249 self.fname = fname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
250 self.allowed = set()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
251 with open(fname) as f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
252 for line in f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
253 self.allowed.add(line.strip().split()[0])
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
254
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
255 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
256 return read.qname in self.allowed
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
257
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
258 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
259 return 'Whitelist: %s' % (self.fname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
260
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
261 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
262 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
263
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
264
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
265 class IncludeRegion(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
266 _excludes = []
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
267 _last = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
268
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
269 def __init__(self, region):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
270 IncludeRegion._excludes.append(ExcludeRegion(region))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
271 # self.excl = ExcludeRegion(region)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
272
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
273 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
274 if read == IncludeRegion._last:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
275 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
276
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
277 IncludeRegion._last = read
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
278
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
279 for excl in IncludeRegion._excludes:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
280 if not excl.filter(bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
281 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
282 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
283
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
284 # return not self.excl.filter(bam,read)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
285 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
286 return 'Including: %s' % (self.excl.region)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
287
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
288 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
289 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
290
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
291
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
292 class IncludeBED(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
293 def __init__(self, fname, nostrand=None):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
294 self.excl = ExcludeBED(fname, nostrand)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
295
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
296 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
297 return not self.excl.filter(bam, read)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
298
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
299 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
300 return 'Including from BED: %s%s' % (self.excl.fname, ' nostrand' if self.excl.nostrand else '')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
301
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
302 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
303 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
304
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
305
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
306 class ExcludeRegion(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
307 def __init__(self, region):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
308 self.region = region
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
309 spl = region.split(':')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
310 self.chrom = spl[0]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
311 se = [int(x) for x in spl[1].split('-')]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
312 self.start = se[0] - 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
313 self.end = se[1]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
314
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
315 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
316 if not read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
317 if bam.getrname(read.tid) == self.chrom:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
318 if self.start <= read.pos <= self.end:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
319 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
320 if self.start <= read.aend <= self.end:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
321 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
322 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
323
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
324 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
325 return 'Excluding: %s' % (self.region)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
326
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
327 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
328 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
329
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
330
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
331 class ExcludeRef(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
332 def __init__(self, ref):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
333 self.ref = ref
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
334
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
335 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
336 if not read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
337 if bam.getrname(read.tid) == self.ref:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
338 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
339 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
340
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
341 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
342 return 'Excluding: %s' % (self.ref)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
343
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
344 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
345 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
346
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
347
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
348 class IncludeRef(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
349 def __init__(self, ref):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
350 self.ref = ref
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
351
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
352 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
353 if not read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
354 if bam.getrname(read.tid) == self.ref:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
355 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
356 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
357
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
358 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
359 return 'Including: %s' % (self.ref)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
360
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
361 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
362 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
363
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
364
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
365 class ExcludeBED(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
366 def __init__(self, fname, nostrand=None):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
367 self.regions = {} # store BED regions as keyed bins (chrom, bin)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
368 self.fname = fname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
369 if nostrand == 'nostrand':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
370 self.nostrand = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
371 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
372 self.nostrand = False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
373
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
374 self.bed = BedFile(fname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
375 # with open(fname) as f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
376 # for line in f:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
377 # if not line:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
378 # continue
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
379 # if line[0] == '#':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
380 # continue
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
381 # cols = line.strip().split('\t')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
382
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
383 # chrom = cols[0]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
384 # start = int(cols[1])
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
385 # end = int(cols[2])
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
386 # if self.nostrand:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
387 # strand = '?'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
388 # else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
389 # strand = cols[5]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
390
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
391 # startbin = start / 100000
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
392 # endbin = end / 100000
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
393
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
394 # for bin in xrange(startbin, endbin + 1):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
395 # if not (chrom, bin) in self.regions:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
396 # self.regions[(chrom, bin)] = []
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
397 # self.regions[(chrom, bin)].append((start, end, strand))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
398
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
399 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
400 if not read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
401 if self.nostrand:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
402 strand = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
403 elif read.is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
404 strand = '-'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
405 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
406 strand = '+'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
407
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
408 for region in self.bed.fetch(bam.getrname(read.tid), read.pos, read.aend, strand):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
409 # region found, exclude read
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
410 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
411 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
412
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
413 # bin = read.pos / 100000
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
414 # ref = bam.getrname(read.tid)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
415
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
416 # if not (ref, bin) in self.regions:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
417 # return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
418
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
419 # for start, end, strand in self.regions[(ref, bin)]:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
420 # if not self.nostrand:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
421 # if strand == '+' and read.is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
422 # continue
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
423 # if strand == '-' and not read.is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
424 # continue
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
425 # if start <= read.pos <= end:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
426 # return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
427 # if start <= read.aend <= end:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
428 # return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
429 # return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
430
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
431 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
432 return 'Excluding from BED: %s%s' % (self.fname, ' nostrand' if self.nostrand else '')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
433
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
434 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
435 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
436
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
437
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
438 class Mismatch(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
439 def __init__(self, num):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
440 self.num = int(num)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
441
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
442 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
443 if read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
444 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
445
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
446 if read_calc_mismatches(read) > self.num:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
447 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
448
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
449 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
450
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
451 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
452 return '>%s mismatch%s' % (self.num, '' if self.num == 1 else 'es')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
453
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
454 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
455 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
456
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
457
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
458 class MismatchRef(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
459 def __init__(self, num, refname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
460 self.num = int(num)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
461 self.refname = refname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
462
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
463 if not os.path.exists('%s.fai' % refname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
464 pysam.faidx(refname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
465
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
466 self.ref = pysam.Fastafile(refname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
467
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
468 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
469 if read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
470 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
471
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
472 chrom = bam.getrname(read.tid)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
473 if read_calc_mismatches_ref(self.ref, read, chrom) > self.num:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
474 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
475
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
476 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
477
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
478 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
479 return '>%s mismatch%s in %s' % (self.num, '' if self.num == 1 else 'es', os.path.basename(self.refname))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
480
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
481 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
482 self.ref.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
483
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
484
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
485 class MismatchDbSNP(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
486 def __init__(self, num, fname, verbose=None):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
487 sys.stderr.write('Note: MismatchDbSNP is considered *experimental*\n')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
488
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
489 self.num = int(num)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
490 self.fname = fname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
491 self.dbsnp = DBSNP(fname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
492 if verbose == 'verbose':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
493 self.verbose = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
494 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
495 self.verbose = False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
496
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
497 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
498 if read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
499 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
500
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
501 if read_calc_mismatches(read) <= self.num:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
502 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
503
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
504 chrom = bam.getrname(read.tid)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
505
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
506 mm = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
507 snps = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
508
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
509 for op, pos, seq in read_calc_variations(read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
510 if not self.dbsnp.is_valid_variation(chrom, op, pos, seq, self.verbose):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
511 mm += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
512 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
513 snps += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
514
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
515 if mm > self.num:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
516 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
517
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
518 if snps:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
519 read.tags = read.tags + [('ZS', snps)]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
520
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
521 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
522
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
523 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
524 return '>%s mismatch%s using %s' % (self.num, '' if self.num == 1 else 'es', os.path.basename(self.fname))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
525
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
526 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
527 self.dbsnp.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
528
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
529
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
530 class MismatchRefDbSNP(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
531 def __init__(self, num, refname, dbsnpname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
532 sys.stderr.write('Note: MismatchRefDbSNP is considered *experimental*\n')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
533 self.num = int(num)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
534 self.refname = refname
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
535 self.dbsnp = DBSNP(dbsnpname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
536
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
537 if not os.path.exists('%s.fai' % refname):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
538 pysam.faidx(refname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
539
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
540 self.ref = pysam.Fastafile(refname)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
541
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
542 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
543 if read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
544 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
545
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
546 chrom = bam.getrname(read.tid)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
547
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
548 mm = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
549 snps = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
550
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
551 for op, pos, seq in read_calc_mismatches_gen(self.ref, read, chrom):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
552 if not self.dbsnp.is_valid_variation(chrom, op, pos, seq):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
553 mm += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
554 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
555 snps += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
556
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
557 if mm > self.num:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
558 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
559
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
560 if snps:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
561 read.tags = read.tags + [('ZS', snps)]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
562
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
563 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
564
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
565 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
566 return '>%s mismatch%s using %s/%s' % (self.num, '' if self.num == 1 else 'es', os.path.basename(self.dbsnpname), os.path.basename(self.refname))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
567
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
568 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
569 self.ref.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
570 self.dbsnp.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
571
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
572
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
573 class Mapped(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
574 def __init__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
575 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
576
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
577 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
578 if read.is_paired and (read.is_unmapped or read.mate_is_unmapped):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
579 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
580 elif read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
581 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
582 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
583
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
584 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
585 return 'is mapped'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
586
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
587 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
588 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
589
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
590
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
591 class Unmapped(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
592 def __init__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
593 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
594
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
595 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
596 if read.is_paired and (read.is_unmapped or read.mate_is_unmapped):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
597 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
598 elif read.is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
599 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
600 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
601
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
602 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
603 return 'is unmapped'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
604
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
605 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
606 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
607
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
608
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
609 class ProperPair(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
610 def __init__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
611 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
612
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
613 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
614 if not read.is_paired:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
615 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
616
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
617 if read.is_unmapped or read.mate_is_unmapped:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
618 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
619
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
620 if read.is_reverse == read.mate_is_reverse:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
621 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
622
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
623 return read.is_proper_pair
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
624
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
625 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
626 return 'proper pair'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
627
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
628 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
629 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
630
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
631
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
632 class NoProperPair(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
633 def __init__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
634 self.proper = ProperPair()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
635 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
636
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
637 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
638 return not self.proper.filter(bam, read)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
639
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
640 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
641 return 'not proper pairs'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
642
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
643 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
644 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
645
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
646
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
647 class MaskFlag(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
648 def __init__(self, value):
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
649 if isinstance(value, int):
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
650 self.flag = value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
651 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
652 if value[0:2] == '0x':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
653 self.flag = int(value, 16)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
654 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
655 self.flag = int(value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
656
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
657 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
658 return "Doesn't match flag: %s" % self.flag
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
659
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
660 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
661 return (read.flag & self.flag) == 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
662
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
663 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
664 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
665
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
666
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
667 class SecondaryFlag(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
668 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
669 return "no 0x100 (secondary) flag"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
670
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
671 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
672 return not read.is_secondary
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
673
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
674 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
675 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
676
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
677
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
678 class ReadMinLength(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
679 def __init__(self, minval):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
680 self.minval = int(minval)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
681
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
682 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
683 return "read length min: %s" % self.minval
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
684
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
685 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
686 return len(read.seq) >= self.minval
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
687
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
688 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
689 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
690
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
691
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
692 class ReadMaxLength(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
693 def __init__(self, val):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
694 self.val = int(val)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
695
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
696 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
697 return "read length max: %s" % self.val
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
698
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
699 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
700 return len(read.seq) <= self.val
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
701
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
702 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
703 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
704
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
705
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
706 class MaximumMismatchRatio(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
707 def __init__(self, ratio):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
708 self.ratio = float(ratio)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
709
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
710 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
711 return "maximum mismatch ratio: %s" % self.val
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
712
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
713 def filter(self, bam, read):
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
714 return read_calc_mismatches(read) <= self.ratio * len(read.seq)
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
715
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
716 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
717 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
718
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
719
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
720 class QCFailFlag(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
721 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
722 return "no 0x200 (qcfail) flag"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
723
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
724 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
725 return not read.is_qcfail
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
726
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
727 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
728 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
729
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
730
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
731 class PCRDupFlag(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
732 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
733 return "no 0x400 (pcrdup) flag"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
734
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
735 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
736 return not read.is_duplicate
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
737
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
738 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
739 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
740
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
741
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
742 class _TagCompare(object):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
743 def __init__(self, tag, value):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
744 self.args = '%s %s' % (tag, value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
745
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
746 if ':' in tag:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
747 self.tag = tag.split(':')[0]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
748 tagtype = tag.split(':')[1]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
749 if tagtype == 'i':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
750 self.value = int(value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
751 elif tagtype == 'f':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
752 self.value = float(value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
753 elif tagtype == 'H':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
754 self.value = int(value) # not sure about this
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
755 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
756 self.value = value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
757 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
758 self.tag = tag
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
759
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
760 # guess at type...
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
761 try:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
762 self.value = int(value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
763 except:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
764 try:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
765 self.value = float(value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
766 except:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
767 self.value = value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
768
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
769 def get_value(self, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
770 if self.tag == 'MAPQ':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
771 return read.mapq
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
772
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
773 for name, value in read.tags:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
774 if name == self.tag:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
775 return value
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
776
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
777 return None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
778
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
779 def __repr__(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
780 return "%s %s %s" % (self.tag, self.__class__.op, self.value)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
781
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
782 def close(self):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
783 pass
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
784
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
785
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
786 class TagLessThan(_TagCompare):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
787 op = '<'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
788
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
789 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
790 if self.get_value(read) < self.value:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
791 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
792 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
793
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
794
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
795 class TagLessThanEqual(_TagCompare):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
796 op = '<='
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
797
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
798 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
799 if self.get_value(read) <= self.value:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
800 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
801 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
802
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
803
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
804 class TagGreaterThan(_TagCompare):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
805 op = '>'
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
806
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
807 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
808 if self.get_value(read) > self.value:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
809 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
810 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
811
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
812
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
813 class TagGreaterThanEqual(_TagCompare):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
814 op = '>='
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
815
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
816 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
817 if self.get_value(read) >= self.value:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
818 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
819 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
820
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
821
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
822 class TagEqual(_TagCompare):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
823 op = '='
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
824
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
825 def filter(self, bam, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
826 if self.get_value(read) == self.value:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
827 return True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
828 return False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
829
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
830
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
831 _criteria = {
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
832 'mapped': Mapped,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
833 'unmapped': Unmapped,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
834 'properpair': ProperPair,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
835 'noproperpair': NoProperPair,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
836 'noqcfail': QCFailFlag,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
837 'nosecondary': SecondaryFlag,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
838 'nopcrdup': PCRDupFlag,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
839 'mask': MaskFlag,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
840 'lt': TagLessThan,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
841 'gt': TagGreaterThan,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
842 'lte': TagLessThanEqual,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
843 'gte': TagGreaterThanEqual,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
844 'eq': TagEqual,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
845 'mismatch': Mismatch,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
846 'mismatch_ref': MismatchRef,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
847 'mismatch_dbsnp': MismatchDbSNP,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
848 'mismatch_ref_dbsnp': MismatchRefDbSNP,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
849 'exclude': ExcludeRegion,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
850 'excludebed': ExcludeBED,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
851 'excluderef': ExcludeRef,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
852 'includeref': IncludeRef,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
853 'include': IncludeRegion,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
854 'includebed': IncludeBED,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
855 'whitelist': Whitelist,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
856 'blacklist': Blacklist,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
857 'length': ReadMinLength, # deprecated
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
858 'minlen': ReadMinLength,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
859 'maxlen': ReadMaxLength,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
860 'uniq': Unique,
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
861 'maximum_mismatch_ratio': MaximumMismatchRatio
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
862 }
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
863
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
864
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
865 def bam_filter(infile, outfile, criteria, failedfile=None, verbose=False):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
866 if verbose:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
867 sys.stderr.write('Input file : %s\n' % infile)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
868 sys.stderr.write('Output file : %s\n' % outfile)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
869 if failedfile:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
870 sys.stderr.write('Failed reads: %s\n' % failedfile)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
871 sys.stderr.write('Criteria:\n')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
872 for criterion in criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
873 sys.stderr.write(' %s\n' % criterion)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
874
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
875 sys.stderr.write('\n')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
876
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
877 bamfile = pysam.Samfile(infile, "rb")
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
878 outfile = pysam.Samfile(outfile, "wb", template=bamfile)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
879
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
880 if failedfile:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
881 failed_out = open(failedfile, 'w')
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
882 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
883 failed_out = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
884
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
885 passed = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
886 failed = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
887
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
888 def _callback(read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
889 return "%s | %s kept,%s failed" % ('%s:%s' % (bamfile.getrname(read.tid), read.pos) if read.tid > -1 else 'unk', passed, failed)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
890
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
891 for read in bam_iter(bamfile, quiet=True):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
892 p = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
893
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
894 for criterion in criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
895 if not criterion.filter(bamfile, read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
896 p = False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
897 failed += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
898 if failed_out:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
899 failed_out.write('%s\t%s\n' % (read.qname, criterion))
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
900 # outfile.write(read_to_unmapped(read))
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
901 break
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
902 if p:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
903 passed += 1
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
904 outfile.write(read)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
905
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
906 bamfile.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
907 outfile.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
908 if failed_out:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
909 failed_out.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
910 sys.stdout.write("%s kept\n%s failed\n" % (passed, failed))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
911
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
912 for criterion in criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
913 criterion.close()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
914
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
915
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
916 def read_to_unmapped(read):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
917 '''
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
918 Example unmapped read
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
919 2358_2045_1839 | 4 | * | 0 | 0 | * | * | 0 | 0 | GGACGAGAAGGAGTATTTCTCCGAGAACACATTCACGGAGAGTCTAACTC | 0QT\VNO^IIRJKXTIHIKTY\STZZ[XOJKPWLHJQQQ^XPQYIIRQII | PG:Z:bfast | AS:i:- | NH:i:0 | IH:i:1 | HI:i:1 | CS:Z:T10213222020221330022203222011113021130222212230122 | CQ:Z:019=2+><%@.'>52%)'15?90<7;:5+(-49('-7-<>5-@5%<.2%= | CM:i:0 | XA:i:4
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
920
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
921 Example mapped read:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
922 2216_1487_198 | 16 | chr11:19915291-19925392 | 5531 | 12 | 24M2D26M | * | 0 | 0 | TCTGTCTGGGTGCAGTAGCTATACGTAATCCCAGCACTTTGGGAGGCCAA | 1C8FZ`M""""""WZ""%"#\I;"`R@D]``ZZ``\QKX\Y]````IK^` | PG:Z:bfast | AS:i:1150 | NM:i:2 | NH:i:10 | IH:i:1 | HI:i:1 | MD:Z:24^CT26 | CS:Z:T00103022001002113210023031213331122121223321221122 | CQ:Z:A8=%;AB<;97<3/9:>>3>@?5&18@-%;866:94=14:=?,%?:7&)1 | CM:i:9 | XA:i:4 | XE:Z:-------23322---2-11----2----------------------------
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
923
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
924 '''
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
925 # TODO: rewrite read properties to unmapped state
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
926 # if colorspace: convert CS to NT directly
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
927 # remove excess tags
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
928
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
929 read.is_unmapped = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
930 read.tid = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
931 read.pos = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
932 read.mapq = 0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
933 return read
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
934
5
8d56004aed6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 0
diff changeset
935
0
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
936 if __name__ == '__main__':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
937 infile = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
938 outfile = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
939 failed = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
940 criteria = []
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
941
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
942 crit_args = []
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
943 last = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
944 verbose = False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
945 fail = False
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
946
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
947 for arg in sys.argv[1:]:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
948 if last == '-failed':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
949 failed = arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
950 last = None
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
951 elif arg == '-h':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
952 usage()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
953 elif arg == '-failed':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
954 last = arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
955 elif arg == '-v':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
956 verbose = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
957 elif not infile and os.path.exists(arg):
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
958 infile = arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
959 elif not outfile:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
960 outfile = arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
961 elif arg[0] == '-':
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
962 if not arg[1:] in _criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
963 print "Unknown criterion: %s" % arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
964 fail = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
965 if crit_args:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
966 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:]))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
967 crit_args = [arg, ]
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
968 elif crit_args:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
969 crit_args.append(arg)
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
970 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
971 print "Unknown argument: %s" % arg
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
972 fail = True
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
973
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
974 if not fail and crit_args:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
975 criteria.append(_criteria[crit_args[0][1:]](*crit_args[1:]))
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
976
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
977 if fail or not infile or not outfile or not criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
978 if not infile and not outfile and not criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
979 usage()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
980
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
981 if not infile:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
982 print "Missing: input bamfile"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
983 if not outfile:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
984 print "Missing: output bamfile"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
985 if not criteria:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
986 print "Missing: filtering criteria"
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
987 usage()
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
988 else:
60115871d49e planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 4a7736168ec93adb93e6c7d21d80b201ea5c5352-dirty
iuc
parents:
diff changeset
989 bam_filter(infile, outfile, criteria, failed, verbose)