annotate bin/design_matrix_creator @ 3:12fb0d4b1e93 draft

planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit c7e4f2dfb8c35144b787850b60e116edfbaaa20f
author yhoogstrate
date Thu, 03 Sep 2015 09:42:12 -0400
parents a4a4c88783ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
1 #!/usr/bin/env python
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
2
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
3 import argparse, os, shutil, sys, tempfile, subprocess
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
4
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
5 __version_info__ = ('1', '0', '0')#, 'beta')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
6 __version__ = '.'.join(__version_info__) if (len(__version_info__) == 3) else '.'.join(__version_info__[0:3])+"-"+__version_info__[3]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
7 __author__ = 'Youri Hoogstrate'
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
8 __homepage__ = 'https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools'
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
9 __license__ = 'GNU General Public License v3 (GPLv3)'
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
10
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
11
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
12 class sampleContainer:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
13 def __init__(self):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
14 self.samples = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
15 self.treatments = {}
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
16 self.treatment_index = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
17 self.treatment_types = {}
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
18
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
19 def do_decode(self,encoded_str):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
20 return encoded_str.decode("base64").strip().replace("\t",'')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
21
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
22 def add_samples(self,argument):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
23 print " - Adding samples"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
24 for sample in argument:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
25 self.add_sample(self.do_decode(sample))
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
26
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
27 def add_sample(self,sample):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
28 if(sample in self.samples):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
29 sys.stderr.write("Error:\n* Non-unique sample: "+sample+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
30 sys.exit(1)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
31 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
32 self.samples.append(sample)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
33 print " - Added: "+sample
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
34
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
35 def add_blocking(self,argument):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
36 print " - Adding paired samples"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
37 pair = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
38 for block in argument:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
39 self.add_block(block)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
40
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
41 def add_block(self,blocks):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
42 blocks = blocks.split(":")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
43 as_treatment = blocks[0]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
44 blocks = blocks[1:]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
45
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
46 used_samples = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
47 indexed_samples = {}
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
48
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
49 for i in range(len(blocks)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
50 block = blocks[i]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
51 samples = self.get_samples_from_block(block)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
52 indexed_samples[i+1] = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
53 for sample in samples:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
54 if(sample in used_samples):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
55 sys.stderr.write("Error:\n* Blocking contains multiple times the same sample: "+sample+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
56 sys.exit(0)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
57 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
58 indexed_samples[i+1] = block
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
59 used_samples.append(sample)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
60
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
61 for sample in self.samples:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
62 if(sample not in used_samples):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
63 i = i + 1
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
64 indexed_samples[i+1] = str(sample).encode('base64').strip()
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
65
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
66 for index in indexed_samples.keys():
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
67 key = str(index).encode('base64').strip()
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
68 as_treatment += ":"+key+":"+indexed_samples[index]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
69
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
70 self.add_treatment(as_treatment)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
71
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
72 def get_samples_from_block(self,decoded_block):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
73 return [ self.do_decode(x) for x in decoded_block.split(",")]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
74
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
75 def add_treatments(self,argument):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
76 print " - Adding treatments"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
77 for treatment in argument:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
78 self.add_treatment(treatment)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
79
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
80 def add_treatment(self,treatment_argument):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
81 print " - Parsing treatment"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
82
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
83
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
84 treatment_argument = treatment_argument.split(":")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
85 name = self.do_decode(treatment_argument[0])
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
86 treatment_argument = treatment_argument[1:]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
87
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
88
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
89 treatment = {"factor_index":{},"sample_index":{}}
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
90 only_integers = True
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
91
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
92 i = 1
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
93 for item in treatment_argument:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
94 if(i % 2):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
95 factor = self.do_decode(item)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
96
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
97 if(treatment['factor_index'].has_key(factor)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
98 sys.stderr.write("Error:\n* Factor has been added multiple times to treatment: "+factor+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
99 sys.exit(0)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
100 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
101 print " - Adding factor: "+factor
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
102 treatment["factor_index"][factor] = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
103 if(not factor.isdigit()):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
104 only_integers = False
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
105 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
106 for sample in item.split(","):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
107 sample = self.do_decode(sample)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
108
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
109 if(not sample in self.samples):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
110 sys.stderr.write("Error:\n* Unknown sample: "+sample+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
111 sys.exit(0)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
112
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
113 treatment["factor_index"][factor].append(sample)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
114 if(treatment["sample_index"].has_key(sample)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
115 sys.stderr.write("Error:\n* Factor has been added to treatment before: "+sample+"/"+factor+", factors must be mutually exclusive!\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
116 sys.exit(0)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
117 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
118 treatment["sample_index"][sample] = factor
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
119 i += 1
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
120
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
121 treatment_factors = sorted(treatment["factor_index"].keys())
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
122
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
123 if(name == None):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
124 treatment["name"] = "_vs_".join(treatment_factors)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
125 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
126 treatment["name"] = str(name)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
127
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
128 if(len(treatment["sample_index"]) != len(self.samples)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
129 sys.stderr.write("Error:\n* The number of samples for treatment '"+treatment["name"]+"' ("+str(len(treatment["sample_index"]))+") is different from the total number of samples ("+str(len(self.samples))+").\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
130
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
131 if(only_integers):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
132 treatment_type = "integer"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
133 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
134 treatment_type = "string"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
135
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
136 if(self.treatments.has_key(treatment["name"])):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
137 sys.stderr.write("Error:\n* Treatment was already added: '"+treatment["name"]+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
138 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
139 self.treatments[treatment["name"]] = treatment
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
140 self.treatment_index.append(treatment["name"])
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
141 self.treatment_types[treatment["name"]] = treatment_type
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
142 print " - Treatment \""+treatment["name"]+"\" of type \""+treatment_type+"\" is valid"
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
143
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
144 def export(self,output):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
145 # Open file stream
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
146 if(args.output == "-"):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
147 fh = sys.stdout
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
148 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
149 fh = open(args.output,"w")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
150
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
151 # Write header:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
152 fh.write("sample-name\t"+"\t".join(self.treatment_index)+"\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
153
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
154 # Write body:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
155 for sample in self.samples:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
156 fh.write(sample)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
157 for treatment_id in self.treatment_index:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
158 treatment = self.treatments[treatment_id]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
159 fh.write("\t"+treatment["sample_index"][sample])
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
160 fh.write("\n")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
161
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
162 fh.close()
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
163
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
164 if __name__=="__main__":
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
165 parser = argparse.ArgumentParser(description="Create an edgeR design matrix with read-count datasets.")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
166 parser.add_argument("-o","--output", help="Output file, '-' for stdout.",required=True)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
167 parser.add_argument("-c","--columns-file", nargs="?", help='Use columns of [this] file as UIDs (counting from 1)')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
168 parser.add_argument("-s","--sample-names", nargs="*", help='Sample names (UIDs that correspond to the columns in the expression matrix)')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
169 parser.add_argument("-t","--treatments", nargs="+", help='Treatment or conditions: "name::sample:condition& (sample-names and conditions have to be provided using Base64 encoding to avoid weird characters)',required=True)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
170 parser.add_argument("-b","--blocking", nargs="+", help='Description of sample blocking: "blocking_condition*&sample-1-name&sample-2-name&sample-n-name"')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
171
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
172 args = parser.parse_args()
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
173
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
174 columns = None
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
175 if(args.columns_file):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
176 with open(args.columns_file, "r") as f:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
177 listed_columns = [None] + f.readline().strip("\n").split("\t")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
178 for i in range(1,len(listed_columns)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
179 listed_columns[i] = listed_columns[i].encode('base64').replace('\n','')
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
180
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
181 s = sampleContainer()
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
182
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
183 if(listed_columns):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
184 columns = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
185 for sample in args.sample_names:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
186 columns.append(listed_columns[int(sample)])
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
187
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
188
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
189 treatments = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
190 for treatment in args.treatments:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
191 treatment = treatment.split(":")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
192 for i in range(1,len(treatment)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
193 if(i%2 == 0):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
194 treatment_tmp = treatment[i].split(",")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
195 for j in range(len(treatment_tmp)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
196 treatment_tmp[j] = listed_columns[int(treatment_tmp[j])]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
197 treatment[i] = ",".join(treatment_tmp)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
198
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
199 treatments.append(":".join(treatment))
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
200
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
201 blockings = []
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
202 if(args.blocking):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
203 for blocking in args.blocking:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
204 blocking = blocking.split(":")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
205 for i in range(1,len(blocking)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
206 block = blocking[i].split(",")
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
207 for j in range(len(block)):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
208 block[j] = listed_columns[int(block[j])]
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
209 blocking[i] = ",".join(block)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
210 blockings.append(":".join(blocking))
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
211
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
212 s.add_samples(columns)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
213 s.add_treatments(treatments)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
214 s.add_blocking(blockings)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
215
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
216 else:
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
217 s.add_samples(args.sample_names)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
218 s.add_treatments(args.treatments)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
219 if(args.blocking):
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
220 s.add_blocking(args.blocking)
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
221
a4a4c88783ea planemo upload for repository https://bitbucket.org/EMCbioinf/galaxy-tool-shed-tools/raw/master/edger_with_design_matrix commit 2700e500a4fb135a20ede7d52221a9d31f1aaa5e-dirty
yhoogstrate
parents:
diff changeset
222 s.export(args.output)