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