Skip to content

Commit

Permalink
make BC position finding optional
Browse files Browse the repository at this point in the history
  • Loading branch information
paulranum11 committed Jul 15, 2022
1 parent 3265ef9 commit 8713008
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions python_only_tool/DemultiplexUsingBarcodes_New_V2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
#parser.add_argument('-p', '--performanceMetrics', required=False, action='store_true', help='Provide -p flag to turn on performance metrics reporting', default=False)
#parser.add_argument('-t', '--readsPerCellThreshold', required=False, help='Provide a minimum reads per cell threshold for retaining a cell', default=1)
#parser.add_argument('-v', '--verbose', required=False, action='store_true', help='Provide -v flag to turn on verbose progress reporting for each bin', default=False)
#parser.add_argument('-k', '--positionDetection', required=True, type=bool, help='Use automated barcode position detection using flanking sequences')
#= parser.parse_)

def demultiplex_fun(inputFastqF, inputFastqR, outputDir, numReadsBin, errorThreshold, performanceMetrics, readsPerCellThreshold, verbose = False):
def demultiplex_fun(inputFastqF, inputFastqR, outputDir, numReadsBin, errorThreshold, performanceMetrics, readsPerCellThreshold, positionDetection, verbose = False):
#####
# Set consistent parameters here
Round1_barcode_staticSeq = "CATTCG"
Round2_barcode_staticSeq = "ATCCAC"
Round3_barcode_staticSeq = "GTGGCC"
if positionDetection == True:
Round1_barcode_staticSeq = "CATTCG"
Round2_barcode_staticSeq = "ATCCAC"
Round3_barcode_staticSeq = "GTGGCC"
#####

#####
Expand Down Expand Up @@ -147,53 +149,55 @@ def return_fastq(self):
######
# Learn barcode positions from input fastqR
######
print("Learning barcode positions...")

print("Using default barcode positions...")
print("Barcode position setting is " + str(positionDetection))
#Set Default Positions
umi_start=0
umi_end=10
barcode3_start=10
barcode3_end=18
barcode2_start=48
barcode2_end=int(48+8)
barcode3_start=86
barcode3_end=int(86+8)

# Code for automated barcode position extractor based on static sequences
line_ct_Learner = 0
learner_bc1_list = []
learner_bc2_list = []
learner_bc3_list = []
with open("position_learner_fastqr.fastq", "r") as infile:
for line in infile:
if (line_ct_Learner % 4 == 1):
if line.find(Round1_barcode_staticSeq) >= 17:
learner_bc1_list.append(line.find(Round1_barcode_staticSeq))
if line.find(Round2_barcode_staticSeq) >= 17:
learner_bc2_list.append(line.find(Round2_barcode_staticSeq))
if line.find(Round3_barcode_staticSeq) >= 17:
learner_bc3_list.append(line.find(Round3_barcode_staticSeq))
line_ct_Learner += 1
foundPosition_Round1_barcode=max(set(learner_bc1_list), key=learner_bc1_list.count)
foundPosition_Round2_barcode=max(set(learner_bc2_list), key=learner_bc2_list.count)
foundPosition_Round3_barcode=max(set(learner_bc3_list), key=learner_bc3_list.count)
print("Extracted position1 = " + str(foundPosition_Round1_barcode))
print("Extracted position2 = " + str(foundPosition_Round2_barcode))
print("Extracted position3 = " + str(foundPosition_Round3_barcode))
# Use extracted static sequence positions to infer barcode positions
umi_start=int(foundPosition_Round3_barcode - 18)
umi_end=int(foundPosition_Round3_barcode - 8)
print("UMI position has been extracted as " + str(umi_start) + ":" + str(umi_end))
barcode3_start=int(foundPosition_Round3_barcode - 8)
barcode3_end=int(foundPosition_Round3_barcode)
print("Barcode3 position has been extracted as " + str(barcode3_start) + ":" + str(barcode3_end))
barcode2_start=int(foundPosition_Round2_barcode - 8)
barcode2_end=int(foundPosition_Round2_barcode)
print("Barcode2 position has been extracted as " + str(barcode2_start) + ":" + str(barcode2_end))
barcode1_start=int(foundPosition_Round1_barcode + 6)
barcode1_end=int(foundPosition_Round1_barcode + 14)
print("Barcode1 position has been extracted as " + str(barcode1_start) + ":" + str(barcode1_end))

barcode1_start=86
barcode1_end=int(86+8)

if bool(positionDetection) == True:
print("Learning barcode positions to replace defaults...")
# Code for automated barcode position extractor based on static sequences
line_ct_Learner = 0
learner_bc1_list = []
learner_bc2_list = []
learner_bc3_list = []
with open("position_learner_fastqr.fastq", "r") as infile:
for line in infile:
if (line_ct_Learner % 4 == 1):
if line.find(Round1_barcode_staticSeq) >= 17:
learner_bc1_list.append(line.find(Round1_barcode_staticSeq))
if line.find(Round2_barcode_staticSeq) >= 17:
learner_bc2_list.append(line.find(Round2_barcode_staticSeq))
if line.find(Round3_barcode_staticSeq) >= 17:
learner_bc3_list.append(line.find(Round3_barcode_staticSeq))
line_ct_Learner += 1
foundPosition_Round1_barcode=max(set(learner_bc1_list), key=learner_bc1_list.count)
foundPosition_Round2_barcode=max(set(learner_bc2_list), key=learner_bc2_list.count)
foundPosition_Round3_barcode=max(set(learner_bc3_list), key=learner_bc3_list.count)
print("Extracted position1 = " + str(foundPosition_Round1_barcode))
print("Extracted position2 = " + str(foundPosition_Round2_barcode))
print("Extracted position3 = " + str(foundPosition_Round3_barcode))
# Use extracted static sequence positions to infer barcode positions
umi_start=int(foundPosition_Round3_barcode - 18)
umi_end=int(foundPosition_Round3_barcode - 8)
print("UMI position has been extracted as " + str(umi_start) + ":" + str(umi_end))
barcode3_start=int(foundPosition_Round3_barcode - 8)
barcode3_end=int(foundPosition_Round3_barcode)
print("Barcode3 position has been extracted as " + str(barcode3_start) + ":" + str(barcode3_end))
barcode2_start=int(foundPosition_Round2_barcode - 8)
barcode2_end=int(foundPosition_Round2_barcode)
print("Barcode2 position has been extracted as " + str(barcode2_start) + ":" + str(barcode2_end))
barcode1_start=int(foundPosition_Round1_barcode + 6)
barcode1_end=int(foundPosition_Round1_barcode + 14)
print("Barcode1 position has been extracted as " + str(barcode1_start) + ":" + str(barcode1_end))



######
Expand Down

0 comments on commit 8713008

Please sign in to comment.