Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,143,313 members, 7,780,758 topics. Date: Thursday, 28 March 2024 at 09:22 PM

Python: I Need Help With A Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python: I Need Help With A Problem (895 Views)

Help With A Problem Of Building A Network Intrusion detection system / I Have Never Faced Such A Problem Before / Pls I Need To Solve A Problem Troubling Me (2) (3) (4)

(1) (Reply) (Go Down)

Python: I Need Help With A Problem by peacettw: 8:45pm On Jan 09, 2021
Ok. So I am currently going through an online course on DNA base pairing.

I decided to use python to help with the pairing. Essentially "A" should pair with "T" and "G" should pair with "C" and vise versa.

At the end of it all, I want a sequence of AAATTTGGGCCC to become TTT, AAA, CCC, GGG.

My issue is how to arrive at "TTT , AAA , CCC, GGG" as one string with python

Please look at the code below and let me know where I am getting it wrong. Thanks

dna=
"CCTGTATGCCCAAGGGGTTTCGATCGTAC
GACTGTCAGTCAGCTAGCT"

count =0
for i in dna:
count=count +1
print(i, end="" )
if count % 3 ==0:
print(", ", end="" )

The end result is not a single string, rather it's broken up... I can put them all together in a list with the append method but I just want a string and not a list.

PS: please ignore the lack of indentations where appropriate, for some reason this social platform is stripping all left spaces
Re: Python: I Need Help With A Problem by peacettw: 9:03pm On Jan 09, 2021
Is noone here?
Re: Python: I Need Help With A Problem by peacettw: 9:51pm On Jan 09, 2021
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
Re: Python: I Need Help With A Problem by ibromodzi: 7:29pm On Jan 10, 2021
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)

Use the code formatting tool next time you are seeking for help, it is not easy reading codes like a normal text. Computational Molecular Biology is an interesting domain by the way. Keep exploring bro.

1 Like

Re: Python: I Need Help With A Problem by peacettw: 8:28pm On Jan 10, 2021
ibromodzi:


Use the code formatting tool next time you are seeking for help, it is not easy reading codes like a normal text. Computational Molecular Biology is an interesting domain by the way. Keep exploring bro.

Ok. Thanks for the tips and I am female.. May I know where to access the code formatting tool?
Re: Python: I Need Help With A Problem by ibromodzi: 8:42pm On Jan 10, 2021
peacettw:


Ok. Thanks for the tips and I am female.. May I know where to access the code formatting tool?

Oh, sorry about that. Just click on the hash logo and insert your code there.

Re: Python: I Need Help With A Problem by peacettw: 10:23pm On Jan 10, 2021
ibromodzi:


Oh, sorry about that. Just click on the hash logo and insert your code there.




Thanks a lot

1 Like

Re: Python: I Need Help With A Problem by ecomm(m): 10:31pm On Jan 10, 2021
.
Re: Python: I Need Help With A Problem by zizytd(m): 11:33pm On Jan 10, 2021
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)

Look at the attached image after the print list(l), is it what you want?

you can also do it using for loop. it is shorter, see second attachment.

Re: Python: I Need Help With A Problem by peacettw: 4:34am On Jan 11, 2021
zizytd:


Look at the attached image after the print list(l), is it what you want?

you can also do it using for loop. it is shorter, see second attachment.

Perfect. Thanks a whole lot. Seems that I have so much to learn.

Is there like a community of python coders in Nigeria that I can join?
Re: Python: I Need Help With A Problem by Starkid3010(m): 6:18am On Jan 11, 2021
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
you can actually use another method for this... I am not familiar with this your method very well
Re: Python: I Need Help With A Problem by peacettw: 6:57am On Jan 11, 2021
ecomm:
tongue

rand_dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

dna = {'C': [], 'T': [], 'A': []}

for letter in rand_dna:
if letter == 'C':
dna['C'].append('C')


Just seeing this. Not quite what I wanted but thanks a lot for the effort.
Re: Python: I Need Help With A Problem by peacettw: 7:05am On Jan 11, 2021
Starkid3010:
you can actually use another method for this... I am not familiar with this your method very well

I understand. It can be quite tricky.. Take for instance my challenge. All I wanted was how to convert the contents of a list back to a string. Never knew that a string had a join() method until now.

Need to study more
Re: Python: I Need Help With A Problem by peacettw: 7:07am On Jan 11, 2021
Starkid3010:
you can actually use another method for this... I am not familiar with this your method very well

Oh. That's splendid. Can you tell us which other way this can also be addressed?
Re: Python: I Need Help With A Problem by zizytd(m): 8:12am On Jan 11, 2021
peacettw:


Perfect. Thanks a whole lot. Seems that I have so much to learn.

Is there like a community of python coders in Nigeria that I can join?

The more you practice the better you become. I don't have any idea about any community of python coders in Nigeria.
Re: Python: I Need Help With A Problem by Starkid3010(m): 9:54am On Jan 11, 2021
peacettw:


I understand. It can be quite tricky.. Take for instance my challenge. All I wanted was how to convert the contents of a list back to a string. Never knew that a string had a join() method until now.

Need to study more
yeah that's where I am driving at
Just ' '.join() will do it easily
I just started programming also
Re: Python: I Need Help With A Problem by Abcruz(m): 10:51pm On Jan 11, 2021
peacettw:


Oh. That's splendid. Can you tell us which other way this can also be addressed?

I used the BioPython package for DNA analysis and everything is simplified with it.
With BioPython, transcription and translation takes less than a line of code. You can install and learn it as well.

2 Likes

Re: Python: I Need Help With A Problem by peacettw: 3:19am On Jan 12, 2021
Abcruz:


I used the BioPython package for DNA analysis and everything is simplified with it.
With BioPython, transcription and translation takes less than a line of code. You can install and learn it as well.

Thanks a whole lot

1 Like

Re: Python: I Need Help With A Problem by Abcruz(m): 8:32am On Jan 12, 2021
peacettw:


Thanks a whole lot

You're welcome.
Re: Python: I Need Help With A Problem by trippleXXL(m): 12:02pm On Jan 12, 2021
Please can you recommend anywhere on Lagos Mainland where one can learn coding from beginner level.
Re: Python: I Need Help With A Problem by Stellar360(m): 9:09am On Jan 14, 2021
peacettw:
Never mind, I have figured it out
dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"
l=list() n= len(dna)/3 count=0
print(dna, "\n" ) while n>0: j=dna[count:count+3] count = count + 3 n= n - 1 l.append(j) print(j) print(l)
this is great, dear. guess i really have to return to python soon as possible.
Re: Python: I Need Help With A Problem by Stellar360(m): 9:10am On Jan 14, 2021
ecomm:
tongue
rand_dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"
dna = {'C': [], 'T': [], 'A': []}
for letter in rand_dna: if letter == 'C': dna['C'].append('C')
wow! and this right here, is the beauty of coding with Python

(1) (Reply)

I Want To Learn Web Development, How Do I Start? / Let's Build A Tech Ecosystem In Africa / Autocad.help !

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.