Skip to content

Upgrade to python 3#3

Open
emma2207 wants to merge 5 commits intoheinc1010:masterfrom
emma2207:python-version
Open

Upgrade to python 3#3
emma2207 wants to merge 5 commits intoheinc1010:masterfrom
emma2207:python-version

Conversation

@emma2207
Copy link

@emma2207 emma2207 commented Nov 12, 2025

I could not get the original tool to work on the HPC because I was having difficulties getting the older versions of libraries in my conda environment, and I ended up upgrading to the code to use python 3.
I confirmed that the tool works with the provided tutorial data and cleaned up the list of imports.

@emma2207
Copy link
Author

@heinc1010 I hope you don't mind me barging in here and proposing an upgrade to Python 3!
I tried to keep it as minimal as possible.

Copilot AI review requested due to automatic review settings December 9, 2025 20:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR upgrades BAMixChecker from Python 2.7 to Python 3, making it compatible with modern Python environments and HPC systems. The upgrade includes comprehensive changes to adapt the codebase to Python 3 syntax and semantics.

  • Replaced the deprecated commands module with subprocess
  • Converted all print statements to function calls and exit() to sys.exit()
  • Added proper byte-to-string decoding for subprocess outputs
  • Updated bitwise operators to logical operators and fixed dictionary iteration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
README.md Updated Python version requirement from 2.7 to 3
BAMixChecker.py Comprehensive Python 3 migration including syntax updates, module replacements, proper string handling for subprocess outputs, operator corrections, and exception handling improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

print " HTML file or Heatmap would not be created properly."
print " Recommand to install related R packages."
print " - Required R packages : rmarkdown, ztable, corrplot."
print("WARNING: Requied R packages are not installed.")
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo: "Requied" should be "Required".

Suggested change
print("WARNING: Requied R packages are not installed.")
print("WARNING: Required R packages are not installed.")

Copilot uses AI. Check for mistakes.
print " - Required R packages : rmarkdown, ztable, corrplot."
print("WARNING: Requied R packages are not installed.")
print(" HTML file or Heatmap would not be created properly.")
print(" Recommand to install related R packages.")
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo: "Recommand" should be "Recommend".

Suggested change
print(" Recommand to install related R packages.")
print(" Recommend to install related R packages.")

Copilot uses AI. Check for mistakes.
Comment on lines +918 to +919
print("## ERROR: Reference file is necessary. Use -r option.")
sys.exit(1)
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The print exit() statement on line 919 is incorrect syntax. This should be just sys.exit(1) without the print statement wrapping it. The exit() function doesn't return a value to print.

Copilot uses AI. Check for mistakes.
print dir_path
print "## ERROR: Option -d and -l are exclusive. Try with one of the options.\n##\t Check 'https://github.com/heinc1010/BAMixChecker' for more information about the options of BAMixChecker."
exit()
print(dir_path)
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The dir_path variable is printed here but it hasn't been assigned a value yet in this code path. At this point, dir_path is still an empty string (initialized on line 875). This print statement should be removed or moved to after line 888 where dir_path is actually assigned, or the variable should reference args.DIR instead.

Suggested change
print(dir_path)
print(args.DIR)

Copilot uses AI. Check for mistakes.
if args.RefVer in [ "hg38","hg19" ]:
if args.BEDfile != '':
print "Run for targeted sequecing data"
print("Run for targeted sequecing data")
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo: "sequecing" should be "sequencing".

Suggested change
print("Run for targeted sequecing data")
print("Run for targeted sequencing data")

Copilot uses AI. Check for mistakes.
print " Refer the instruction or given error message above from GATK."
exit()
print("## ERROR: Calling error with GATK HaplotyCaller.")
print(" Preperation for calling with GATK is instructed in gitHub 'https://github.com/heinc1010/BAMixChecker'.")
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo: "Preperation" should be "Preparation".

Suggested change
print(" Preperation for calling with GATK is instructed in gitHub 'https://github.com/heinc1010/BAMixChecker'.")
print(" Preparation for calling with GATK is instructed in gitHub 'https://github.com/heinc1010/BAMixChecker'.")

Copilot uses AI. Check for mistakes.
print "## The specificity could be lower with the small numbr of SNP loci."
print "Make an optimized list of SNPs to compare - 'targetSNPs.bed'\n",
print("## WARNING: The target size is too small, so the number of SNP sites to compare is under 200.")
print("## The specificity could be lower with the small numbr of SNP loci.")
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo: "numbr" should be "number".

Suggested change
print("## The specificity could be lower with the small numbr of SNP loci.")
print("## The specificity could be lower with the small number of SNP loci.")

Copilot uses AI. Check for mistakes.
if ( dic_sw == None ) & ( dic_un_p == None):
print "## WARNING : The file names don't have detectable common regulation."
print " Pairing samples only by genotype."
if ( dic_sw == None ) and ( dic_un_p == None):
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Testing for None should use the 'is' operator.

Suggested change
if ( dic_sw == None ) and ( dic_un_p == None):
if ( dic_sw is None ) and ( dic_un_p is None):

Copilot uses AI. Check for mistakes.
if ( dic_sw == None ) & ( dic_un_p == None):
print "## WARNING : The file names don't have detectable common regulation."
print " Pairing samples only by genotype."
if ( dic_sw == None ) and ( dic_un_p == None):
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Testing for None should use the 'is' operator.

Suggested change
if ( dic_sw == None ) and ( dic_un_p == None):
if ( dic_sw is None ) and ( dic_un_p is None):

Copilot uses AI. Check for mistakes.
if isinstance(stderr, bytes):
stderr = stderr.decode('utf-8', errors='replace')
if isinstance(stdoutput, bytes):
stdoutput = stdoutput.decode('utf-8', errors='replace')
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Variable stdoutput is not used.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants