[Python] How do I join the sequences so I can make a dictionary? [closed]

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    In Python, am being asked to make a dictionary from whats in the string (FASTA Sequence), with the alphanumeric part (identifier) being the key and the letters (sequence) being the value. I was first asked to make a list of identifiers, so split the lines so I could isolate them. I now have no idea how to proceed in joining the elements of the sequence WITHOUT losing any part of the sequence or identifier. The sequence is not imported, it was posted as is by my professor, so please no suggestions about changing that. Can anyone help figure out what I should do? However, it should be EXTREMELY simple because I am only a couple weeks into taking a python course for school.

    I have tried using the join command in a for loop, but because I need it to update the list I am working with, I believe it doesn't work, as there is no output. However there is no error message either. I have tried replacing the new lines with nothing to join the elements that compose the sequence, but when it is time to separate it from the identifier, I am losing information (particularly the 1 and the first letter of sequence). I also have several new line characters within the sequence I need to get rid of as wellI cannot alter the original sequence in any way. I have attached my code but do not have anything currently for the task I am asking about, as I have had to start over.

    ESTs ='''>AA417440 1
    tattagcctttgtttcgtaatccttactgttaatggtttgttcaataccg
    tncttggattttttagccttttcaagtttcttttgaactttcgcaatttc
    agcatcaatatcaacgtgtcccttgacgagaagatgtacattgacttctg
    ggttaacagattgcaatacgcaaccttctggaatttcggaagcatcacga
    acaacagtgacttcgtcgatggccttgatcaacgagacaatagaatcttt
    ctgatcttcagcagnttggngnattcctcgtggttagattcaacgaaaac
    cttaccattcttcaaantattgttctcagataacaaggaacgagcttctt
    tggtantgttcaagancaagtcgtaagcattggtcgatttgacatcancg
    tnctcagatacgtaaactggataagaagctttttcaatngagggaggctt
    ctcaagtggaacgctttgggnagtcttttggcacatttcttccaga
    >AA417441 1
    ttagatcatttaatgacctcggagaactgttcctagaattactcctggaa
    ctactagcactgttgctagtggtattatttgctgtgcttgaatcaaaaat
    cctcaattttttcataaattggccgccaaagccagtattactagagccgt
    tgctattgctgtccaagaggtccttcaattcttcgttgtggagttcaatg
    aacgaacattttactacgtaatcgttctgttgtaggtccaatgtgtcaaa
    caacttcaaaagaaccctcggcattattcctgctggatcg
    >AA417442 1
    taagtaggttcaaatcaggcactgtcaaagaccgatgcatgatttgaagt
    cctcgctgatcaccattggcatagttctgaaatagggtttcggctgactt
    tacggagaaatatgaatgaatagatttaccaacaaagaacaaattggtta
    ccgcagatatcaaaagacaatagtataaagttttgttaacttttgaaaaa
    catttgaagataaccattaccattgccagtaaaactttcatggtcttaat
    gatgacactgcttaaataaaacacggtcaattttgtaaaaatttttgaaa
    gagacagaaaatcataattgatatatacaggttgcatgaaatcgccggcc
    tttncatcgttttctattctttcctttggtaaaacaccaaggaatccaca
    caatttaataacatcactcattttttctctatcgttgaatttttttagat
    attccctcgtctttcttgttaatttcagaatgtccaagtttacaatatct
    caaatgccagttgaggt
    >AA417443 1
    tatcacaattgcttttttgagaagccaaagagctgattggtgaggttgaa
    ggtgtccccacaccttcactttcgattcttctccttttatttggtaaggc
    ccacgtcgacgtatcgaatttgtgttttcttgtatccgaggaataatttt
    cacgtagaccatatggtacgtcactgctcctacttccagaacttctgctc
    tcaacgtcgctgttaccacttgcttctacttcagaaccatcaaaattgcg
    aggttcgtttttcacaaatgtgtgccataagtacttacctgagttccaaa
    gagtttctcttatgcctcctataaaaccagctttactagctctatctgac
    ccatctttcattgattcttccattgataaaacacggcgggcgtttaaata
    attgaatcttgacgtattggg
    '''

    #Converting the string to a list and removing the first empty index and new lines
    ESTlist= ESTs.splitlines()
    print(ESTlist) #used check that the last command worked

    #Creating list of definitions
    deflines = []
    for x in ESTlist:
    if ">" in x:
    deflines.append(x)

    print("Definition Lines:",deflines)

    #Creating dictionary from ESTlist


    I want the output to be:

    dictionary={ ('\>AA417440 1 ': 'tattagcctttgtttcgtaatccttactgttaatggtttgttcaataccg
    tncttggattttttagccttttcaagtttcttttgaactttcgcaatttcagcatcaatatcaacgtgtcccttgacgagaagatgtacattgacttctgggttaacagattgcaatacgcaaccttctggaatttcggaagcatcacgaacaacagtgacttcgtcgatggccttgatcaacgagacaatagaatctttctgatcttcagcagnttggngnattcctcgtggttagattcaacgaaaaccttaccattcttcaaantattgttctcagataacaaggaacgagcttctttggtantgttcaagancaagtcgtaagcattggtcgatttgacatcancgtnctcagatacgtaaactggataagaagctttttcaatngagggaggcttctcaagtggaacgctttgggnagtcttttggcacatttcttccaga',
    '\>AA417441 1' : 'ttagatcatttaatgacctcggagaactgttcctagaattactcctggaactactagcactgttgctagtggtattatttgctgtgcttgaatcaaaaatcctcaattttttcataaattggccgccaaagccagtattactagagccgttgctattgctgtccaagaggtccttcaattcttcgttgtggagttcaatgaacgaacattttactacgtaatcgttctgttgtaggtccaatgtgtcaaacaacttcaaaagaaccctcggcattattcctgctggatcg'
    ...}


    and so on.

    Continue reading...

Compartilhe esta Página