Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
v27.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Magdoll committed Aug 11, 2021
1 parent a33ee74 commit 328257b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
32 changes: 25 additions & 7 deletions phasing/utils/convert_group_to_read_stat_file.py
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)
44 changes: 44 additions & 0 deletions singlecell/link_molecule_to_celltype.py
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)

0 comments on commit 328257b

Please sign in to comment.