annotate bedutil.py @ 0:da1b538b87e5 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
author galaxyp
date Mon, 22 Jan 2018 13:13:47 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
2 """
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
3 #
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
4 #------------------------------------------------------------------------------
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
5 # University of Minnesota
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
6 # Copyright 2016, Regents of the University of Minnesota
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
7 #------------------------------------------------------------------------------
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
8 # Author:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
9 #
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
10 # James E Johnson
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
11 #
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
12 #------------------------------------------------------------------------------
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
13 """
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
14
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
15 from __future__ import print_function
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
16
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
17 import sys
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
18
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
19 from Bio.Seq import reverse_complement, translate
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
20
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
21
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
22 def bed_from_line(line, ensembl=False, seq_column=None):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
23 fields = line.rstrip('\r\n').split('\t')
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
24 if len(fields) < 12:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
25 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
26 (chrom, chromStart, chromEnd, name, score, strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
27 thickStart, thickEnd, itemRgb,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
28 blockCount, blockSizes, blockStarts) = fields[0:12]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
29 bed_entry = BedEntry(chrom=chrom, chromStart=chromStart, chromEnd=chromEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
30 name=name, score=score, strand=strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
31 thickStart=thickStart, thickEnd=thickEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
32 itemRgb=itemRgb,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
33 blockCount=blockCount,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
34 blockSizes=blockSizes.rstrip(','),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
35 blockStarts=blockStarts.rstrip(','))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
36 if seq_column is not None and -len(fields) <= seq_column < len(fields):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
37 bed_entry.seq = fields[seq_column]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
38 if ensembl and len(fields) >= 20:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
39 bed_entry.second_name = fields[12]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
40 bed_entry.cds_start_status = fields[13]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
41 bed_entry.cds_end_status = fields[14]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
42 bed_entry.exon_frames = fields[15].rstrip(',')
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
43 bed_entry.biotype = fields[16]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
44 bed_entry.gene_name = fields[17]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
45 bed_entry.second_gene_name = fields[18]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
46 bed_entry.gene_type = fields[19]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
47 return bed_entry
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
48
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
49
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
50 def as_int_list(obj):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
51 if obj is None:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
52 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
53 if isinstance(obj, list):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
54 return [int(x) for x in obj]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
55 elif isinstance(obj, str):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
56 return [int(x) for x in obj.split(',')]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
57 else: # python2 unicode?
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
58 return [int(x) for x in str(obj).split(',')]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
59
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
60
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
61 class BedEntry(object):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
62 def __init__(self, chrom=None, chromStart=None, chromEnd=None,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
63 name=None, score=None, strand=None,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
64 thickStart=None, thickEnd=None, itemRgb=None,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
65 blockCount=None, blockSizes=None, blockStarts=None):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
66 self.chrom = chrom
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
67 self.chromStart = int(chromStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
68 self.chromEnd = int(chromEnd)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
69 self.name = name
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
70 self.score = int(score) if score is not None else 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
71 self.strand = '-' if str(strand).startswith('-') else '+'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
72 self.thickStart = int(thickStart) if thickStart else self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
73 self.thickEnd = int(thickEnd) if thickEnd else self.chromEnd
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
74 self.itemRgb = str(itemRgb) if itemRgb is not None else r'100,100,100'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
75 self.blockCount = int(blockCount)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
76 self.blockSizes = as_int_list(blockSizes)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
77 self.blockStarts = as_int_list(blockStarts)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
78 self.second_name = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
79 self.cds_start_status = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
80 self.cds_end_status = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
81 self.exon_frames = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
82 self.biotype = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
83 self.gene_name = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
84 self.second_gene_name = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
85 self.gene_type = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
86 self.seq = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
87 self.cdna = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
88 self.pep = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
89 # T26C
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
90 self.aa_change = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
91 # p.Trp26Cys g.<pos><ref>><alt> # g.1304573A>G
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
92 self.variants = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
93
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
94 def __str__(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
95 return '%s\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%s\t%d\t%s\t%s' % (
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
96 self.chrom, self.chromStart, self.chromEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
97 self.name, self.score, self.strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
98 self.thickStart, self.thickEnd, str(self.itemRgb), self.blockCount,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
99 ','.join([str(x) for x in self.blockSizes]),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
100 ','.join([str(x) for x in self.blockStarts]))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
101
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
102 def get_splice_junctions(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
103 splice_juncs = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
104 for i in range(self.blockCount - 1):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
105 splice_junc = "%s:%d_%d"\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
106 % (self.chrom,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
107 self.chromStart + self.blockSizes[i],
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
108 self.chromStart + self.blockStarts[i+1])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
109 splice_juncs.append(splice_junc)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
110 return splice_juncs
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
111
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
112 def get_exon_seqs(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
113 if not self.seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
114 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
115 exons = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
116 for i in range(self.blockCount):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
117 exons.append(self.seq[self.blockStarts[i]:self.blockStarts[i]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
118 + self.blockSizes[i]])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
119 if self.strand == '-': # reverse complement
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
120 exons.reverse()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
121 for i, s in enumerate(exons):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
122 exons[i] = reverse_complement(s)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
123 return exons
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
124
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
125 def get_spliced_seq(self, strand=None):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
126 if not self.seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
127 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
128 seq = ''.join(self.get_exon_seqs())
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
129 if strand and self.strand != strand:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
130 seq = reverse_complement(seq)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
131 return seq
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
132
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
133 def get_cdna(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
134 if not self.cdna:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
135 self.cdna = self.get_spliced_seq()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
136 return self.cdna
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
137
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
138 def get_cds(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
139 cdna = self.get_cdna()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
140 if cdna:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
141 if self.chromStart == self.thickStart\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
142 and self.chromEnd == self.thickEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
143 return cdna
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
144 pos = [self.cdna_offset_of_pos(self.thickStart),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
145 self.cdna_offset_of_pos(self.thickEnd)]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
146 if 0 <= min(pos) <= max(pos) <= len(cdna):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
147 return cdna[min(pos):max(pos)]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
148 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
149
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
150 def set_cds(self, cdna_start, cdna_end):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
151 cdna_len = sum(self.blockSizes)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
152 if 0 <= cdna_start < cdna_end <= cdna_len:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
153 cds_pos = [self.pos_of_cdna_offet(cdna_start),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
154 self.pos_of_cdna_offet(cdna_end)]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
155 if all(cds_pos):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
156 self.thickStart = min(cds_pos)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
157 self.thickEnd = max(cds_pos)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
158 return self
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
159 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
160
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
161 def trim_cds(self, basepairs):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
162 if self.chromStart <= self.thickStart < self.thickEnd <= self.chromEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
163 cds_pos = [self.cdna_offset_of_pos(self.thickStart),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
164 self.cdna_offset_of_pos(self.thickEnd)]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
165 if basepairs > 0:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
166 return self.set_cds(min(cds_pos) + basepairs, max(cds_pos))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
167 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
168 return self.set_cds(min(cds_pos), max(cds_pos) + basepairs)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
169 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
170
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
171 def get_cds_bed(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
172 cds_pos = [self.cdna_offset_of_pos(self.thickStart),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
173 self.cdna_offset_of_pos(self.thickEnd)]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
174 return self.trim(min(cds_pos), max(cds_pos))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
175
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
176 def get_cigar(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
177 cigar = ''
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
178 r = range(self.blockCount)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
179 xl = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
180 for x in r:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
181 if xl is not None:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
182 intronSize = abs(self.blockStarts[x] - self.blockSizes[xl]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
183 - self.blockStarts[xl])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
184 cigar += '%dN' % intronSize
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
185 cigar += '%dM' % self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
186 xl = x
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
187 return cigar
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
188
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
189 def get_cigar_md(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
190 cigar = ''
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
191 md = ''
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
192 r = range(self.blockCount)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
193 xl = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
194 for x in r:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
195 if xl is not None:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
196 intronSize = abs(self.blockStarts[x] - self.blockSizes[xl]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
197 - self.blockStarts[xl])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
198 cigar += '%dN' % intronSize
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
199 cigar += '%dM' % self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
200 xl = x
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
201 md = '%d' % sum(self.blockSizes)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
202 return (cigar, md)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
203
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
204 def get_translation(self, sequence=None):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
205 translation = None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
206 seq = sequence if sequence else self.get_spliced_seq()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
207 if seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
208 seqlen = len(seq) / 3 * 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
209 if seqlen >= 3:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
210 translation = translate(seq[:seqlen])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
211 return translation
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
212
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
213 def get_translations(self):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
214 translations = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
215 seq = self.get_spliced_seq()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
216 if seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
217 for i in range(3):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
218 translation = self.get_translation(sequence=seq[i:])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
219 if translation:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
220 translations.append(translation)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
221 return translations
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
222
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
223 def pos_of_cdna_offet(self, offset):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
224 if offset is not None and 0 <= offset < sum(self.blockSizes):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
225 r = list(range(self.blockCount))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
226 rev = self.strand == '-'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
227 if rev:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
228 r.reverse()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
229 nlen = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
230 for x in r:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
231 if offset < nlen + self.blockSizes[x]:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
232 if rev:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
233 return self.chromStart + self.blockStarts[x]\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
234 + self.blockSizes[x] - (offset - nlen)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
235 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
236 return self.chromStart + self.blockStarts[x]\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
237 + (offset - nlen)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
238 nlen += self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
239 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
240
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
241 def cdna_offset_of_pos(self, pos):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
242 if not self.chromStart <= pos < self.chromEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
243 return -1
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
244 r = list(range(self.blockCount))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
245 rev = self.strand == '-'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
246 if rev:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
247 r.reverse()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
248 nlen = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
249 for x in r:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
250 bStart = self.chromStart + self.blockStarts[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
251 bEnd = bStart + self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
252 if bStart <= pos < bEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
253 return nlen + (bEnd - pos if rev else pos - bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
254 nlen += self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
255
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
256 def apply_variant(self, pos, ref, alt):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
257 pos = int(pos)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
258 if not ref or not alt:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
259 print("variant requires ref and alt sequences", file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
260 return
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
261 if not self.chromStart <= pos <= self.chromEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
262 print("variant not in entry %s: %s %d < %d < %d" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
263 (self.name, self.strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
264 self.chromStart, pos, self.chromEnd),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
265 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
266 print("%s" % str(self), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
267 return
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
268 if len(ref) != len(alt):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
269 print("variant only works for snp: %s %s" % (ref, alt),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
270 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
271 return
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
272 if not self.seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
273 print("variant entry %s has no seq" % self.name, file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
274 return
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
275 """
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
276 if self.strand == '-':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
277 ref = reverse_complement(ref)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
278 alt = reverse_complement(alt)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
279 """
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
280 bases = list(self.seq)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
281 offset = pos - self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
282 for i in range(len(ref)):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
283 # offset = self.cdna_offset_of_pos(pos+i)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
284 if offset is not None:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
285 bases[offset+i] = alt[i]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
286 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
287 print("variant offset %s: %s %d < %d < %d" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
288 (self.name, self.strand, self.chromStart,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
289 pos+1, self.chromEnd), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
290 print("%s" % str(self), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
291 self.seq = ''.join(bases)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
292 self.variants.append("g.%d%s>%s" % (pos+1, ref, alt))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
293
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
294 def get_variant_bed(self, pos, ref, alt):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
295 pos = int(pos)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
296 if not ref or not alt:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
297 print("variant requires ref and alt sequences", file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
298 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
299 if not self.chromStart <= pos <= self.chromEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
300 print("variant not in entry %s: %s %d < %d < %d" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
301 (self.name, self.strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
302 self.chromStart, pos, self.chromEnd),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
303 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
304 print("%s" % str(self), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
305 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
306 if not self.seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
307 print("variant entry %s has no seq" % self.name, file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
308 return None
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
309 tbed = BedEntry(chrom=self.chrom,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
310 chromStart=self.chromStart, chromEnd=self.chromEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
311 name=self.name, score=self.score, strand=self.strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
312 thickStart=self.chromStart, thickEnd=self.chromEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
313 itemRgb=self.itemRgb,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
314 blockCount=self.blockCount,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
315 blockSizes=self.blockSizes,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
316 blockStarts=self.blockStarts)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
317 bases = list(self.seq)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
318 offset = pos - self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
319 tbed.seq = ''.join(bases[:offset] + list(alt)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
320 + bases[offset+len(ref):])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
321 if len(ref) != len(alt):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
322 diff = len(alt) - len(ref)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
323 rEnd = pos + len(ref)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
324 # need to adjust blocks
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
325 # change spans blocks,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
326 for x in range(tbed.blockCount):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
327 bStart = tbed.chromStart + tbed.blockStarts[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
328 bEnd = bStart + tbed.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
329 # change within a block or extends (last block)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
330 # adjust blocksize
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
331 # seq: GGGcatGGG
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
332 # ref c alt tag: GGGtagatGGG
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
333 # ref cat alt a: GGGaGGG
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
334 if bStart <= pos < rEnd < bEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
335 tbed.blockSizes[x] += diff
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
336 return tbed
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
337
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
338 # (start, end)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
339 def get_subrange(self, tstart, tstop, debug=False):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
340 chromStart = self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
341 chromEnd = self.chromEnd
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
342 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
343 print("%s" % (str(self)), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
344 r = list(range(self.blockCount))
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
345 if self.strand == '-':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
346 r.reverse()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
347 bStart = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
348 bEnd = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
349 for x in r:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
350 bEnd = bStart + self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
351 if bStart <= tstart < bEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
352 if self.strand == '+':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
353 chromStart = self.chromStart + self.blockStarts[x] +\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
354 (tstart - bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
355 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
356 chromEnd = self.chromStart + self.blockStarts[x] +\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
357 self.blockSizes[x] - (tstart - bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
358 if bStart <= tstop < bEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
359 if self.strand == '+':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
360 chromEnd = self.chromStart + self.blockStarts[x] +\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
361 (tstop - bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
362 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
363 chromStart = self.chromStart + self.blockStarts[x] +\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
364 self.blockSizes[x] - (tstop - bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
365 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
366 print("%3d %s\t%d\t%d\t%d\t%d\t%d\t%d" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
367 (x, self.strand, bStart, bEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
368 tstart, tstop, chromStart, chromEnd), file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
369 bStart += self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
370 return(chromStart, chromEnd)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
371
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
372 # get the blocks for sub range
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
373 def get_blocks(self, chromStart, chromEnd):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
374 tblockCount = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
375 tblockSizes = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
376 tblockStarts = []
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
377 for x in range(self.blockCount):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
378 bStart = self.chromStart + self.blockStarts[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
379 bEnd = bStart + self.blockSizes[x]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
380 if bStart > chromEnd:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
381 break
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
382 if bEnd < chromStart:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
383 continue
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
384 cStart = max(chromStart, bStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
385 tblockStarts.append(cStart - chromStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
386 tblockSizes.append(min(chromEnd, bEnd) - cStart)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
387 tblockCount += 1
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
388 return (tblockCount, tblockSizes, tblockStarts)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
389
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
390 def trim(self, tstart, tstop, debug=False):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
391 (tchromStart, tchromEnd) =\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
392 self.get_subrange(tstart, tstop, debug=debug)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
393 (tblockCount, tblockSizes, tblockStarts) =\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
394 self.get_blocks(tchromStart, tchromEnd)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
395 tbed = BedEntry(
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
396 chrom=self.chrom, chromStart=tchromStart, chromEnd=tchromEnd,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
397 name=self.name, score=self.score, strand=self.strand,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
398 thickStart=tchromStart, thickEnd=tchromEnd, itemRgb=self.itemRgb,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
399 blockCount=tblockCount,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
400 blockSizes=tblockSizes, blockStarts=tblockStarts)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
401 if self.seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
402 ts = tchromStart-self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
403 te = tchromEnd - tchromStart + ts
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
404 tbed.seq = self.seq[ts:te]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
405 return tbed
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
406
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
407 def get_filtered_translations(self, untrimmed=False, filtering=True,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
408 ignore_left_bp=0, ignore_right_bp=0,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
409 debug=False):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
410 translations = [None, None, None]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
411 seq = self.get_spliced_seq()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
412 ignore = (ignore_left_bp if self.strand == '+'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
413 else ignore_right_bp) / 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
414 block_sum = sum(self.blockSizes)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
415 exon_sizes = [x for x in self.blockSizes]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
416 if self.strand == '-':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
417 exon_sizes.reverse()
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
418 splice_sites = [sum(exon_sizes[:x]) / 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
419 for x in range(1, len(exon_sizes))]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
420 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
421 print("splice_sites: %s" % splice_sites, file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
422 junc = splice_sites[0] if len(splice_sites) > 0 else exon_sizes[0]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
423 if seq:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
424 for i in range(3):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
425 translation = self.get_translation(sequence=seq[i:])
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
426 if translation:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
427 tstart = 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
428 tstop = len(translation)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
429 offset = (block_sum - i) % 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
430 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
431 print("frame: %d\ttstart: %d tstop: %d " +
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
432 "offset: %d\t%s" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
433 (i, tstart, tstop, offset, translation),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
434 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
435 if not untrimmed:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
436 tstart = translation.rfind('*', 0, junc) + 1
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
437 stop = translation.find('*', junc)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
438 tstop = stop if stop >= 0 else len(translation)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
439 offset = (block_sum - i) % 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
440 trimmed = translation[tstart:tstop]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
441 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
442 print("frame: %d\ttstart: %d tstop: %d " +
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
443 "offset: %d\t%s" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
444 (i, tstart, tstop, offset, trimmed),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
445 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
446 if filtering and tstart > ignore:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
447 continue
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
448 # get genomic locations for start and end
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
449 if self.strand == '+':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
450 chromStart = self.chromStart + i + (tstart * 3)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
451 chromEnd = self.chromEnd - offset\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
452 - (len(translation) - tstop) * 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
453 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
454 chromStart = self.chromStart + offset\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
455 + (len(translation) - tstop) * 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
456 chromEnd = self.chromEnd - i - (tstart * 3)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
457 # get the blocks for this translation
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
458 (tblockCount, tblockSizes, tblockStarts) =\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
459 self.get_blocks(chromStart, chromEnd)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
460 translations[i] = (chromStart, chromEnd, trimmed,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
461 tblockCount, tblockSizes, tblockStarts)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
462 if debug:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
463 print("tblockCount: %d tblockStarts: %s " +
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
464 "tblockSizes: %s" %
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
465 (tblockCount, tblockStarts, tblockSizes),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
466 file=sys.stderr)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
467 return translations
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
468
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
469 def get_seq_id(self, seqtype='unk:unk', reference='', frame=None):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
470 # Ensembl fasta ID format
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
471 # >ID SEQTYPE:STATUS LOCATION GENE TRANSCRIPT
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
472 # >ENSP00000328693 pep:splice chromosome:NCBI35:1:904515:910768:1\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
473 # gene:ENSG00000158815:transcript:ENST00000328693\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
474 # gene_biotype:protein_coding transcript_biotype:protein_coding
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
475 frame_name = ''
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
476 chromStart = self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
477 chromEnd = self.chromEnd
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
478 strand = 1 if self.strand == '+' else -1
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
479 if frame is not None:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
480 block_sum = sum(self.blockSizes)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
481 offset = (block_sum - frame) % 3
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
482 frame_name = '_' + str(frame + 1)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
483 if self.strand == '+':
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
484 chromStart += frame
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
485 chromEnd -= offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
486 else:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
487 chromStart += offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
488 chromEnd -= frame
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
489 location = "chromosome:%s:%s:%s:%s:%s"\
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
490 % (reference, self.chrom, chromStart, chromEnd, strand)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
491 seq_id = "%s%s %s %s" % (self.name, frame_name, seqtype, location)
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
492 return seq_id
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
493
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
494 def get_line(self, start_offset=0, end_offset=0):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
495 if start_offset or end_offset:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
496 s_offset = start_offset if start_offset else 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
497 e_offset = end_offset if end_offset else 0
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
498 if s_offset > self.chromStart:
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
499 s_offset = self.chromStart
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
500 chrStart = self.chromStart - s_offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
501 chrEnd = self.chromEnd + e_offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
502 blkSizes = self.blockSizes
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
503 blkSizes[0] += s_offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
504 blkSizes[-1] += e_offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
505 blkStarts = self.blockStarts
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
506 for i in range(1, self.blockCount):
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
507 blkStarts[i] += s_offset
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
508 items = [str(x) for x in [self.chrom, chrStart, chrEnd, self.name,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
509 self.score, self.strand, self.thickStart,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
510 self.thickEnd, self.itemRgb,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
511 self.blockCount,
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
512 ','.join([str(x) for x in blkSizes]),
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
513 ','.join([str(x) for x in blkStarts])]]
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
514 return '\t'.join(items) + '\n'
da1b538b87e5 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 88cf1e923a8c9e5bc6953ad412d15a7c70f054d1
galaxyp
parents:
diff changeset
515 return self.line