Mercurial > repos > tomnl > metfrag
annotate metfrag.py @ 0:75c805123b45 draft
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
| author | tomnl |
|---|---|
| date | Tue, 24 Jul 2018 07:59:44 -0400 |
| parents | |
| children | c1b168770b68 |
| rev | line source |
|---|---|
|
0
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
1 import argparse |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
2 import csv |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
3 import os |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
4 import sys |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
5 print(sys.version) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
6 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
7 parser = argparse.ArgumentParser() |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
8 parser.add_argument('--input') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
9 parser.add_argument('--db_local') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
10 parser.add_argument('--db_online') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
11 parser.add_argument('--ppm') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
12 parser.add_argument('--ppm_frag') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
13 parser.add_argument('--fragmasstol') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
14 parser.add_argument('--polarity') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
15 parser.add_argument('--results') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
16 parser.add_argument('--threads') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
17 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
18 args = parser.parse_args() |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
19 print args |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
20 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
21 os.makedirs("tmet") |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
22 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
23 with open(args.input,"r") as infile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
24 numlines = 0 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
25 for line in infile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
26 line = line.strip() |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
27 if numlines == 0: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
28 if "NAME" in line: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
29 featid = line.split("NAME: ")[1] |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
30 if "PRECURSORMZ" in line: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
31 mz = float(line.split("PRECURSORMZ: ")[1]) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
32 if args.polarity=="pos": |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
33 mz2 = mz-1.007276 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
34 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
35 mz2 = mz+1.007276 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
36 if "Num Peaks" in line: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
37 numlines = int(line.split("Num Peaks: ")[1]) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
38 linesread = 0 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
39 peaklist = [] |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
40 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
41 if linesread == numlines: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
42 numlines = 0 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
43 #write spec file |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
44 with open('./tmpspec.txt', 'w') as outfile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
45 for p in peaklist: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
46 outfile.write(p[0]+"\t"+p[1]+"\n") |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
47 #create commandline input |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
48 cmd_command = "PeakListPath=tmpspec.txt " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
49 if args.db_local != "None": |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
50 cmd_command += "MetFragDatabaseType=LocalCSV " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
51 cmd_command += "LocalDatabasePath={0} ".format(args.db_local) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
52 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
53 cmd_command += "MetFragDatabaseType={0} ".format(args.db_online) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
54 cmd_command += "FragmentPeakMatchAbsoluteMassDeviation={0} ".format(args.fragmasstol) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
55 cmd_command += "FragmentPeakMatchRelativeMassDeviation={0} ".format(args.ppm_frag) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
56 cmd_command += "DatabaseSearchRelativeMassDeviation={0} ".format(args.ppm) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
57 cmd_command += "NeutralPrecursorMass={0} ".format(mz2) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
58 cmd_command += "SampleName={0}_metfrag ".format(featid) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
59 cmd_command += "ResultsPath=./tmet/ " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
60 if args.polarity == "pos": |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
61 cmd_command += "IsPositiveIonMode=True " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
62 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
63 cmd_command += "IsPositiveIonMode=False " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
64 if args.polarity == "pos": ### Annotation information. Create a dict for the PrecurorIonModes?? |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
65 cmd_command += "PrecursorIonMode=1 " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
66 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
67 cmd_command += "PrecursorIonMode=-1 " |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
68 cmd_command += "MetFragCandidateWriter=CSV " ## TSV not available |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
69 cmd_command += "NumberThreads={} ".format(args.threads) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
70 # run Metfrag |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
71 print "metfrag {0}".format(cmd_command) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
72 os.system("metfrag {0}".format(cmd_command)) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
73 else: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
74 line = tuple(line.split("\t")) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
75 linesread += 1 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
76 peaklist.append(line) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
77 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
78 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
79 #outputs might have different headers. Need to get a list of all the headers before we start merging the files |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
80 outfiles = sorted(os.listdir("./tmet")) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
81 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
82 headers = [] |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
83 c = 0 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
84 for fname in outfiles: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
85 with open("./tmet/"+fname) as infile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
86 reader = csv.reader(infile) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
87 headers.extend(reader.next()) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
88 # check if file has any data rows |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
89 for i, row in enumerate(reader): |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
90 c+=1 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
91 if i==1: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
92 break |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
93 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
94 # if no data rows (e.g. matches) then do not save an output and leave the program |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
95 if c==0: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
96 sys.exit() |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
97 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
98 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
99 print headers |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
100 headers = ['UID'] + sorted(list(set(headers))) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
101 print headers |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
102 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
103 #merge outputs |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
104 with open(args.results, 'a') as merged_outfile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
105 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
106 dwriter = csv.DictWriter(merged_outfile, fieldnames=headers, delimiter='\t') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
107 dwriter.writeheader() |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
108 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
109 for fname in outfiles: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
110 fileid = os.path.basename(fname).split("_")[0] |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
111 with open("./tmet/"+fname) as infile: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
112 reader = csv.DictReader(infile, delimiter=',', quotechar='"') |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
113 for line in reader: |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
114 line['UID'] = fileid |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
115 dwriter.writerow(line) |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
116 |
|
75c805123b45
planemo upload for repository https://github.com/computational-metabolomics/metfrag-galaxy commit b5f4005c77b275b9b1b4349b08476afc783a8e14
tomnl
parents:
diff
changeset
|
117 |
