Mercurial > repos > galaxyp > gffcompare_to_bed
annotate gffcompare_to_bed.py @ 3:ba5368c19dbd draft default tip
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
author | galaxyp |
---|---|
date | Wed, 13 Jan 2021 20:59:52 +0000 |
parents | 9a4cfc910674 |
children |
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) |
2
9a4cfc910674
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 2a470e2c775a7427aa530e058510e4dc7b6d8e80"
galaxyp
parents:
0
diff
changeset
|
34 if isinstance(blockSizes, str): |
0
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 |
2
9a4cfc910674
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 2a470e2c775a7427aa530e058510e4dc7b6d8e80"
galaxyp
parents:
0
diff
changeset
|
40 if isinstance(blockStarts, str): |
0
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 |
3
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
47 def sort_exons(self): |
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
48 sorted_list = [i for i in sorted(zip(self.blockStarts,self.blockSizes))] |
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
49 self.blockStarts = [i[0] for i in sorted_list] |
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
50 self.blockSizes = [i[1] for i in sorted_list] |
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
51 |
0
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
52 def __str__(self): |
3
ba5368c19dbd
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 98ac160e172e3a404163c1af8e2d5ae42a2b425d"
galaxyp
parents:
2
diff
changeset
|
53 self.sort_exons() |
0
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 ','.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
|
59 ','.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
|
60 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
61 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
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 'input', |
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='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
|
68 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
|
69 'output', |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
70 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
|
71 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
|
72 '-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
|
73 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
|
74 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
|
75 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
|
76 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
77 # 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
|
78 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
|
79 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
|
80 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 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
|
85 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 continue |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
93 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
|
94 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
|
95 continue |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
96 (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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 if args.debug: |
2
9a4cfc910674
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 2a470e2c775a7427aa530e058510e4dc7b6d8e80"
galaxyp
parents:
0
diff
changeset
|
102 sys.stderr.write("%s\t%s\n" % ('\t'.join([seqname, source, |
9a4cfc910674
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 2a470e2c775a7427aa530e058510e4dc7b6d8e80"
galaxyp
parents:
0
diff
changeset
|
103 feature, start, end, score, strand, frame]), |
9a4cfc910674
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 2a470e2c775a7427aa530e058510e4dc7b6d8e80"
galaxyp
parents:
0
diff
changeset
|
104 attribute)) |
0
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 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 continue |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
135 |
7e572e148175
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/gffcompare_to_bed commit 321b217382f6be33bd77c7dbb51c8caf5fa50afe
galaxyp
parents:
diff
changeset
|
136 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
|
137 __main__() |