Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument import interface: Sysmex XT4000i #537

Merged
merged 29 commits into from
Feb 1, 2018
Merged

Instrument import interface: Sysmex XT4000i #537

merged 29 commits into from
Feb 1, 2018

Conversation

xispa
Copy link
Member

@xispa xispa commented Jan 4, 2018

Description of the issue/feature this PR addresses

IMPORTANT: #536 needs to be accepted first

Import interface for 'Sysmex XT-4000i' instrument, a fluorescence flow cytometry for high quality haematology analysis. It uses 'Sysmex XT-1800i's Parser (#536), since they are in the same format.
https://www.sysmex-mea.com/products/xt-4000i-919.html

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

# We test in import functions if the file was uploaded
try:
if self._encoding:
import codecs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this import on the top of the module

# Some Instruments can generate files with different encodings, so we
# may need this parameter
self._separator = separator
self._encoding = encoding
Copy link
Contributor

@ramonski ramonski Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does these variables have to be prefixed with an _? Just a style question, but we want that our code looks nice and not like a regular expression (if possible).

Copy link
Member Author

@xispa xispa Jan 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to tell the dev that these variables are meant to be private, only for instance's internal use. Just want to make a bit difficult for the dev to do something like instance.encoding='wtf'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramonski @xispa for now I will leave the underscore.

f = open(infile.name, 'rU')
except AttributeError:
f = infile
for line in f.readlines():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file never gets closed. I'm not sure how this affects Memory in the long run, so I would prefer to use a context manager here, e.g. with file.open(...) and read the lines somewhere into a variable. Probably best to do that in a separate method. e.g. lines = self.read(infile.name). There you could also preprocess the lines, e.g. with lines.strip or similar

except AttributeError:
f = infile
for line in f.readlines():
self._numline += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramonski As far as I checked self._numline is used to show the line number in the logs

elif sline[0] == SEGMENT_RESULT:
return self._handle_result_line(sline)
elif sline[0] == SEGMENT_EOF:
return self._handle_eof(sline)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are accessing here multiple times the first element of the header, therefore I would create a variable like segment = sline[0] and then you could think of a mapping of segment -> handler to get it immediately, e.g.

handlers = {
    SEGMENT_HEADER: self._handle_header,
    ...
}
handler = hanlers.get(segment)
...

tbex = ''
try:
importer.process()
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid blind excepts

allowed_ar_states=status,
allowed_analysis_states=None,
override=over,
instrument_uid=instrument)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take care of indendation

elif sample == 'clientsid':
sam = ['getClientSampleID']
elif sample == 'sample_clientsid':
sam = ['getSampleID', 'getClientSampleID']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use a dictionary mapping here

elif override == 'override':
over = [True, False]
elif override == 'overrideempty':
over = [True, True]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use a dictionary mapping here

if artoapply == 'received':
status = ['sample_received']
elif artoapply == 'received_tobeverified':
status = ['sample_received', 'attachment_due', 'to_be_verified']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use a dictionary mapping here

@xispa xispa merged commit 6187342 into master Feb 1, 2018
@xispa xispa deleted the sysmex-xt4000i branch February 2, 2018 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants