Mercurial > repos > yating-l > hubarchivecreator
annotate util/index/ExternIndex.py @ 82:62600ac1d0f7 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
author | yating-l |
---|---|
date | Wed, 27 Sep 2017 17:31:19 -0400 |
parents | 4ca7cbf2d9b8 |
children | 0bc486356e2a |
rev | line source |
---|---|
66
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/python |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
2 import collections |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
3 import abc |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
4 from abc import ABCMeta |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
5 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
6 class ExternIndex(object): |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
7 __metaclass__ = ABCMeta |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
8 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
9 @abc.abstractmethod |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
10 def __init__(self): |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
11 """init""" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
12 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
13 @abc.abstractmethod |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
14 def setExtLink(self): |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
15 """set external link""" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
16 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
17 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
18 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
19 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
20 ''' |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
21 @staticmethod |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
22 def setExtLink(database, inputFile, extra_settings, seqType=None, useIframe=True, iframeHeight=None, iframeWidth=None): |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
23 if "NCBI" in database: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
24 if not seqType: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
25 seqType = int(ExternIndex.getSeqType(inputFile)) |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
26 else: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
27 seqType = seqType |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
28 if seqType < 0: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
29 print seqType |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
30 raise Exception("Sequence Type is not set for bigPsl. Stopping the application") |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
31 if seqType == 2: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
32 extra_settings["url"] = "https://www.ncbi.nlm.nih.gov/protein/$$" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
33 elif seqType == 1: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
34 extra_settings["url"] = "https://www.ncbi.nlm.nih.gov/nuccore/$$" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
35 else: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
36 raise Exception("Sequence Type {0} is not valid for bigPsl. Stopping the application".format(seqType)) |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
37 elif "UniProt" in database: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
38 extra_settings["url"] = "http://www.uniprot.org/uniprot/$$" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
39 elif "FlyBase" in database: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
40 extra_settings["url"] = "http://flybase.org/reports/$$" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
41 else: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
42 extra_settings["url"] = "https://www.ncbi.nlm.nih.gov/gquery/?term=$$" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
43 extra_settings["urlLabel"] = database + " Details:" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
44 if useIframe: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
45 extra_settings["iframeUrl"] = extra_settings["url"] |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
46 if not iframeHeight: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
47 iframeHeight = "600" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
48 if not iframeWidth: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
49 iframeWidth = "800" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
50 extra_settings["iframeOptions"] = "height= %s width= %s" % (iframeHeight, iframeWidth) |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
51 |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
52 @staticmethod |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
53 def getSeqType(inputFile): |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
54 with open(inputFile, "r") as bigpsl: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
55 sampleSeq = bigpsl.readline().split() |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
56 if len(sampleSeq) == 25: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
57 return sampleSeq[-1] |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
58 else: |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
59 return "-1" |
4ca7cbf2d9b8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
yating-l
parents:
diff
changeset
|
60 ''' |