This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Showing
2 changed files
with
69 additions
and
7 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 |
---|---|---|
@@ -1,9 +1,27 @@ | ||
""" | ||
Converting collapsed group.txt file into a .read_stat file that could be used to run IsoPhase later | ||
""" | ||
|
||
import os, sys | ||
|
||
f = open('dedup.5merge.collapsed.read_stat.txt', 'w') | ||
f.write("id\tpbid\tis_fl\tstat\n") | ||
for line in open('dedup.5merge.collapsed.group.txt'): | ||
a,b=line.strip().split() | ||
for x in set(b.split(',')): f.write(f"{x}\t{a}\tY\tunique\n") | ||
|
||
f.close() | ||
def main(group_filename, output_filename): | ||
f = open(output_filename, 'w') | ||
f.write("id\tpbid\tis_fl\tstat\n") | ||
for line in open(group_filename): | ||
a,b=line.strip().split() | ||
for x in set(b.split(',')): f.write(f"{x}\t{a}\tY\tunique\n") | ||
f.close() | ||
print(f"Output written to: {output_filename}") | ||
|
||
if __name__ == "__main__": | ||
from argparse import ArgumentParser | ||
parser = ArgumentParser() | ||
parser.add_argument("group_txt", help="Collapsed .group.txt to convert") | ||
parser.add_argument("output_txt", help="Output filename") | ||
|
||
args = parser.parse_args() | ||
if not os.path.exists(args.group_txt): | ||
print("Input .group.txt file {0} does not exist! Abort!".format(args.group_txt)) | ||
sys.exit(-1) | ||
|
||
main(args.group_txt, args.output_txt) |
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,44 @@ | ||
from csv import DictReader, DictWriter | ||
import gzip | ||
import os, sys | ||
|
||
def main(bc_info_csv, input_csv, output_csv): | ||
bc_info = {} # BC --> cell type | ||
reader = DictReader(open(bc_info_csv), delimiter=',') | ||
if 'BCrev' not in reader.fieldnames or 'Celltype' not in reader.fieldnames: | ||
print(f"ERROR: Expected 'BCrev' and 'Celltype' columns in {bc_info_csv}. Abort!") | ||
sys.exit(-1) | ||
for r in reader: | ||
bc_info[r['BCrev']] = r['Celltype'] | ||
|
||
reader = DictReader(gzip.open(input_csv, 'rt'), delimiter='\t') | ||
if 'BCrev' not in reader.fieldnames or 'id' not in reader.fieldnames: | ||
print(f"ERROR: Expected 'id' and 'BCrev' columns in {input_csv}. Abort!") | ||
sys.exit(-1) | ||
|
||
f = open(output_csv, 'w') | ||
writer = DictWriter(f, fieldnames=reader.fieldnames+['Celltype'], delimiter=',') | ||
writer.writeheader() | ||
for r in reader: | ||
if r['BCrev'] in bc_info: | ||
r['Celltype'] = bc_info[r['BCrev']] | ||
writer.writerow(r) | ||
f.close() | ||
print(f"Output written to: {output_csv}") | ||
|
||
if __name__ == "__main__": | ||
from argparse import ArgumentParser | ||
parser = ArgumentParser() | ||
parser.add_argument("bc_csv", help="Comma-delimited barcode to cell type information, must have 'BCrev' and 'Celltype' columns") | ||
parser.add_argument("annotated_csv", help="Tab-delimited annotated CSV file, gzipped, must have 'id' and 'BCrev' columns") | ||
parser.add_argument("output_csv", help="Output CSV filename") | ||
|
||
args = parser.parse_args() | ||
if not os.path.exists(args.bc_csv): | ||
print("Input file {0} does not exist! Abort!".format(args.bc_csv)) | ||
sys.exit(-1) | ||
if not os.path.exists(args.annotated_csv): | ||
print("Input file {0} does not exist! Abort!".format(args.annotated_csv)) | ||
sys.exit(-1) | ||
|
||
main(args.bc_csv, args.annotated_csv, args.output_csv) |