diff list-chrom-cols.py @ 5:fb9c0409d85c draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 608d9e59a0d2dcf85a037968ddb2c61137fb9bce
author prog
date Wed, 19 Apr 2017 10:00:05 -0400
parents 20d69a062da3
children
line wrap: on
line diff
--- a/list-chrom-cols.py	Tue Mar 14 12:40:22 2017 -0400
+++ b/list-chrom-cols.py	Wed Apr 19 10:00:05 2017 -0400
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# vi: fdm=marker
 
 import argparse
 import subprocess
@@ -7,7 +8,10 @@
 import json
 import csv
 
-def get_chrom_cols(dbtype, dburl, dbtoken = None, dbfields = None):
+# Get chrom cols {{{1
+################################################################
+
+def get_chrom_cols(dbtype, dburl, dbtoken = None, col_field = 'chromcol'):
     
     cols = []
     
@@ -19,19 +23,14 @@
         v = json.JSONDecoder().decode(result)
         i = 0
         for colid, coldesc in v.iteritems():
-            cols.append( (coldesc['name'], colid, i == 0) )
+            s = coldesc['name'] + ' - ' + coldesc['constructor'] + ' - L' + str(coldesc['length']) + ' - diam. ' + str(coldesc['diameter']) + ' - part. ' + str(coldesc['particule_size']) + ' - flow ' + str(coldesc['flow_rate'])
+            cols.append( (s , colid, i == 0) )
             ++i
         
     elif dbtype == 'inhouse':
-        # Get field for chromatographic column name
-        col_field = 'chromcol'
-        if dbfields is not None:
-            fields = dict(u.split("=") for u in dbfields.split(","))
-            if 'chromcol' in fields:
-                col_field = fields['chromcol']
                 
         # Get all column names from file
-        with open(dburl if isinstance(dburl, str) else dburl.get_file_name(), 'rb') as dbfile:
+        with open(dburl if isinstance(dburl, str) else dburl.get_file_name(), 'r') as dbfile:
             reader = csv.reader(dbfile, delimiter = "\t", quotechar='"')
             header = reader.next()
             if col_field in header:
@@ -46,9 +45,8 @@
     
     return cols
 
-########
-# MAIN #
-########
+# Main {{{1
+################################################################
 
 if __name__ == '__main__':
     
@@ -57,7 +55,7 @@
     parser.add_argument('-d', help = 'Database type',       dest = 'dbtype',    required = True)
     parser.add_argument('-u', help = 'Database URL',        dest = 'dburl',     required = True)
     parser.add_argument('-t', help = 'Database token',      dest = 'dbtoken',   required = False)
-    parser.add_argument('-f', help = 'Database fields',     dest = 'dbfields',  required = False)
+    parser.add_argument('-f', help = 'Chromatogrphic column field name',     dest = 'col_field',  required = False)
     args = parser.parse_args()
     args_dict = vars(args)