annotate dma-filelist-generation.py @ 19:d4081e4160af draft

planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 14435cfc042911bf1ee409f5a0d5ef908f5feec0-dirty
author tomnl
date Thu, 21 Jun 2018 08:47:44 -0400
parents 55aa2dd24828
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
1 import argparse
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
2 import textwrap
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
3 import os
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
4 import re
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
5 import collections
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
6 import csv
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
7 from operator import itemgetter
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
8
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
9 def check_folder(in_dir, reg_string):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
10 filelist = []
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
11 for f in os.listdir(in_dir):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
12
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
13 if re.match(reg_string, f, re.IGNORECASE):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
14
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
15 fn, fe = os.path.splitext(f)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
16 fnl = fn.split("_")
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
17 filename = fn
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
18 fullpth = os.path.join(in_dir, f)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
19 wells = fnl[0]
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
20
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
21
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
22
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
23 if re.match("^.*pos.*", f, re.IGNORECASE):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
24 polarity = "pos"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
25 elif re.match("^.*neg.*", f, re.IGNORECASE):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
26 polarity = "neg"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
27 else:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
28 error_message = "Files need to have either 'pos' or 'neg' in the file name"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
29 print error_message
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
30 return 1, error_message, "", ""
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
31 if re.match("^.*blank.*", f, re.IGNORECASE):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
32 sample_type = "blank"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
33 else:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
34 sample_type = "sample"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
35
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
36
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
37 filelist.append([wells, sample_type, polarity, filename, fullpth])
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
38
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
39 return filelist
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
40
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
41 def get_filelist(filesin, o, file_type='mzML', create_filelist=True):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
42
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
43 filedict = collections.OrderedDict()
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
44
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
45
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
46 if file_type=="mzML":
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
47 reg_string = "^.*mzML$"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
48 else:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
49 reg_string = "^.*raw$"
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
50
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
51 if isinstance(filesin, list):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
52 filelist = []
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
53 for f in filesin:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
54 filelist.extend(check_folder(f, reg_string))
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
55 else:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
56 filelist = check_folder(filesin, reg_string)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
57
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
58 # Turn filelist into a dictionary
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
59 for f1 in filelist:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
60 well = f1[0]
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
61 filedict[well] = []
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
62 for f2 in filelist:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
63 if well == f2[0]:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
64 filedict[well].append(f2[1:len(f2)+1])
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
65
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
66
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
67
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
68 filelist = sorted(filelist, key=itemgetter(0, 1))
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
69
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
70 for k, v in filedict.iteritems():
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
71 classes = [i[0] for i in v]
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
72 classes.sort()
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
73 if not classes == ['blank', 'sample']:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
74 error_message = "!!!!ERROR!!!! Blank and sample required for each well, file type {}".format(file_type)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
75 print error_message
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
76 return 1, error_message, "", ""
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
77
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
78 print 'files of type {} checked, files OK'.format(file_type)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
79
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
80 if create_filelist:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
81
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
82 outname = write_filedict(filedict, o, file_type)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
83 print 'filelist created in folder {}, using file type {}, full path {}'.format(o, file_type, outname)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
84
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
85 return 0, "files OK", filedict, filelist
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
86
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
87 def write_filedict(filedict, out_dir, file_type, file_spacing='tsv'):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
88
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
89 outname = os.path.join(out_dir,'filelist_{}.{}'.format(file_type, file_spacing))
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
90
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
91 if file_spacing=='tsv':
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
92 delim = '\t'
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
93 elif file_spacing=='csv':
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
94 delim = ','
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
95 else:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
96 delim = ','
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
97
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
98
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
99 with open(outname, 'wb') as csvfile:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
100 w = csv.writer(csvfile, delimiter=delim)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
101
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
102 w.writerow(['filename','classLabel', 'multilist', 'multilistLabel'])
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
103 c = 1
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
104 for k, v in filedict.iteritems():
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
105 for i in v:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
106 w.writerow([os.path.basename(i[3]), i[0], c, k])
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
107 c +=1
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
108
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
109 return outname
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
110
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
111
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
112 def main():
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
113
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
114 p = argparse.ArgumentParser(prog='PROG',
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
115 formatter_class=argparse.RawDescriptionHelpFormatter,
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
116 description='''Create filelist for DMA DIMS nearline workflow''',
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
117 epilog=textwrap.dedent('''
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
118 -------------------------------------------------------------------------
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
119
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
120 Example Usage
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
121
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
122 python dma-filelist-generation.py -i [dir with sample files], [dir with blank files] -o .
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
123
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
124 '''))
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
125
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
126 p.add_argument('-i', dest='i', help='dir with sample files', nargs = '*', required=True)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
127 p.add_argument('-o', dest='o', help='out dir', required=True)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
128 p.add_argument('--check_mzml', dest='check_mzml', action='store_true')
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
129 p.add_argument('--check_raw', dest='check_raw', action='store_true')
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
130 p.add_argument('--create_filelist_mzml', dest='create_filelist_mzml', action='store_true')
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
131 p.add_argument('--create_filelist_raw', dest='create_filelist_raw', action='store_true')
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
132
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
133 args = p.parse_args()
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
134
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
135 if not os.path.exists(args.o):
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
136 os.makedirs(args.o)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
137 print args.o
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
138
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
139 if not args.check_mzml and not args.check_raw:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
140 print '--check_mzml or --check_raw (or both) are required as inputs'
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
141 exit()
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
142
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
143 if args.check_mzml:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
144 get_filelist(args.i, args.o, file_type='mzML', create_filelist=args.create_filelist_mzml)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
145
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
146 if args.check_raw:
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
147
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
148 get_filelist(args.i, args.o, file_type='raw', create_filelist=args.create_filelist_raw)
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
149
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
150
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
151
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
152 if __name__ == '__main__':
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
153 main()
55aa2dd24828 planemo upload for repository https://github.com/computational-metabolomics/dma-tools-galaxy commit 6c48bd51987a28401de6cf5e49b1b30e5e73fe16-dirty
tomnl
parents:
diff changeset
154