-
Notifications
You must be signed in to change notification settings - Fork 1
feat: rename transcript ids to gene names #141
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a2dc78
feat: rename transcript IDs of count data to gene names obtained from…
yeising af6adad
chore: update downstream diffexp to use new named input
yeising 5e6c27e
fix: updated script to remove gene name so transcript_ids match trans…
yeising 63afb3e
style: snakefmt reformatting
yeising bf4d7a4
chore: update rule all input with gnee named merged count data
yeising 03f3ab6
docs: elaborated script commentary
yeising 9d09ec3
feat: broadened gene name extraction by expanding attribute keys
yeising 8f790ff
style: snakefmt formatting
yeising cfde63d
feat: introduced missing id handling
yeising 8bf39bb
feat: adds warning and stats for report
yeising 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
yeising marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,72 @@ | ||
| import re | ||
| import sys | ||
| import pandas as pd | ||
|
|
||
| # Start logging | ||
| log_file = open(snakemake.log[0], "w") | ||
| sys.stderr = sys.stdout = log_file | ||
|
|
||
|
|
||
| counts = snakemake.input.all_counts | ||
| annotation = snakemake.input.annotation | ||
| output = snakemake.output[0] | ||
|
|
||
|
|
||
| # Load count data | ||
| counts = pd.read_csv(counts, sep="\t", dtype=str) | ||
|
|
||
|
|
||
| # Parse gff attributes into a {key: value} dictionairy | ||
| def parse_attributes(attr_str): | ||
| attrs = {} | ||
| for part in attr_str.strip().split(";"): | ||
| if "=" in part: | ||
| key, value = part.split("=", 1) | ||
| attrs[key] = value | ||
| return attrs | ||
|
|
||
|
|
||
| # Build mapping dictionairy {ID: gene} | ||
| # Parses gff line by line, extracts attributes field (9th), | ||
| # Includes entries that contain both "ID" and "gene" keys | ||
| id_to_gene = {} | ||
| with open(annotation) as gff: | ||
| for line in gff: | ||
| if line.startswith("#"): | ||
| continue | ||
| parts = line.strip().split("\t") | ||
yeising marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if len(parts) < 9: | ||
| continue | ||
| attrs = parse_attributes(parts[8]) | ||
| if "ID" in attrs and "gene" in attrs: | ||
| id_to_gene[attrs["ID"]] = attrs["gene"] | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Clean transcript ID from region-specific suffixes | ||
| # - "gene-Dmel_CR6900" matches directly within annotation | ||
| # - "rna-Dmel_CG34063_CDS=1-1024" must be cleaned first | ||
| # The pattern "_CDS=1-1024" is stripped before matching | ||
| def clean_id(raw_id): | ||
| return re.sub(r"_CDS=.*", "", raw_id) | ||
|
|
||
|
|
||
| # Map a transcript ID to its gene name | ||
| # Try exact match using transcript ID | ||
| # If not found, try using cleaned ID | ||
| # If still not found, return transcript ID as fallback | ||
| def map_id(original_ref): | ||
| clean_ref = clean_id(original_ref) | ||
| if original_ref in id_to_gene: | ||
| return f"{id_to_gene[original_ref]}::{original_ref}" | ||
| if clean_ref in id_to_gene: | ||
| return f"{id_to_gene[clean_ref]}::{original_ref}" | ||
| return original_ref | ||
|
|
||
|
|
||
| # Replace transcript IDs in "Reference" column with mapping results | ||
| counts["Reference"] = counts["Reference"].apply(map_id) | ||
|
|
||
yeising marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Write output | ||
| counts.to_csv(output, sep="\t", index=False) | ||
|
|
||
| log_file.close() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.