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