annotate gffcompare_to_bed.py @ 0:7e572e148175 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
author galaxyp
date Thu, 11 Jan 2018 11:16:51 -0500
parents
children 9a4cfc910674
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
2 """
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
3 #
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
4 #------------------------------------------------------------------------------
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
5 # University of Minnesota
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
6 # Copyright 2017, Regents of the University of Minnesota
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
7 #------------------------------------------------------------------------------
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
8 # Author:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
9 #
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
10 # James E Johnson
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
11 #
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
12 #------------------------------------------------------------------------------
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
13 """
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
14
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
15 import argparse
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
16 import sys
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
17
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
18
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
19 class BedEntry(object):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
20 def __init__(self, chrom=None, chromStart=None, chromEnd=None,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
21 name=None, score=None, strand=None,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
22 thickStart=None, thickEnd=None, itemRgb=None,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
23 blockCount=None, blockSizes=None, blockStarts=None):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
24 self.chrom = chrom
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
25 self.chromStart = int(chromStart)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
26 self.chromEnd = int(chromEnd)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
27 self.name = name
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
28 self.score = int(score) if score is not None else 0
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
29 self.strand = '-' if str(strand).startswith('-') else '+'
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
30 self.thickStart = int(thickStart) if thickStart else self.chromStart
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
31 self.thickEnd = int(thickEnd) if thickEnd else self.chromEnd
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
32 self.itemRgb = str(itemRgb) if itemRgb is not None else r'100,100,100'
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
33 self.blockCount = int(blockCount)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
34 if isinstance(blockSizes, str) or isinstance(blockSizes, unicode):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
35 self.blockSizes = [int(x) for x in blockSizes.split(',')]
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
36 elif isinstance(blockSizes, list):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
37 self.blockSizes = [int(x) for x in blockSizes]
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
38 else:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
39 self.blockSizes = blockSizes
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
40 if isinstance(blockStarts, str) or isinstance(blockSizes, unicode):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
41 self.blockStarts = [int(x) for x in blockStarts.split(',')]
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
42 elif isinstance(blockStarts, list):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
43 self.blockStarts = [int(x) for x in blockStarts]
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
44 else:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
45 self.blockStarts = blockStarts
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
46
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
47 def __str__(self):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
48 return '%s\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%s\t%d\t%s\t%s' % (
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
49 self.chrom, self.chromStart, self.chromEnd,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
50 self.name, self.score, self.strand,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
51 self.thickStart, self.thickEnd, str(self.itemRgb), self.blockCount,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
52 ','.join([str(x) for x in self.blockSizes]),
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
53 ','.join([str(x) for x in self.blockStarts]))
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
54
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
55
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
56 def __main__():
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
57 parser = argparse.ArgumentParser(
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
58 description='Retrieve Ensembl cDNAs and three frame translate')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
59 parser.add_argument(
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
60 'input',
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
61 help='GFFCompare annotated GTF file, (-) for stdin')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
62 parser.add_argument(
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
63 'output',
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
64 help='BED file, (-) for stdout')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
65 parser.add_argument(
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
66 '-C', '--class_code', action='append', default=[],
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
67 help='Restrict output to gffcompare class codes')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
68 parser.add_argument('-d', '--debug', action='store_true', help='Debug')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
69 args = parser.parse_args()
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
70
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
71 # print >> sys.stderr, "args: %s" % args
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
72 input_rdr = open(args.input, 'r') if args.input != '-' else sys.stdin
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
73 output_wtr = open(args.output, 'w') if args.output != '-' else sys.stdout
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
74
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
75 def write_bed_entry(bed):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
76 if bed.blockCount == 0:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
77 bed.blockCount = 1
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
78 output_wtr.write("%s\n" % str(bed))
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
79
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
80 class_codes = [c.strip() for codes in args.class_code
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
81 for c in codes.split(',')] if args.class_code else None
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
82 bed = None
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
83 class_code = None
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
84 for i, line in enumerate(input_rdr):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
85 if line.startswith('#'):
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
86 continue
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
87 fields = line.rstrip('\r\n').split('\t')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
88 if len(fields) != 9:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
89 continue
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
90 (seqname, source, feature, start, end,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
91 score, strand, frame, attributes) = fields
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
92 attribute = {i[0]: i[1].strip('"') for i in [j.strip().split(' ')
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
93 for j in attributes.rstrip(';').split(';')]}
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
94 if feature == 'transcript':
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
95 if args.debug:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
96 print >> sys.stderr, "%s\t%s"\
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
97 % ('\t'.join([seqname, source, feature,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
98 start, end, score, strand, frame]),
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
99 attribute)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
100 if bed is not None:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
101 write_bed_entry(bed)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
102 bed = None
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
103 class_code = attribute['class_code'].strip('"')\
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
104 if 'class_code' in attribute else None
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
105 if class_codes and class_code not in class_codes:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
106 continue
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
107 chromStart = int(start) - 1
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
108 chromEnd = int(end)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
109 cat = '_' + class_code if class_code and class_code != '=' else ''
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
110 bed = BedEntry(chrom=seqname,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
111 chromStart=chromStart, chromEnd=chromEnd,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
112 name=attribute['transcript_id'] + cat,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
113 strand=strand,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
114 blockCount=0,
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
115 blockSizes=[chromEnd - chromStart],
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
116 blockStarts=[0])
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
117 elif feature == 'exon' and bed is not None:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
118 chromStart = int(start) - 1
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
119 chromEnd = int(end)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
120 blockSize = chromEnd - chromStart
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
121 if bed.blockCount == 0:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
122 bed.blockSizes = []
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
123 bed.blockStarts = []
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
124 bed.blockSizes.append(blockSize)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
125 bed.blockStarts.append(chromStart - bed.chromStart)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
126 bed.blockCount += 1
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
127 if bed is not None:
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
128 write_bed_entry(bed)
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
129
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
130
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
131 if __name__ == "__main__":
7e572e148175 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff changeset
132 __main__()