-
Notifications
You must be signed in to change notification settings - Fork 71
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
an alpha version of a report generator that creats a report of the re… #416
Open
shadizaheri
wants to merge
1
commit into
main
Choose a base branch
from
sz_alpha_report_generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import docx | ||
from docx.shared import Inches | ||
import os | ||
import glob | ||
from pdf2image import convert_from_path, convert_from_bytes | ||
from pdf2image.exceptions import ( | ||
PDFInfoNotInstalledError, | ||
PDFPageCountError, | ||
PDFSyntaxError | ||
) | ||
# Get the current working directory | ||
cwd = os.getcwd() | ||
output_file = input("Enter the desired name of output file (do not include the .docx part): ") | ||
|
||
# Print the current working directory | ||
print("Current working directory: {0}".format(cwd)) | ||
|
||
#path_to_files = r'/Users/szaheri/Documents/SV/GATK-SV/github_ryan_shared/bwa_dragen_sample_level_comparison/results/bwa/perFamily_plots_tarball/bwa_samples_aligning_with_dragen_perFamily_plots/supporting_plots/sv_inheritance_plots/' | ||
#folder = r'/Users/szaheri/Documents/SV/GATK-SV/github_ryan_shared/bwa_dragen_sample_level_comparison/results/bwa/perFamily_plots_tarball/bwa_samples_aligning_with_dragen_perFamily_plots/supporting_plots/sv_inheritance_plots/' | ||
|
||
path_to_files = os.getcwd()+ '/' | ||
folder = os.getcwd()+ '/' | ||
head_tail = os.path.split(cwd) | ||
|
||
print(head_tail) | ||
# print tail part of the path | ||
print(head_tail[1]) | ||
|
||
files = [folder + fn for fn in os.listdir(folder) if fn.endswith('.pdf')] | ||
print(files) | ||
# Convert them. | ||
def pic(path, name): | ||
images = convert_from_path(path + name) #+ '.pdf' | ||
for i in range(len(images)): | ||
images[i].save(name[:-4] +str(i) +'.jpg', 'JPEG') | ||
|
||
|
||
#pic(path_to_files,'all.pdf') | ||
|
||
|
||
for filee in glob. glob("*.pdf"): | ||
#print(filee) | ||
pic(path_to_files,filee) | ||
|
||
|
||
|
||
mydoc = docx.Document() | ||
#mydoc = docx.Document("dragen_sample_level.docx") | ||
mydoc.add_paragraph("This is a report of the " + str(head_tail[0])) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
|
||
files = [folder + fn for fn in os.listdir(folder) if fn.endswith('.pdf')] | ||
print(files) | ||
# Convert them. | ||
#def pic(path, name): | ||
# images = convert_from_path(path + name) #+ '.pdf' | ||
# for i in range(len(images)): | ||
# images[i].save(name +str(i) +'.jpg', 'JPEG') | ||
|
||
|
||
#pic(path_to_files,'all.pdf') | ||
|
||
mydoc.add_heading(str(head_tail[1]), 0) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
for filee in glob. glob("*.jpg" or "*.png"): | ||
print(filee) | ||
#pic(path_to_files,filee) | ||
mydoc.add_heading(str(filee[:-4]), 1) | ||
mydoc.save(str(output_file) + ".docx") | ||
mydoc.add_picture(filee, width=Inches(6.0))#, width=docx.shared.Inches(5), height=docx.shared.Inches(5)) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
|
||
for filee in glob. glob("*.png"): | ||
print(filee) | ||
#pic(path_to_files,filee) | ||
mydoc.add_heading(str(filee[:-4]), 1) | ||
mydoc.save(str(output_file) + ".docx") | ||
mydoc.add_picture(filee, width=Inches(6.0))#, width=docx.shared.Inches(5), height=docx.shared.Inches(5)) | ||
mydoc.save(str(output_file) + ".docx") | ||
# You’re free to specify both width and height, but usually you wouldn’t want to. | ||
# If you specify only one, python-docx uses it to calculate the properly scaled value of the other. | ||
# This way the aspect ratio is preserved and your picture doesn’t look stretched. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import docx | ||
from docx.shared import Inches | ||
import os | ||
import glob | ||
from pdf2image import convert_from_path, convert_from_bytes | ||
from pdf2image.exceptions import ( | ||
PDFInfoNotInstalledError, | ||
PDFPageCountError, | ||
PDFSyntaxError | ||
) | ||
# Get the current working directory | ||
cwd = os.getcwd() | ||
output_file = input("This script assumes that there is already a .docx created \n if this is the first time runing this script please first run the alpha_first_time_report_generator.py \n Enter the name of the already existing output file: ") | ||
#output_file = "CleftPalete_WGS_GATK-SV" | ||
# Print the current working directory | ||
print("Current working directory: {0}".format(cwd)) | ||
|
||
#path_to_files = r'/Users/szaheri/Documents/SV/GATK-SV/github_ryan_shared/bwa_dragen_sample_level_comparison/results/bwa/perFamily_plots_tarball/bwa_samples_aligning_with_dragen_perFamily_plots/supporting_plots/sv_inheritance_plots/' | ||
#folder = r'/Users/szaheri/Documents/SV/GATK-SV/github_ryan_shared/bwa_dragen_sample_level_comparison/results/bwa/perFamily_plots_tarball/bwa_samples_aligning_with_dragen_perFamily_plots/supporting_plots/sv_inheritance_plots/' | ||
|
||
path_to_files = os.getcwd()+ '/' | ||
folder = os.getcwd()+ '/' | ||
head_tail = os.path.split(cwd) | ||
|
||
print(head_tail) | ||
# print tail part of the path | ||
print(head_tail[1]) | ||
|
||
files = [folder + fn for fn in os.listdir(folder) if fn.endswith('.pdf')] | ||
print(files) | ||
# Convert them. | ||
def pic(path, name): | ||
images = convert_from_path(path + name) #+ '.pdf' | ||
for i in range(len(images)): | ||
images[i].save(name[:-4] +str(i) +'.jpg', 'JPEG') | ||
|
||
|
||
#pic(path_to_files,'all.pdf') | ||
|
||
|
||
for filee in glob. glob("*.pdf"): | ||
#print(filee) | ||
pic(path_to_files,filee) | ||
|
||
|
||
|
||
#mydoc = docx.Document() | ||
mydoc = docx.Document(str(output_file) + ".docx") | ||
mydoc.add_paragraph("This is a report of the " + str(head_tail[0])) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
|
||
#mydoc.add_paragraph("This is the second paragraph of a MS Word file.") | ||
#mydoc.save("my_written_file.docx") | ||
|
||
|
||
files = [folder + fn for fn in os.listdir(folder) if fn.endswith('.pdf')] | ||
print(files) | ||
# Convert them. | ||
#def pic(path, name): | ||
# images = convert_from_path(path + name) #+ '.pdf' | ||
# for i in range(len(images)): | ||
# images[i].save(name +str(i) +'.jpg', 'JPEG') | ||
|
||
|
||
#pic(path_to_files,'all.pdf') | ||
|
||
mydoc.add_heading(str(head_tail[1]), 0) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
for filee in glob. glob("*.jpg" or "*.png"): | ||
print(filee) | ||
#pic(path_to_files,filee) | ||
mydoc.add_heading(str(filee[:-4]), 1) | ||
mydoc.save(str(output_file) + ".docx") | ||
mydoc.add_picture(filee, width=Inches(6.0))#, width=docx.shared.Inches(5), height=docx.shared.Inches(5)) | ||
mydoc.save(str(output_file) + ".docx") | ||
|
||
|
||
for filee in glob. glob("*.png"): | ||
print(filee) | ||
#pic(path_to_files,filee) | ||
mydoc.add_heading(str(filee[:-4]), 1) | ||
mydoc.save(str(output_file) + ".docx") | ||
mydoc.add_picture(filee, width=Inches(6.0))#, width=docx.shared.Inches(5), height=docx.shared.Inches(5)) | ||
mydoc.save(str(output_file) + ".docx") | ||
# You’re free to specify both width and height, but usually you wouldn’t want to. | ||
# If you specify only one, python-docx uses it to calculate the properly scaled value of the other. | ||
# This way the aspect ratio is preserved and your picture doesn’t look stretched. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
output_file = input("This script assumes that there is already a .docx created \n if this is the first time runing this script please first run the alpha_first_time_report_generator.py \n Enter the name of the already existing output file (do not include the .docx part): ")