I have code which is given below:
for pileupcolumn in samfile.pileup(max_depth = 1000000) :
X.append(pileupcolumn.n)
for pileupread in pileupcolumn.pileups:
if (pileupread.alignment.mapping_quality <= 15):
continue
if not pileupread.is_del and not pileupread.is_refskip:
if pileupread.alignment.query_qualities[pileupread.query_position] < 30:
# Skip entries with base phred scores < 10
continue
if pileupread.alignment.is_reverse: #negative
ReverseList[pileupcolumn.pos] += pileupread.alignment.query_sequence[pileupread.query_position]
else:
ForwardList[pileupcolumn.pos] += pileupread.alignment.query_sequence[pileupread.query_position]
The above code is taking a lot of time and I want to replace concatenation in the 11th and 13th line with join. Is there any way to do so?
Instead of concatenating, collect the values into a list, then join the list at the end of the loop.
I still use concatenation at the end, because this optimization only works for the
for pileupreadloop. If differentpileupcolumnobjects have the samepos, we need to concatenate at that point. We also need this concatenation if theReverseListelements already have values before this code runs.