|
a |
|
b/singlecellmultiomics/modularDemultiplexer/demultiplexModules/Hexamer.py |
|
|
1 |
from singlecellmultiomics.modularDemultiplexer.baseDemultiplexMethods import DemultiplexingStrategy |
|
|
2 |
from singlecellmultiomics.modularDemultiplexer.baseDemultiplexMethods import NonMultiplexable |
|
|
3 |
from singlecellmultiomics.modularDemultiplexer.baseDemultiplexMethods import TaggedRecord |
|
|
4 |
from singlecellmultiomics.modularDemultiplexer.baseDemultiplexMethods import TagDefinitions |
|
|
5 |
|
|
|
6 |
|
|
|
7 |
# ask buys or annaa about it |
|
|
8 |
|
|
|
9 |
class HexamerBaseDemultiplexer(DemultiplexingStrategy): |
|
|
10 |
|
|
|
11 |
def __init__( |
|
|
12 |
self, |
|
|
13 |
indexFileParser, |
|
|
14 |
illuminaIndicesAlias='illumina_merged_iPCR_RP', |
|
|
15 |
**kwargs): |
|
|
16 |
self.barcodeFileParser = None |
|
|
17 |
DemultiplexingStrategy.__init__(self) |
|
|
18 |
self.indexFileParser = indexFileParser |
|
|
19 |
self.illuminaIndicesAlias = illuminaIndicesAlias |
|
|
20 |
self.shortName = 'HEX' |
|
|
21 |
self.longName = 'HexamersDemux' |
|
|
22 |
self.autoDetectable = False |
|
|
23 |
self.hexLength = 6 |
|
|
24 |
self.description = 'Demultiplex as a bulk sample and add hexamer H0..H3 tags' |
|
|
25 |
self.barcodeSummary = 'Bulk, no cell barcodes' |
|
|
26 |
self.indexSummary = f'sequencing indices: {illuminaIndicesAlias}' |
|
|
27 |
|
|
|
28 |
def demultiplex(self, records, library=None, **kwargs): |
|
|
29 |
global TagDefinitions |
|
|
30 |
|
|
|
31 |
try: |
|
|
32 |
h0 = records[0].sequence[:self.hexLength] |
|
|
33 |
h1 = records[0].qual[:self.hexLength] |
|
|
34 |
if len(records) > 1: |
|
|
35 |
h2 = records[1].sequence[:self.hexLength] |
|
|
36 |
h3 = records[1].qual[:self.hexLength] |
|
|
37 |
trs = [] |
|
|
38 |
for record in records: |
|
|
39 |
t = TaggedRecord( |
|
|
40 |
rawRecord=record, |
|
|
41 |
tagDefinitions=TagDefinitions, |
|
|
42 |
indexFileParser=self.indexFileParser, |
|
|
43 |
indexFileAlias=self.illuminaIndicesAlias, |
|
|
44 |
library=library) |
|
|
45 |
t.addTagByTag('H0', h0, isPhred=False) |
|
|
46 |
t.addTagByTag('H1', h1, isPhred=True) |
|
|
47 |
if len(records) > 1: |
|
|
48 |
t.addTagByTag('H2', h2, isPhred=False) |
|
|
49 |
t.addTagByTag('H3', h3, isPhred=True) |
|
|
50 |
trs.append( |
|
|
51 |
t.asFastq( |
|
|
52 |
record.sequence, |
|
|
53 |
record.plus, |
|
|
54 |
record.qual)) |
|
|
55 |
|
|
|
56 |
return trs |
|
|
57 |
|
|
|
58 |
except NonMultiplexable: |
|
|
59 |
raise |
|
|
60 |
except Exception as e: |
|
|
61 |
print(e) |