Conditions | 8 |
Total Lines | 136 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import abc |
||
77 | def __call__(self, target: Target) -> Sequence[Target]: |
||
78 | """ |
||
79 | |||
80 | Returns: |
||
81 | |||
82 | """ |
||
83 | # traverse the DAG up and down, following only desired links |
||
84 | # some links from complex to complex group are "overlaps with" |
||
85 | # ex: CHEMBL4296059 |
||
86 | # it's also rare to need going from a selectivity group "down" to complex group / family / etc. |
||
87 | # usually they have a link upwards |
||
88 | # so... |
||
89 | # If it's a single protein, it's too risk to traverse up into complexes |
||
90 | # That's because lots of proteins *occasionally* make complexes, and there are some weird ones |
||
91 | # BUT We want to catch some obvious cases like GABA A subunits |
||
92 | # ChEMBL calls many of these "something subunit something" |
||
93 | # This is the only time we'll allow going directly from protein to complex |
||
94 | # In this case, we'll also disallow links form protein to family, |
||
95 | # just because we're pretty sure it's a subunit |
||
96 | # But we can go from single protein to complex to complex group to family |
||
97 | if ( |
||
98 | target.type |
||
99 | in [ |
||
100 | TargetType.single_protein, |
||
101 | TargetType.protein_family, |
||
102 | TargetType.protein_complex, |
||
103 | TargetType.protein_complex_group, |
||
104 | ] |
||
105 | and ("subunit" in target.name.split(" ") or "chain" in target.name.split(" ")) |
||
106 | ): |
||
107 | edges = { |
||
108 | DagTargetLinkType( |
||
109 | TargetType.single_protein, |
||
110 | TargetRelationshipType.subset_of, |
||
111 | TargetType.protein_complex, |
||
112 | ), |
||
113 | DagTargetLinkType( |
||
114 | TargetType.protein_complex, |
||
115 | TargetRelationshipType.subset_of, |
||
116 | TargetType.protein_complex_group, |
||
117 | ), |
||
118 | DagTargetLinkType( |
||
119 | TargetType.protein_complex, |
||
120 | TargetRelationshipType.overlaps_with, |
||
121 | TargetType.protein_complex_group, |
||
122 | ), |
||
123 | DagTargetLinkType( |
||
124 | TargetType.protein_complex_group, |
||
125 | TargetRelationshipType.subset_of, |
||
126 | TargetType.protein_complex_group, |
||
127 | ), |
||
128 | DagTargetLinkType( |
||
129 | TargetType.protein_complex_group, |
||
130 | TargetRelationshipType.subset_of, |
||
131 | TargetType.protein_family, |
||
132 | ), |
||
133 | DagTargetLinkType( |
||
134 | TargetType.protein_family, |
||
135 | TargetRelationshipType.subset_of, |
||
136 | TargetType.protein_family, |
||
137 | ), |
||
138 | } |
||
139 | elif target.type in [TargetType.single_protein, TargetType.protein_family]: |
||
140 | edges = { |
||
141 | DagTargetLinkType( |
||
142 | TargetType.single_protein, |
||
143 | TargetRelationshipType.subset_of, |
||
144 | TargetType.protein_family, |
||
145 | ), |
||
146 | DagTargetLinkType( |
||
147 | TargetType.protein_family, |
||
148 | TargetRelationshipType.subset_of, |
||
149 | TargetType.protein_family, |
||
150 | ), |
||
151 | } |
||
152 | elif target.type in [TargetType.protein_complex, TargetType.protein_complex_group]: |
||
153 | edges = { |
||
154 | DagTargetLinkType( |
||
155 | TargetType.protein_complex, |
||
156 | TargetRelationshipType.subset_of, |
||
157 | TargetType.protein_complex_group, |
||
158 | ), |
||
159 | DagTargetLinkType( |
||
160 | TargetType.protein_complex, |
||
161 | TargetRelationshipType.overlaps_with, |
||
162 | TargetType.protein_complex_group, |
||
163 | ), |
||
164 | DagTargetLinkType( |
||
165 | TargetType.protein_complex_group, |
||
166 | TargetRelationshipType.subset_of, |
||
167 | TargetType.protein_complex_group, |
||
168 | ), |
||
169 | DagTargetLinkType( |
||
170 | TargetType.protein_complex_group, |
||
171 | TargetRelationshipType.subset_of, |
||
172 | TargetType.protein_family, |
||
173 | ), |
||
174 | DagTargetLinkType( |
||
175 | TargetType.protein_family, |
||
176 | TargetRelationshipType.subset_of, |
||
177 | TargetType.protein_family, |
||
178 | ), |
||
179 | } |
||
180 | elif target.type == TargetType.selectivity_group: |
||
181 | edges = { |
||
182 | DagTargetLinkType( |
||
183 | TargetType.selectivity_group, |
||
184 | TargetRelationshipType.superset_of, |
||
185 | TargetType.protein_complex_group, |
||
186 | ), |
||
187 | DagTargetLinkType( |
||
188 | TargetType.protein_complex_group, |
||
189 | TargetRelationshipType.subset_of, |
||
190 | TargetType.protein_complex_group, |
||
191 | ), |
||
192 | DagTargetLinkType( |
||
193 | TargetType.selectivity_group, |
||
194 | TargetRelationshipType.superset_of, |
||
195 | TargetType.protein_family, |
||
196 | ), |
||
197 | DagTargetLinkType( |
||
198 | TargetType.protein_family, |
||
199 | TargetRelationshipType.subset_of, |
||
200 | TargetType.protein_family, |
||
201 | ), |
||
202 | } |
||
203 | else: |
||
204 | return [target] |
||
205 | for edge in set(edges): |
||
206 | edges.add( |
||
207 | DagTargetLinkType( |
||
208 | edge.source_type, TargetRelationshipType.equivalent_to, edge.dest_type |
||
209 | ) |
||
210 | ) |
||
211 | found = target.traverse(edges) |
||
212 | return [f.target for f in found if f.is_end] |
||
213 | |||
273 |