-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using Python to convert cluster files from wide to long for…
…mat (#76) * Create Python version of wide-to-long cluster file conversion Rscript * Call python version of script * Add permission to execute python script * Specify python3 * Update container used for tests
- Loading branch information
1 parent
72ffd49
commit d841ac3
Showing
3 changed files
with
32 additions
and
2 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
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
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,30 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import pandas as pd | ||
import csv | ||
|
||
# Parse command-line arguments | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-c", "--clusters-file", dest="clusters_path", help="Path to clusters file") | ||
parser.add_argument("-e", "--experiment-accession", dest="exp_acc", help="Experiment accession") | ||
parser.add_argument("-o", "--output", dest="output_path", help="Output file path") | ||
args = parser.parse_args() | ||
|
||
# Read clusters file | ||
clusters_wide = pd.read_csv(args.clusters_path, sep='\t', header=0, usecols=lambda x: x != "sel.K") | ||
|
||
# Reshape data from wide to long format | ||
clusters_long = pd.melt(clusters_wide, id_vars=['K'], var_name='cell_id', value_name='cluster_id') | ||
|
||
# Add experiment accession column | ||
clusters_long['experiment_accession'] = args.exp_acc | ||
|
||
# Rename 'K' column to 'k' | ||
clusters_long.rename(columns={'K': 'k'}, inplace=True) | ||
|
||
# Select and reorder columns | ||
columns = ['experiment_accession', 'cell_id', 'k', 'cluster_id'] | ||
|
||
# Write output to file | ||
clusters_long.to_csv(args.output_path, index=False, columns=columns, quoting=csv.QUOTE_NONNUMERIC) |