Skip to content

Commit

Permalink
added the ability to read the reverse as the second column in the inp…
Browse files Browse the repository at this point in the history
…ut file as well as extending the previous try and except conditions
  • Loading branch information
jwcodee committed Oct 26, 2018
1 parent c7b0217 commit 3603aee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
30 changes: 26 additions & 4 deletions prince/match_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def check_file_exists(itr8tr):
first=next(itr8tr)
return(chain([first],itr8tr))

def compute_match_score(genome, templates, templateKmers, kmerLength):
def compute_match_score(genome, genome_reverse, templates, templateKmers, kmerLength):
try:
reads1 = check_file_exists(SeqIO.parse(genome + "1.fq", "fastq"))
reads2 = check_file_exists(SeqIO.parse(genome + "2.fq", "fastq"))
Expand All @@ -33,10 +33,32 @@ def compute_match_score(genome, templates, templateKmers, kmerLength):
reads2 = check_file_exists(SeqIO.parse(handle, "fastq"))
except:
try:
reads1 = check_file_exists(SeqIO.parse(genome, "fastq"))
reads2 = iter(())
with gzip.open(genome + "_1.fq.gz", "rt") as handle:
reads1 = check_file_exists(SeqIO.parse(handle, "fastq"))

with gzip.open(genome + "_2.fq.gz", "rt") as handle:
reads2 = check_file_exists(SeqIO.parse(handle, "fastq"))
except:
raise IOError("Can not open target file %s." % genome)
try:
if genome_reverse == "":
reads1 = check_file_exists(SeqIO.parse(genome, "fastq"))
reads2 = iter(())
else:
reads1 = check_file_exists(SeqIO.parse(genome, "fastq"))
reads2 = check_file_exists(SeqIO.parse(genome_reverse, "fastq"))
except:
try:
if genome_reverse == "":
with gzip.open(genome, "rt") as handle:
reads1 = check_file_exists(SeqIO.parse(handle, "fastq"))
reads2 = iter(())
else:
with gzip.open(genome, "rt") as handle:
reads1 = check_file_exists(SeqIO.parse(handle, "fastq"))
with gzip.open(genome_reverse, "rt") as handle:
reads2 = check_file_exists(SeqIO.parse(handle, "fastq"))
except:
raise IOError("Can not open target file %s." % genome)

#Run reads through Coarse Filtering to drastically reduce computation for Fine Filtering
nucleotides_seen,recruitedReads = coarse_filtering(chain(reads1,reads2), kmerLength, templateKmers)
Expand Down
11 changes: 8 additions & 3 deletions prince/query_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ def test_target(opts, templates,templateNames, templateKmers):
query = file.readline().strip("\n")
while query:
start_time = time.time()
targetFileName = query.split("/")[-1] #CHANGE
#add split on tab to deal with second column scenarios
targetFileName = query.split("\t")[0].split("/")[-1] #CHANGE
print("\nQuerying %s" % targetFileName)

targetMatchScore = compute_match_score(query, templates, templateKmers, opts.k)
query1 = query.split("\t")[0]
try:
query2 = query.split("\t")[1]
except:
query2 = ""
targetMatchScore = compute_match_score(query1, query2, templates, templateKmers, opts.k)

data = get_data(opts.boost_output)
equations = get_equations(data)
Expand Down

0 comments on commit 3603aee

Please sign in to comment.