Eitan177's picture
Update app.py
d0d4f8d verified
import streamlit as st
import pandas as pd
# Title and description
st.title("mastervariantfilextreme Filtering App for Genomic Data")
st.write("Upload a genomic data file, filter it by specified criteria, and download the filtered data.")
# File upload
uploaded_file = st.file_uploader("Upload your text file", type="txt")
if uploaded_file is not None:
# Read the file
dfd = pd.read_csv(uploaded_file, sep='\t')
# Define the columns to retain
columns_to_keep = [0, 0, 0, 11, 15, 1, 2, 2, 3, 4, 5, 8, 24]
# Use iloc to select columns by their integer position
dfd = dfd.iloc[:, columns_to_keep]
# Rename columns
dfd.columns = ['Project', 'Sample', 'ID', 'Genome', 'mut_type', 'chrom', 'pos_start', 'pos_end', 'REF', 'ALT', 'DEPTH', 'AF', 'FILTER']
# Filter the dataframe
dfd_filtered = dfd[(dfd['DEPTH'] > 200) & (dfd['FILTER'] == 'PASS') & (dfd['AF'] > 2)]
dfd_filtered.drop_duplicates(inplace=True)
# Display the filtered data
st.write("Filtered Data:")
st.dataframe(dfd_filtered)
# Download button for the filtered data
st.download_button(
label="Download filtered data as CSV",
data=dfd_filtered.to_csv(sep='\t', index=False),
file_name="txtformatted_for_sigprofile_filtered.txt",
mime="text/csv"
)
else:
st.write("Please upload a file to proceed.")