I am trying to answer the following question "A colleague has produced a file with one DNA sequence on each line. Download the file and load it into Python using numpy.loadtxt(). You will need to use the optional argument dtype=str to tell loadtxt() that the data is composed of strings.
Calculate the GC content of each sequence. The GC content is the percentage of bases that are either G or C (as a percentage of total base pairs). Print the result for each sequence as "The GC content of the sequence is XX.XX%" where XX.XX is the actual GC content. Do this using a "formatted strings". "
Having imported the file of dna sequences and joining these together I now want to split the string into 5 sequences (corresponding to each of the 5 rows) to then start the calculations...
NB: This is the file source: http://www.programmingforbiologists.org/data/dna_sequences_1.txt
This is my code:
import numpy
dna_data=numpy.loadtxt("dna_sequences",dtype=str)
",".join(dna_data)
seq1,seq2,seq3,seq4,seq5=dna_data.split(",",4)
I am getting this error message: AttributeError: 'numpy.ndarray' object has no attribute 'split'
Please help!!!
",".join(dna_data)in a variable that you split later on...but are you sure you need to join that if you're splitting it up in the next line? - Andras Deak