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

New tree plot #103

Open
wants to merge 9 commits into
base: dev
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
5 changes: 4 additions & 1 deletion bin/gene_overlaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Code written by Chris Wyatt with some editing by ChatGPT

library(dplyr)
library(GenomicRanges)

# Parse command-line arguments
Expand All @@ -19,6 +20,9 @@ read_gff_to_granges <- function(gff_file) {
gff_data <- read.delim(gff_file, header = FALSE, comment.char = "#")
colnames(gff_data) <- c("seqname", "source", "feature", "start", "end",
"score", "strand", "frame", "attribute")
gff_data <- gff_data %>%
filter(strand %in% c("-","+"))

gr <- GRanges(
seqnames = gff_data$seqname,
ranges = IRanges(start = gff_data$start, end = gff_data$end),
Expand Down Expand Up @@ -67,7 +71,6 @@ for (i in seq_len(length(overlap_results))) {
if (query_idx != subject_idx) {
query_gene <- genes[query_idx]
subject_gene <- genes[subject_idx]

overlap_range <- intersect(ranges(query_gene), ranges(subject_gene))
overlap_length <- width(overlap_range)

Expand Down
63 changes: 63 additions & 0 deletions bin/gene_overlaps_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python3

# Written using ChatGPT

import pandas as pd
import argparse

# Set up the argument parser
parser = argparse.ArgumentParser(description='Extract gene statistics from files.')
parser.add_argument('input_files', nargs='+', help='List of input files.')
parser.add_argument('output_file', help='Path to save the output TSV file.')
parser.add_argument('--include-sense', action='store_true', help='Include sense genes count.')
parser.add_argument('--include-antisense', action='store_true', help='Include antisense genes count.')

# Parse the arguments
args = parser.parse_args()

# Initialize an empty list to store the results
results = []

# Process each input file
for file in args.input_files:
try:
# Load the file into a DataFrame
df = pd.read_csv(file, sep='\t', header=None, names=['Statistic', 'Count'])

# Extract required statistics
total_genes = df.loc[df['Statistic'] == 'Total number of genes', 'Count'].values[0]
overlapping_genes = df.loc[df['Statistic'] == 'Total number of overlapping genes', 'Count'].values[0]

# Optional statistics
sense_genes = df.loc[df['Statistic'] == 'Number of genes fully contained in sense direction', 'Count'].values[0] if args.include_sense else "NA"
antisense_genes = df.loc[df['Statistic'] == 'Number of genes fully contained in antisense direction', 'Count'].values[0] if args.include_antisense else "NA"
print(sense_genes)

# Collect results in a dictionary
entry = {
'File': file,
'Total_genes': total_genes,
'Overlapping_genes': overlapping_genes,
}
if args.include_sense:
entry['Fully_contained_sense_genes'] = sense_genes
if args.include_antisense:
entry['Fully_contained_antisense_genes'] = antisense_genes

results.append(entry)
except Exception as e:
print(f"Error processing {file}: {e}")
continue

# Convert the results to a DataFrame
columns = ['File', 'Total_genes', 'Overlapping_genes']
if args.include_sense:
columns.append('Fully_contained_sense_genes')
if args.include_antisense:
columns.append('Fully_contained_antisense_genes')

result_df = pd.DataFrame(results, columns=columns)

# Write the result to the output file
result_df.to_csv(args.output_file, sep='\t', index=False)
print(f"Extraction completed successfully. Output saved to {args.output_file}.")
Loading