-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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] | ||||||
| idname=re.sub('\.fasta$', '', vname) | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| with open(item, "r") as f4: | ||||||
| f5 = open(f"{pathTo2}/{str(idname)}_renamed.fasta", "w") | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| line4=f4.readline() | ||||||
| count=1 | ||||||
| while line4: | ||||||
| line4=str.rstrip(line4) | ||||||
| if '>' in line4: | ||||||
| line44 = f">{str(idname)}_{str(count)}" | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prGreen(skk): | ||
| print(f"\033[92m {skk}\033[00m") | ||
|
Comment on lines
-15
to
+17
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prYellow(skk): | ||
| print(f"\033[93m {skk}\033[00m") | ||
|
Comment on lines
-16
to
+19
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prLightPurple(skk): | ||
| print(f"\033[94m {skk}\033[00m") | ||
|
Comment on lines
-17
to
+21
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prPurple(skk): | ||
| print(f"\033[95m {skk}\033[00m") | ||
|
Comment on lines
-18
to
+23
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prCyan(skk): | ||
| print(f"\033[96m {skk}\033[00m") | ||
|
Comment on lines
-19
to
+25
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prLightGray(skk): | ||
| print(f"\033[97m {skk}\033[00m") | ||
|
Comment on lines
-20
to
+27
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prBlack(skk): | ||
| print(f"\033[98m {skk}\033[00m") | ||
|
Comment on lines
-21
to
+29
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| def prBlue(skk): | ||
| print(f"\033[94m {skk}\033[00m") | ||
|
Comment on lines
-22
to
+31
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # from BioPython | ||
| def read_fasta(fp): | ||
|
|
||
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.
suggestion (llm): Using 'os.path.basename' would be a more robust method for extracting the file name from a path.