Question: You now have to write a function equivalent to build_dbGraph_from_string, which built a de Bruin graph from a single genomic string, now I have to
You now have to write a function equivalent to build_dbGraph_from_string, which built a de Bruin graph from a single genomic string, now I have to build a code from reads that are in FastQ format. The program we are using is python.
The prior code was:
def build_dbGraph_from_string(string, order): dbGraph = dict() for i in range(len(string) - (order-1)): kmer = string[i:i+order] dbGraph[kmer] = 1 return dbGraph
Then we built a graph from the reads in a FASTQ file. First, we implement the following function that gets the reads. We remove the new line character from the end of each line (with str.strip()), and for convention, we convert all characters in the reads to uppper case (with str.upper()).:
def get_reads(filePath): reads = list() # The list of strings that will store the reads (the DNA strings) in the FASTQ file at filePath fastqFile = open(filePath, 'r') fastqLines = fastqFile.readlines() fastqFile.close()
for lineIndex in range(1, len(fastqLines), 4): line = fastqLines[lineIndex] reads.append(line.strip().upper()) return reads
1. Could you explain the following part " for lineIndex in range(1, len(fastqLines), 4):" of the code above?
2. How do a write a working function equivalent to build_dbGraph_from_string but for reads?
This is what I'm working with:
def build_dbGraph_from_reads(reads, order): dbGraph = dict() # Your code here ... for i in range(len(reads) - (order-1)): kmer = reads[i:i+order] dbGraph[kmer] = 1 return dbGraph
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
