Downloads · 30 days
0
Dhruv369/BTP_Homorepeats
BTP_Homorepeats is a machine learning model from Dhruv369. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
def createexcel(sequencesdata, homorepeats, filenames): output = BytesIO() workbook = xlsxwriter.Workbook(output, {'inmemory': True}) worksheet = workbook.addworksheet()
Downloads · 30 days
0
Access
Public
Updated Oct 10, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md3.2 KB · 68%
From the Hugging Face model README
def create_excel(sequences_data, homorepeats, filenames): output = BytesIO() workbook = xlsxwriter.Workbook(output, {'in_memory': True}) worksheet = workbook.add_worksheet()
row = 0
# Iterate through sequences data grouped by filenames
for file_index, file_data in enumerate(sequences_data):
filename = filenames[file_index]
# Write filename as a separator row
worksheet.write(row, 0, f"File: {filename}")
row += 1
# Write the header for the current file
worksheet.write(row, 0, "Entry ID")
worksheet.write(row, 1, "Protein Name")
col = 2
for repeat in sorted(homorepeats):
worksheet.write(row, col, repeat)
col += 1
row += 1
# Write data for each sequence in the current file
for entry_id, protein_name, freq in file_data:
worksheet.write(row, 0, entry_id)
worksheet.write(row, 1, protein_name)
col = 2
for repeat in sorted(homorepeats):
worksheet.write(row, col, freq.get(repeat, 0))
col += 1
row += 1
# Add an empty row as a separator between files
row += 1
workbook.close()
output.seek(0)
return output
st.title("Protein Homorepeat Analysis")
uploaded_files = st.file_uploader("Upload CSV files", accept_multiple_files=True, type=["csv"])
if uploaded_files: all_homorepeats = set() all_sequences_data = [] filenames = []
for file in uploaded_files:
homorepeats, sequence_data = process_csv(file)
if homorepeats is not None:
all_homorepeats.update(homorepeats)
all_sequences_data.append(sequence_data)
filenames.append(file.name)
if all_sequences_data:
st.success(f"Processed {len(uploaded_files)} files successfully!")
# Step 3: Generate and download the Excel report
excel_file = create_excel(all_sequences_data, all_homorepeats, filenames)
# Download the Excel file
st.download_button(
label="Download Excel file",
data=excel_file,
file_name="protein_homorepeat_results.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
# Step 4: Display summary table
if st.checkbox("Show Results Table"):
# Convert the sequences data into a DataFrame for easy display
rows = []
for file_index, file_data in enumerate(all_sequences_data):
filename = filenames[file_index]
for entry_id, protein_name, freq in file_data:
row = {"Filename": filename, "Entry ID": entry_id, "Protein Name": protein_name}
row.update({repeat: freq.get(repeat, 0) for repeat in sorted(all_homorepeats)})
rows.append(row)
result_df = pd.DataFrame(rows)
st.dataframe(result_df)