|
a |
|
b/singlecellmultiomics/bamProcessing/bamPlateVisualisation.py |
|
|
1 |
#!/usr/bin/env python3 |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
from singlecellmultiomics.statistic import PlateStatistic |
|
|
4 |
import singlecellmultiomics.modularDemultiplexer |
|
|
5 |
import math |
|
|
6 |
import string |
|
|
7 |
import pandas as pd |
|
|
8 |
import matplotlib.pyplot as plt |
|
|
9 |
import numpy as np |
|
|
10 |
import os |
|
|
11 |
import sys |
|
|
12 |
import pysam |
|
|
13 |
import collections |
|
|
14 |
import argparse |
|
|
15 |
from singlecellmultiomics.tagtools import tagtools |
|
|
16 |
import pysamiterators.iterators as pysamIterators |
|
|
17 |
import gzip |
|
|
18 |
import pickle |
|
|
19 |
import subprocess |
|
|
20 |
|
|
|
21 |
import matplotlib |
|
|
22 |
import matplotlib.lines as mlines |
|
|
23 |
matplotlib.rcParams['figure.dpi'] = 160 |
|
|
24 |
matplotlib.use('Agg') |
|
|
25 |
TagDefinitions = singlecellmultiomics.modularDemultiplexer.TagDefinitions |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
if __name__ == '__main__': |
|
|
29 |
argparser = argparse.ArgumentParser( |
|
|
30 |
formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
|
|
31 |
description='Visualize single cell statistics on a plate plot') |
|
|
32 |
argparser.add_argument( |
|
|
33 |
'-o', |
|
|
34 |
type=str, |
|
|
35 |
help="output plot folder path, every library will be visualised as a separate plate", |
|
|
36 |
default='./plots/') |
|
|
37 |
|
|
|
38 |
argparser.add_argument('alignmentfiles', type=str, nargs='*') |
|
|
39 |
args = argparser.parse_args() |
|
|
40 |
|
|
|
41 |
if not os.path.exists(args.o): |
|
|
42 |
os.makedirs(args.o) |
|
|
43 |
|
|
|
44 |
ps = PlateStatistic(args) |
|
|
45 |
for alignmentFile in args.alignmentfiles: |
|
|
46 |
with pysam.AlignmentFile(alignmentFile) as f: |
|
|
47 |
for read in f: |
|
|
48 |
ps.processRead(read) |
|
|
49 |
|
|
|
50 |
ps.plot(args.o + '/PS') |