1
+ #-------------------------------------------------------------------------------
2
+ # Name: module1
3
+ # Purpose:
4
+ #
5
+ # Author: Eli
6
+ #
7
+ # Created: 09/04/2014
8
+ # Copyright: (c) Eli 2014
9
+ # Licence: <your licence>
10
+ #-------------------------------------------------------------------------------
11
+
12
+ def main ():
13
+ pass
14
+
15
+ if __name__ == '__main__' :
16
+ main ()
17
+
18
+ f1 = open ("C:/rnaseq/polyA_data/clusters/1dpa_DE_fdr05_redo.txt" , "r" )
19
+ f2 = open ("C:/rnaseq/polyA_data/clusters/3dpa_DE_fdr05_redo.txt" , "r" )
20
+ f3 = open ("C:/rnaseq/polyA_data/clusters/8dpa_DE_fdr05_redo.txt" , "r" )
21
+
22
+ #Loop through files and extract ID's to lists
23
+ f1_ids = []
24
+ f2_ids = []
25
+ f3_ids = []
26
+
27
+ count = 1
28
+ for line in f1 :
29
+ if count == 1 : #skip header row
30
+ count += 1
31
+ pass
32
+ else :
33
+ f1_ids .append (str (line .split ("\t " )[0 ]))
34
+ count = 1
35
+ for line in f2 :
36
+ if count == 1 : #skip header row
37
+ count += 1
38
+ pass
39
+ else :
40
+ f2_ids .append (str (line .split ("\t " )[0 ]))
41
+ count = 1
42
+ for line in f3 :
43
+ if count == 1 : #skip header row
44
+ count += 1
45
+ pass
46
+ else :
47
+ f3_ids .append (str (line .split ("\t " )[0 ]))
48
+
49
+ #Cross check ID lists, errors can occur if the files aren't formatted properly.
50
+ #print f1_ids, f2_ids, f3_ids
51
+
52
+ f1 = open ("C:/rnaseq/polyA_data/clusters/1dpa_DE_fdr05_redo.txt" , "r" )
53
+ f2 = open ("C:/rnaseq/polyA_data/clusters/3dpa_DE_fdr05_redo.txt" , "r" )
54
+ f3 = open ("C:/rnaseq/polyA_data/clusters/8dpa_DE_fdr05_redo.txt" , "r" )
55
+
56
+ linecount = 1
57
+ for line in f1 : # check whether ids in first condition matched others
58
+ added = 0
59
+ if linecount == 1 :
60
+ linecount += 1
61
+ else :
62
+ for ids2 in f2_ids :
63
+ if ids2 in line : # 1dpa id matched to 3dpa id
64
+ for ids3 in f3_ids :
65
+ if ids3 in line : #1dpa id also matched to 8dpa
66
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-3-8dpa_redo.txt" , "a" ) as file_out :
67
+ file_out .write ("1dpa" + "\t " + line )
68
+ file_out .close ()
69
+ added = 1
70
+ break
71
+
72
+ else : #1dpa id only matched to 3dpa id
73
+ pass
74
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-3dpa_redo.txt" , "a" ) as file_out :
75
+ file_out .write ("1dpa" + "\t " + line )
76
+ file_out .close ()
77
+ added = 1
78
+ break
79
+ # id is unique to 1st condition
80
+ for ids3 in f3_ids :
81
+ if ids3 in line : #1dpa matched only to 8dpa
82
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-8dpa_redo.txt" , "a" ) as file_out :
83
+ file_out .write ("1dpa" + "\t " + line )
84
+ file_out .close ()
85
+ added = 1
86
+ break
87
+ else :
88
+ #print "unique to first condition"
89
+ pass
90
+ if added == 0 :
91
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1dpa_unique_redo.txt" , "a" ) as file_out :
92
+ file_out .write ("1dpa" + "\t " + line )
93
+ file_out .close ()
94
+ continue
95
+
96
+ linecount = 1
97
+ for line in f2 : # check whether ids in second condition matched others
98
+ added = 0
99
+ if linecount == 1 :
100
+ linecount += 1
101
+ else :
102
+ for ids1 in f1_ids :
103
+ if ids1 in line : # 3dpa id matched to 1dpa id
104
+ for ids3 in f3_ids :
105
+ #print "8dpa", ids
106
+ if ids3 in line : #1dpa id also matched to 8dpa
107
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-3-8dpa_redo.txt" , "a" ) as file_out :
108
+ file_out .write ("3dpa" + "\t " + line )
109
+ file_out .close ()
110
+ added = 1
111
+ break
112
+ else : #3dpa id only matched to 1dpa id
113
+ pass
114
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-3dpa_redo.txt" , "a" ) as file_out :
115
+ file_out .write ("3dpa" + "\t " + line )
116
+ file_out .close ()
117
+ added = 1
118
+ break
119
+ for ids3 in f3_ids :
120
+ if ids3 in line : #3dpa matched only to 8dpa
121
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_3-8dpa_redo.txt" , "a" ) as file_out :
122
+ file_out .write ("3dpa" + "\t " + line )
123
+ file_out .close ()
124
+ added = 1
125
+ break
126
+ else :
127
+ pass
128
+ if added == 0 :
129
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_3dpa_unique_redo.txt" , "a" ) as file_out :
130
+ file_out .write ("3dpa" + "\t " + line )
131
+ file_out .close ()
132
+ continue
133
+
134
+
135
+ linecount = 1
136
+ for line in f3 : # check whether ids in 3rd condition matched others
137
+ added = 0
138
+ if linecount == 1 :
139
+ linecount += 1
140
+ else :
141
+ for ids1 in f1_ids :
142
+ if ids1 in line : # 8dpa id matched to 1dpa id
143
+ for ids2 in f2_ids :
144
+ #print "3dpa", ids
145
+ if ids2 in line : #8dpa id also matched to 3dpa
146
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-3-8dpa_redo.txt" , "a" ) as file_out :
147
+ file_out .write ("8dpa" + "\t " + line )
148
+ file_out .close ()
149
+ added = 1
150
+ break
151
+ else : #8dpa id only matched to 1dpa id
152
+ pass
153
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_1-8dpa_redo.txt" , "a" ) as file_out :
154
+ file_out .write ("8dpa" + "\t " + line )
155
+ file_out .close ()
156
+ added = 1
157
+ break
158
+ for ids2 in f2_ids :
159
+ if ids2 in line : #8dpa matched only to 3dpa
160
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_3-8dpa_redo.txt" , "a" ) as file_out :
161
+ file_out .write ("8dpa" + "\t " + line )
162
+ file_out .close ()
163
+ added = 1
164
+ break
165
+ else :
166
+ pass
167
+ if added == 0 :
168
+ with open ("C:/RNAseq/polyA_data/clusters/edgeR_de_8dpa_unique_redo.txt" , "a" ) as file_out :
169
+ file_out .write ("8dpa" + "\t " + line )
170
+ file_out .close ()
171
+ continue
172
+
173
+ f1 .close
174
+ f2 .close
175
+ f3 .close
0 commit comments