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