Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
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
85 changes: 85 additions & 0 deletions scripts/qc/alpha_first_time_report_generator.py
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.
89 changes: 89 additions & 0 deletions scripts/qc/alpha_second_time_report_generator.py
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: ")
Copy link
Contributor Author

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): ")

#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.