0
$\begingroup$

From the FASTA header I get the following information:

gi|1543850138|ref|NC_040192.1| Desmodium mottle virus isolate UG5 segment DNA-B, complete sequence
['gi', '1543850138', 'ref', 'NC_040192.1', ' Desmodium mottle virus isolate UG5 segment DNA-B, complete sequence']

Is there a better way to create a dictonary as I did with the below script?

from Bio import SeqIO

organismInfo = {}
for seq_record in SeqIO.parse("data/landplantsviruses.fasta","fasta"):
    print(seq_record.description)
    temp = seq_record.description.split('|')
    print(temp)
    organismID = temp[3]
    organismName = temp[4].lstrip()
    print(organismID, organismName)
    organismInfo[organismID] = organismName
print(organismInfo)
```
$\endgroup$

1 Answer 1

2
$\begingroup$

You may notice that Uniprot and NCBI have different standard: so your solution is not universal, which is why BioPython does not split the description for you —it could know different 'dialects' of fasta files but that is a tedious minefield.

About coding, one write something in a code golf format, but this is problematic as it is hard to interpret and adapt, i.e. it's a bad practice. Having said that if made a list of keys you could use zip with your list of elements as the list of keys may be more intelligible.

header = 'gi|1543850138|ref|NC_040192.1| Desmodium mottle virus isolate UG5 segment DNA-B, complete sequence'
keys = 'db|id|type|id2|wordy.'.split('|')
organism_info = dict( zip(keys, map(str.strip, header.split('|')) ))

Also, for variables in Python, camel case is for Classes, not instances. Even if you have to send data to JS, using a constistent style, i.e. the PIP guideline one, avoids errors.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.