Mercurial > repos > davidvanzessen > shm_csr
diff shm_csr.py @ 96:385dea3c6cb5 draft
planemo upload commit 423a48569c69301fdbf893ac3a649128404dfff5
author | rhpvorderman |
---|---|
date | Fri, 05 Jan 2024 08:53:22 +0000 |
parents | 6809c63d9161 |
children |
line wrap: on
line diff
--- a/shm_csr.py Mon Mar 27 13:11:53 2023 +0000 +++ b/shm_csr.py Fri Jan 05 08:53:22 2024 +0000 @@ -2,13 +2,20 @@ import logging import sys import os +import traceback import typing from typing import Optional from collections import defaultdict -REGION_FILTERS = ("leader", "FR1", "CDR1", "FR2", "CDR2") +REGION_FILTERS = ("leader", "FR1", "CDR1", "FR2", "CDR2", "None") + +def int_or_zero(value: typing.Any): + try: + return int(value) + except ValueError: + return 0 class Mutation(typing.NamedTuple): """Represent a mutation type as a tuple""" @@ -177,15 +184,15 @@ mutationList += mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"] mutationListByID[ID] = mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"] - fr1Length = int(linesplt[fr1LengthIndex]) - fr2Length = int(linesplt[fr2LengthIndex]) - fr3Length = int(linesplt[fr3LengthIndex]) - cdr1Length = int(linesplt[cdr1LengthIndex]) - cdr2Length = int(linesplt[cdr2LengthIndex]) + fr1Length = int_or_zero(linesplt[fr1LengthIndex]) + fr2Length = int_or_zero(linesplt[fr2LengthIndex]) + fr3Length = int_or_zero(linesplt[fr3LengthIndex]) + cdr1Length = int_or_zero(linesplt[cdr1LengthIndex]) + cdr2Length = int_or_zero(linesplt[cdr2LengthIndex]) LengthDic[ID] = (fr1Length, cdr1Length, fr2Length, cdr2Length, fr3Length) - cdr1AALengthDic[ID] = int(linesplt[cdr1AALengthIndex]) - cdr2AALengthDic[ID] = int(linesplt[cdr2AALengthIndex]) + cdr1AALengthDic[ID] = int_or_zero(linesplt[cdr1AALengthIndex]) + cdr2AALengthDic[ID] = int_or_zero(linesplt[cdr2AALengthIndex]) IDlist += [ID] print("len(mutationdic) =", len(mutationdic)) @@ -222,6 +229,8 @@ # We determine the position to start summing below. # This returns 0 for leader, 1 for FR1 etc. length_start_pos = REGION_FILTERS.index(empty_region_filter) + if empty_region_filter == "None": + length_start_pos = 0 o.write("Sequence.ID\tnumber_of_mutations\tnumber_of_tandems\tregion_length\texpected_tandems\tlongest_tandem\ttandems\n") for ID in IDlist: