-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucpen
committed
Oct 16, 2024
1 parent
6ab7468
commit ea64e43
Showing
2 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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,91 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import csv | ||
from pandas import read_csv, DataFrame | ||
|
||
SCRIPT_VERSION = "v1.0" | ||
|
||
|
||
def modify_gene_counts_df(df: DataFrame, col_name: str, run: bool, value_in: str): | ||
"""Modifies column col_name in df if run is true to make all | ||
rows equal value_in. If run is false it will make all rows NA""" | ||
if run: | ||
df[col_name] = value_in | ||
else: | ||
df[col_name] = "NA" | ||
return df | ||
|
||
|
||
def modify_and_write_sample_annotation( | ||
sample_annot: str, ae_run: bool, as_run: bool, gtf: str | ||
): | ||
""" | ||
Modifies and writes Sample Annotation produced by DROP to make one | ||
that can be used as input for Tomte | ||
""" | ||
df_samples: DataFrame = read_csv(sample_annot, sep="\t") | ||
df_samples["RNA_BAM_FILE"] = "NA" | ||
df_samples["GENE_ANNOTATION"] = df_samples["GENE_ANNOTATION"].fillna(gtf) | ||
df_samples = modify_gene_counts_df( | ||
df=df_samples, | ||
col_name="GENE_COUNTS_FILE", | ||
run=ae_run, | ||
value_in="exported_counts/geneCounts.tsv.gz", | ||
) | ||
df_samples = modify_gene_counts_df( | ||
df=df_samples, | ||
col_name="SPLICE_COUNTS_DIR", | ||
run=as_run, | ||
value_in="exported_counts", | ||
) | ||
df_samples.to_csv("exported_counts/sampleAnnotation.tsv", index=False, sep="\t") | ||
|
||
|
||
def parse_args(argv=None): | ||
"""Define and immediately parse command line arguments.""" | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.MetavarTypeHelpFormatter, | ||
description="""Generate DROP sample annotation for exported db.""", | ||
) | ||
parser.add_argument( | ||
"--sample_annot", | ||
type=str, | ||
help="original sample annotation in export_counts folder", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--ae_run", | ||
type=bool, | ||
help="Was aberrant expression run?", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--as_run", | ||
type=bool, | ||
help="Was aberrant splicing run?", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--gtf", | ||
type=str, | ||
help="Specify gtf file name used to run", | ||
required=True, | ||
) | ||
parser.add_argument("--version", action="version", version=SCRIPT_VERSION) | ||
return parser.parse_args(argv) | ||
|
||
|
||
def main(): | ||
"""Coordinate argument parsing and program execution.""" | ||
args = parse_args() | ||
modify_and_write_sample_annotation( | ||
sample_annot=args.sample_annot, | ||
ae_run=args.ae_run, | ||
as_run=args.as_run, | ||
gtf=args.gtf, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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