-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sourcery refactored master branch #4
base: master
Are you sure you want to change the base?
Conversation
if reads2: | ||
if output2 is None: | ||
raise click.UsageError(f'If paired reads are specified, you must ' | ||
f'specify an output file for the filtered ' | ||
f'reverse reads with `-O/--output2`!') | ||
if reads2 and output2 is None: | ||
raise click.UsageError(f'If paired reads are specified, you must ' | ||
f'specify an output file for the filtered ' | ||
f'reverse reads with `-O/--output2`!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function main refactored with the following changes:
- Merge nested if conditions
- Remove redundant conditional
if node is not None: | ||
all_taxids = node.taxids_set() | ||
else: | ||
all_taxids = set() | ||
all_taxids = node.taxids_set() if node is not None else set() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function find_target_read_ids refactored with the following changes:
- Replace if statement with if expression
if sciname == 'unclassified' or sciname == 'root': | ||
if sciname in ['unclassified', 'root']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TaxNode.build_taxonomy_tree refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator
if centrifuge_results is not None \ | ||
and kraken2_results is not None \ | ||
and tcr.kraken2_unclassified is not None \ | ||
and tcr.kraken2_targets is not None \ | ||
and tcr.centrifuge_unclassified is not None \ | ||
and tcr.centrifuge_targets is not None: | ||
n_target_uq_c = len(tcr.centrifuge_targets - tcr.kraken2_targets) | ||
n_target_uq_k2 = len(tcr.kraken2_targets - tcr.centrifuge_targets) | ||
n_target_total = len(target_read_ids) | ||
logging.info(f'Total viral reads={n_target_total}') | ||
logging.info(f'Centrifuge found n={n_target_uq_c} target reads not ' | ||
f'found with Kraken2') | ||
logging.info(f'Kraken2 found n={n_target_uq_k2} target reads not found' | ||
f' with Centrifuge') | ||
if ( | ||
centrifuge_results is None | ||
or kraken2_results is None | ||
or tcr.kraken2_unclassified is None | ||
or tcr.kraken2_targets is None | ||
or tcr.centrifuge_unclassified is None | ||
or tcr.centrifuge_targets is None | ||
): | ||
return | ||
n_target_uq_c = len(tcr.centrifuge_targets - tcr.kraken2_targets) | ||
n_target_uq_k2 = len(tcr.kraken2_targets - tcr.centrifuge_targets) | ||
n_target_total = len(target_read_ids) | ||
logging.info(f'Total viral reads={n_target_total}') | ||
logging.info(f'Centrifuge found n={n_target_uq_c} target reads not ' | ||
f'found with Kraken2') | ||
logging.info(f'Kraken2 found n={n_target_uq_k2} target reads not found' | ||
f' with Centrifuge') | ||
|
||
uc_uq_k2 = tcr.kraken2_unclassified - tcr.centrifuge_unclassified | ||
uc_uq_c = tcr.centrifuge_unclassified - tcr.kraken2_unclassified | ||
if tcr.centrifuge_df_results is not None \ | ||
and isinstance(tcr.centrifuge_df_results, pd.DataFrame): | ||
c_read_ids = set(tcr.centrifuge_df_results.index) | ||
n_k2_not_in_centrifuge = len(uc_uq_k2 - c_read_ids) | ||
if n_k2_not_in_centrifuge: | ||
logging.info(f'N={n_k2_not_in_centrifuge} Unclassified reads ' | ||
f'by Kraken2 not in Centrifuge results') | ||
if tcr.kraken2_df_results is not None \ | ||
and isinstance(tcr.kraken2_df_results, pd.DataFrame): | ||
k2_read_ids = set(tcr.kraken2_df_results.index) | ||
n_c_not_in_k2 = len(uc_uq_c - k2_read_ids) | ||
if n_c_not_in_k2: | ||
logging.info(f'N={n_c_not_in_k2} Unclassified reads by ' | ||
f'Centrifuge not in Kraken2 results') | ||
if tcr.centrifuge_unclassified and tcr.kraken2_unclassified: | ||
uc_intersect = tcr.centrifuge_unclassified \ | ||
& tcr.kraken2_unclassified | ||
logging.info(f'N={len(uc_intersect)} reads unclassified by both ' | ||
f'Centrifuge and Kraken2.') | ||
uc_uq_k2 = tcr.kraken2_unclassified - tcr.centrifuge_unclassified | ||
uc_uq_c = tcr.centrifuge_unclassified - tcr.kraken2_unclassified | ||
if tcr.centrifuge_df_results is not None \ | ||
and isinstance(tcr.centrifuge_df_results, pd.DataFrame): | ||
c_read_ids = set(tcr.centrifuge_df_results.index) | ||
n_k2_not_in_centrifuge = len(uc_uq_k2 - c_read_ids) | ||
if n_k2_not_in_centrifuge: | ||
logging.info(f'N={n_k2_not_in_centrifuge} Unclassified reads ' | ||
f'by Kraken2 not in Centrifuge results') | ||
if tcr.kraken2_df_results is not None \ | ||
and isinstance(tcr.kraken2_df_results, pd.DataFrame): | ||
k2_read_ids = set(tcr.kraken2_df_results.index) | ||
n_c_not_in_k2 = len(uc_uq_c - k2_read_ids) | ||
if n_c_not_in_k2: | ||
logging.info(f'N={n_c_not_in_k2} Unclassified reads by ' | ||
f'Centrifuge not in Kraken2 results') | ||
if tcr.centrifuge_unclassified and tcr.kraken2_unclassified: | ||
uc_intersect = tcr.centrifuge_unclassified \ | ||
& tcr.kraken2_unclassified | ||
logging.info(f'N={len(uc_intersect)} reads unclassified by both ' | ||
f'Centrifuge and Kraken2.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compare_kraken2_and_centrifuge refactored with the following changes:
- Add guard clause
return sum([1 for l in f]) | ||
return sum(1 for l in f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function count_lines refactored with the following changes:
- Replace unneeded comprehension with generator
db3ba76
to
dc9118a
Compare
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: