Python: I Need Help With A Problem - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Python: I Need Help With A Problem (1407 Views)
| Python: I Need Help With A Problem by peacettw(op): 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(op): 9:03pm On Jan 09, 2021 |
Is noone here? |
| Re: Python: I Need Help With A Problem by peacettw(op): 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: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. |
| Re: Python: I Need Help With A Problem by peacettw(op): 8:28pm On Jan 10, 2021 |
ibromodzi: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: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(op): 10:23pm On Jan 10, 2021 |
ibromodzi:Thanks a lot |
| Re: Python: I Need Help With A Problem by ecomm(m): 10:31pm On Jan 10, 2021*. Modified: 9:50am On Jan 14, 2021 |
. |
| Re: Python: I Need Help With A Problem by zizytd(m): 11:33pm On Jan 10, 2021*. Modified: 12:11am On Jan 11, 2021 |
peacettw: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(op): 4:34am On Jan 11, 2021*. Modified: 5:03am On Jan 11, 2021 |
zizytd: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: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(op): 6:57am On Jan 11, 2021 |
ecomm: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(op): 7:05am On Jan 11, 2021 |
Starkid3010: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(op): 7:07am On Jan 11, 2021 |
Starkid3010: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: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: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: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. |
| Re: Python: I Need Help With A Problem by peacettw(op): 3:19am On Jan 12, 2021 |
Abcruz:Thanks a whole lot |
| Re: Python: I Need Help With A Problem by Abcruz(m): 8:32am On Jan 12, 2021 |
peacettw: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: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:wow! and this right here, is the beauty of coding with Python |
Developers For Hire.. We Are A Problem Solving Team.. Try Us • Help With A Problem Of Building A Network Intrusion detection system • 2 • 3 • 4
Where Can One Learn Ethical Hacking In Nsukka • React + Css Vs React + Tailwindcss Which Do You Prefer?? • Javafx For Gui Developer
