Mercurial > repos > chrisb > gap_all_glycan_tools
comparison convert_detect_formats/rings_detect_format/glycan_sniff.py @ 0:89592faa2875 draft
Uploaded
author | chrisb |
---|---|
date | Wed, 23 Mar 2016 14:35:56 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:89592faa2875 |
---|---|
1 __author__ = "Chris Barnett" | |
2 __version__ = "0.3" | |
3 __license__ = "MIT" | |
4 | |
5 | |
6 def sniff_glycan(inputstream, is_a=None): | |
7 """ | |
8 Passes input glycan format to RINGS and returns format. | |
9 If is_a is specified then return boolean | |
10 :rtype : text, or Boolean if is_a is specified or None if broken (maybe should be False) | |
11 :param inputstream: inputstream with glycan struct. (not sure for multiple... in any of LinearCode, KCF etc. (can be mixed)) | |
12 :param is_a: If not None then test for the file type specified. | |
13 """ | |
14 if inputstream is None or inputstream == [] or inputstream == "": | |
15 return "" | |
16 try: | |
17 from suds.client import Client | |
18 | |
19 url = 'http://rings.t.soka.ac.jp/axis2/services/Utilities?wsdl' | |
20 client = Client(url) | |
21 response = client.service.DeterminingForm(inputstream.read()) | |
22 if response is None: | |
23 return "" | |
24 fmt = response.array[0] # response is an object,just access the attributes | |
25 if is_a is not None and "" != is_a: | |
26 if is_a.upper() == fmt.upper(): # compare fmt names and avoid case issues | |
27 return True | |
28 else: | |
29 return False | |
30 else: | |
31 return fmt | |
32 except Exception as e: | |
33 raise IOError(e) | |
34 | |
35 | |
36 if __name__ == "__main__": | |
37 from optparse import OptionParser | |
38 | |
39 usage = "usage: python %prog [options]\n" | |
40 parser = OptionParser(usage=usage) | |
41 parser.add_option("-i", action="store", type="string", dest="i", default="input", | |
42 help="input any glycan file (input)") | |
43 parser.add_option("-f", action="store", type="string", dest="f", default=None, | |
44 help="return true if is the specified format KCF)") | |
45 (options, args) = parser.parse_args() | |
46 instream = file(options.i, 'r') | |
47 print sniff_glycan(instream, options.f) |