Conditions | 2 |
Total Lines | 83 |
Code Lines | 48 |
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 | #!/usr/bin/env python3 |
||
123 | def get_attributes(self): |
||
124 | """Common attribute definition required from Animal and samples. Need |
||
125 | to be called inside Animal/sample get_atribute method. Keys |
||
126 | is the name in metadata rules |
||
127 | |||
128 | Returns: |
||
129 | dict: a dictionary object |
||
130 | """ |
||
131 | |||
132 | attributes = {} |
||
133 | |||
134 | attributes['Data source ID'] = format_attribute( |
||
135 | value=self.data_source_id) |
||
136 | |||
137 | attributes['Alternative id'] = format_attribute( |
||
138 | value=self.alternative_id) |
||
139 | |||
140 | # HINT: this is a mandatory biosample field: could be removed from |
||
141 | # attributes? |
||
142 | attributes['Description'] = format_attribute( |
||
143 | value=self.description) |
||
144 | |||
145 | attributes["Project"] = format_attribute( |
||
146 | value="IMAGE") |
||
147 | |||
148 | attributes['Submission title'] = format_attribute( |
||
149 | value=self.submission.title) |
||
150 | |||
151 | attributes['Submission description'] = format_attribute( |
||
152 | value=self.submission.description) |
||
153 | |||
154 | attributes['Person last name'] = format_attribute( |
||
155 | value=self.owner.last_name) |
||
156 | |||
157 | attributes['Person initial'] = format_attribute( |
||
158 | value=self.person.initials) |
||
159 | |||
160 | attributes['Person first name'] = format_attribute( |
||
161 | value=self.owner.first_name) |
||
162 | |||
163 | attributes['Person email'] = format_attribute( |
||
164 | value="mailto:%s" % (self.owner.email)) |
||
165 | |||
166 | attributes['Person affiliation'] = format_attribute( |
||
167 | value=self.person.affiliation.name) |
||
168 | |||
169 | attributes['Person role'] = self.person.role.format_attribute() |
||
170 | |||
171 | attributes['Organization name'] = format_attribute( |
||
172 | value=self.organization.name) |
||
173 | |||
174 | attributes['Organization address'] = format_attribute( |
||
175 | value=self.organization.address) |
||
176 | |||
177 | attributes['Organization uri'] = format_attribute( |
||
178 | value=self.organization.URI) |
||
179 | |||
180 | attributes['Organization country'] = \ |
||
181 | self.organization.country.format_attribute() |
||
182 | |||
183 | attributes[ |
||
184 | 'Organization role'] = self.organization.role.format_attribute() |
||
185 | |||
186 | # this could be present or not |
||
187 | if self.name.publication: |
||
188 | attributes['Publication DOI'] = format_attribute( |
||
189 | value=self.name.publication.doi) |
||
190 | |||
191 | attributes['Gene bank name'] = format_attribute( |
||
192 | value=self.gene_bank_name) |
||
193 | |||
194 | attributes[ |
||
195 | 'Gene bank country'] = self.gene_bank_country.format_attribute() |
||
196 | |||
197 | attributes['Data source type'] = format_attribute( |
||
198 | value=self.submission.get_datasource_type_display()) |
||
199 | |||
200 | attributes['Data source version'] = format_attribute( |
||
201 | value=self.submission.datasource_version) |
||
202 | |||
203 | attributes['Species'] = self.specie.format_attribute() |
||
204 | |||
205 | return attributes |
||
206 | |||
292 |