Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions scripts/S02_3.2.4_uniqueIDs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
os.makedirs(pathTo2)
except OSError:
pass
f0 = open(pathTo2+"/Genotype_fasta-headers-rename.log", "a+") # change appropriately how do you want to call log table
fname=glob.glob(pathTo1+"/assemblerNameGenotype*.fasta") # change appropriately pattern in your file naming
for i in range (len(fname)):
vname=fname[i].split("/")
vname=vname[len(vname)-1]
idname=re.sub('\.fasta$', '', vname)
f4 = open(fname[i], "r")
f5 = open(pathTo2+"/"+str(idname) + "_renamed.fasta", "w")
line4=f4.readline()
count=1
while line4:
line4=str.rstrip(line4)
if '>' in line4:
line44=">"+str(idname)+"_"+str(count)
f5.write("%s\n" % (line44))
f0.write("%s\t" % (line4))
f0.write("%s\n" % (line44))
count=count+1
else:
f5.write("%s\n" % (line4))
line4 = f4.readline()
f4.close()
f5.close()
f0.close()
with open(f"{pathTo2}/Genotype_fasta-headers-rename.log", "a+") as f0:
fname = glob.glob(f"{pathTo1}/assemblerNameGenotype*.fasta")
for item in fname:
vname = item.split("/")
vname=vname[len(vname)-1]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

suggestion (llm): Using 'os.path.basename' would be a more robust method for extracting the file name from a path.

Suggested change
vname=vname[len(vname)-1]
+ vname = os.path.basename(item)

idname=re.sub('\.fasta$', '', vname)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

suggestion (llm): Consider precompiling the regular expression outside of the loop for better performance, as it does not change per iteration.

Suggested change
idname=re.sub('\.fasta$', '', vname)
Outside the loop: pattern = re.compile('\\.fasta$')

with open(item, "r") as f4:
f5 = open(f"{pathTo2}/{str(idname)}_renamed.fasta", "w")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

issue (llm): The file opened as 'f5' should be managed using a 'with' statement to ensure it is properly closed even if an error occurs.

Suggested change
f5 = open(f"{pathTo2}/{str(idname)}_renamed.fasta", "w")
+ with open(f"{pathTo2}/{str(idname)}_renamed.fasta", "w") as f5:

line4=f4.readline()
count=1
while line4:
line4=str.rstrip(line4)
if '>' in line4:
line44 = f">{str(idname)}_{str(count)}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nitpick (llm): The 'str' function is redundant when using formatted string literals (f-strings).

Suggested change
line44 = f">{str(idname)}_{str(count)}"
+ line44 = f">{idname}_{count}"

f5.write("%s\n" % (line44))
f0.write("%s\t" % (line4))
f0.write("%s\n" % (line44))
count=count+1
else:
f5.write("%s\n" % (line4))
line4 = f4.readline()
f5.close()
Comment on lines -12 to +33
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 12-35 refactored with the following changes:

This removes the following comments ( why? ):

# change appropriately how do you want to call log table
# change appropriately pattern in your file naming

27 changes: 18 additions & 9 deletions scripts/S03_3.3.9_MSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@
import numbers

# ref: https://www.geeksforgeeks.org/print-colors-python-terminal/
def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))
def prYellow(skk): print("\033[93m {}\033[00m" .format(skk))
def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk))
def prPurple(skk): print("\033[95m {}\033[00m" .format(skk))
def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))
def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk))
def prBlack(skk): print("\033[98m {}\033[00m" .format(skk))
def prBlue(skk): print("\033[94m {}\033[00m" .format(skk))
def prRed(skk):
print(f"\033[91m {skk}\033[00m")
Comment on lines -14 to +15
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prRed refactored with the following changes:

def prGreen(skk):
print(f"\033[92m {skk}\033[00m")
Comment on lines -15 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prGreen refactored with the following changes:

def prYellow(skk):
print(f"\033[93m {skk}\033[00m")
Comment on lines -16 to +19
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prYellow refactored with the following changes:

def prLightPurple(skk):
print(f"\033[94m {skk}\033[00m")
Comment on lines -17 to +21
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prLightPurple refactored with the following changes:

def prPurple(skk):
print(f"\033[95m {skk}\033[00m")
Comment on lines -18 to +23
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prPurple refactored with the following changes:

def prCyan(skk):
print(f"\033[96m {skk}\033[00m")
Comment on lines -19 to +25
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prCyan refactored with the following changes:

def prLightGray(skk):
print(f"\033[97m {skk}\033[00m")
Comment on lines -20 to +27
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prLightGray refactored with the following changes:

def prBlack(skk):
print(f"\033[98m {skk}\033[00m")
Comment on lines -21 to +29
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prBlack refactored with the following changes:

def prBlue(skk):
print(f"\033[94m {skk}\033[00m")
Comment on lines -22 to +31
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prBlue refactored with the following changes:


# from BioPython
def read_fasta(fp):
Expand Down