Hello Everybody,
I just start Python3 and I block on a exercice about string.
I want to read a genbank file and make a string with all the gen found. At this moment I succed to recover every gen with a flag methodology. But, I have a new problem.
I suppress the digit with a online solution (from string import digits) but after this i have space and \n betwenn gen ;( So i would like to delet this space. I try with “”.join(mygenlist) but i did’nt work :0
If you have any solution tell my ^^
Next is my code :
from string import digits
# function for reading
def lit_genbank(nomfichier):
drapeau=False
lecture=""
table = str.maketrans('', '', digits) # table for digit suppression
with open(nomfichier, 'r') as filegbk: # open file
for ligne in filegbk: #read ligne by ligne
if ligne.find("//")!=-1: # if //
drapeau=False #flag false
if drapeau : # if flag true
# Here i delet digits
clarifier= ligne.translate(table)
lecture = lecture + clarifier.strip()
if ligne.find("ORIGIN")!=-1: # si on trouve origine
drapeau=True
return lecture
#
#Main
namefile="GenBank NC_001133.gbk"
seq=lit_genbank(namefile)
seq2= "".join(seq.split()) # dont work
print(seq2) # when i print that i have some space and .join don't work
For GENBANK file is somethings like that :
ORIGIN
1 ccacaccaca cccacacacc cacacaccac accacacacc acaccacacc cacacacaca
61 catcctaaca ctaccctaac acagccctaa tctaaccctg gccaacctgt ctctcaactt
121 accctccatt accctgcctc cactcgttac cctgtcccat tcaaccatac cactccgaac
181 caccatccat ccctctactt actaccactc acccaccgtt accctccaat tacccatatc
//
Result of this python is :
ccacaccaca cccacacacc cacacaccac accacacacc acaccacacc cacacacacacatcctaaca ctac
cctaac acagccctaa tctaaccctg gccaacctgt ctctcaacttaccctccatt accctgcctc cactcgtt
ac cctgtcccat tcaaccatac cactccgaaccaccatccat ccctctactt actaccactc acccaccgtt a