Skip to content

Commit 4b9b8cd

Browse files
authored
Merge pull request #77 from maxplanck-ie/dev_wd
RELACS plot
2 parents a94b92f + 4a2391c commit 4b9b8cd

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

BRB/demultiplex_relacs.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def checkDuplicatedLabels(data):
4949
for sample in data:
5050
num_bar += len(data[sample])
5151
for barcode in data[sample]:
52-
labels.add(data[sample][barcode])
52+
labels.add(data[sample][barcode][0])
5353
num_lab = len(labels)
5454

5555
if num_bar == num_lab:
@@ -71,13 +71,16 @@ def readSampleTable(sampleTable):
7171
elem = line.rstrip().split("\t")
7272
if len(elem) < 3:
7373
continue
74-
75-
sample, barcode, label = elem
74+
if len(elem) == 3:
75+
sample, barcode, label = elem
76+
bc_pos = ""
77+
elif len(elem) == 4:
78+
sample, bc_pos, barcode, label = elem
7679
# sanitize label
7780
label = label.replace(' ', '_')
7881
if sample not in d:
7982
d[sample] = dict()
80-
d[sample][barcode] = label
83+
d[sample][barcode] = [label, bc_pos]
8184

8285
if barcode != 'default' and len(barcode) > bcLen:
8386
bcLen = len(barcode)
@@ -261,6 +264,7 @@ def processSingle(args, sDict, bcLen, read1):
261264

262265
def wrapper(foo):
263266
d, args, sDict, bcLen, bc_dict = foo
267+
264268
print(f"Pool runner: sample {d} with bcLen {bcLen}")
265269
# Make the output directories
266270
try:
@@ -281,21 +285,21 @@ def wrapper(foo):
281285
oDict = dict()
282286
if R2 is not None:
283287
for k, v in sDict.items():
284-
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin,
285-
subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R2.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
288+
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin,
289+
subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R2.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
286290
if 'default' not in oDict:
287291
k = 'default'
288-
v = 'unknown'
289-
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin,
290-
subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R2.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
292+
v = ['unknown', '']
293+
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin,
294+
subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R2.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
291295
processPaired(args, oDict, bcLen, R1, R2, bc_dict, sDict)
292296
else:
293297
for k, v in sDict.items():
294-
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
298+
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
295299
if 'default' not in oDict:
296300
k = 'default'
297301
v = 'unknown'
298-
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
302+
oDict[k] = [subprocess.Popen(['gzip', '-c'], stdout=open('{}/{}/{}_R1.fastq.gz'.format(args.output, d, v[0]), "wb"), stdin=subprocess.PIPE, bufsize=0).stdin]
299303
processSingle(args, oDict, bcLen, R1)
300304
return bc_dict
301305

@@ -308,8 +312,11 @@ def plot_bc_occurance(R1, bc_dict, false_bc, output_path, sDict):
308312
x_ticks = ["false_bc"]
309313

310314
for k,v in sorted(bc_dict.items()):
311-
percentages.append(float(v/total_sum)*100)
312-
x_ticks.append(str(k) + '-' + sDict[str(k)])
315+
percentages.append(float(v/total_sum)*100)
316+
if sDict[str(k)][1] == '':
317+
x_ticks.append(str(k) + ' ' + sDict[str(k)][0])
318+
else:
319+
x_ticks.append(sDict[str(k)][1] + ' ' + sDict[str(k)][0])
313320

314321
percentages = np.asarray(percentages)
315322
bc_mean = np.mean(percentages[1:])

0 commit comments

Comments
 (0)