Seite 1 von 1

Vergleich zwischen nested lists

Verfasst: Donnerstag 12. November 2020, 13:36
von mit
I habe die foldgende Datei:

Code: Alles auswählen

    gene.100079.0.5.p3	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	84.9
    gene.100079.0.3.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	84.9
    gene.100079.0.0.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	86.7
    gene.100080.0.3.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	99.9
    gene.100080.0.0.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	99.9
    chr11_pilon3.g3568.t1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	74.9
    chr11_pilon3.g3568.t2	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	76.7

Die IDs sind sehr aehnlich

Code: Alles auswählen

    gene.100079.0.5.p3
    gene.100079.0.3.p1
    gene.100079.0.0.p1
Wenn nur `gene.100079` verbleibt die IDs sind identisch. Ich moechte die foldenden regeln anwenden:
  • `chr11_pilon3.g3568.t1 = 74.9` && `chr11_pilon3.g3568.t2 = 76.7`. `chr11_pilon3.g3568.t2` hat den höchsten Wert und deshalb soll es ausgegeben werden.
  • `gene.100079.0.0.p1 = 86.7` && `gene.100079.0.5.p3 = 84.9` == `gene.100079.0.3.p1 = 84.9`. `gene.100079.0.0.p1` hat den höchsten Wert und deshalb soll es ausgegeben werden.
  • `gene.100080.0.3.p1 = 99.9` == `gene.100080.0.0.p1 = 99.9`. Beide IDs sind identish und deshalb soll sie ausgegeben werden.
Leider der Vergleich funktioniert nicht in diesem code:

Code: Alles auswählen

from collections import defaultdict
blastStorage = defaultdict(list)

with open("data/blastp-bigcov.tsv") as blast_fn:
    for line in blast_fn:
        lineParts = line.rstrip().split('\t')
        print(lineParts)

        if lineParts[0].startswith("gene"):
            split_id = lineParts[0].split('.')
            tmp_id = split_id[0] + "." + split_id[1]
        else:
            tmp_id = lineParts[0]
        print(tmp_id)
        blastStorage[tmp_id].append(lineParts)

    for isoformID in blastStorage.keys():
        print("results2: "), max(blastStorage[isoformID], key=lambda x: x[12])
Als Ausgabe wuerde ich gerne haben:

Code: Alles auswählen

    chr11_pilon3.g3568.t1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	74.9
    chr11_pilon3.g3568.t2	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	76.7
    gene.100079.0.0.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	86.7
    gene.100080.0.3.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	99.9
    gene.100080.0.0.p1	transcript:OIS96097	82.2	169	30	0	1	169	4	172	1.3e-75	283.1	99.9