This repository was archived by the owner on Nov 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 257
Join paired ends updates #1726
Open
mikerobeson
wants to merge
11
commits into
biocore:master
Choose a base branch
from
mikerobeson:join_paired_ends_updates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Join paired ends updates #1726
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
076e456
moving some join_paired_ends.py code for format.py, as well as associ…
3c515a1
moved function write_synced_barcodes_fastq to format.py
9f6c10f
updated join_paired_ends code with new skbio.io features, removed tes…
9aca821
forgot to add for last commit
1ae13da
removed unused imports in
bc75e97
added option to join_paired_ends.py. updated corresponding code in .
578693f
oops, for got to add
0fc2303
forgot to pass in `-q` option to `write_synced_barcodes_fastq` call a…
1fb5327
updated help text in
3d7e164
updated more code to skbio within test_format.py and format.py, also …
4473379
removed unnecessary comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ | |
| __author__ = "Rob Knight" | ||
| __copyright__ = "Copyright 2011, The QIIME Project" | ||
| __credits__ = ["Rob Knight", "Justin Kuczynski", "Jeremy Widmann", | ||
| "Antonio Gonzalez Pena", "Daniel McDonald", "Jai Ram Rideout"] | ||
| "Antonio Gonzalez Pena", "Daniel McDonald", "Jai Ram Rideout", | ||
| "Mike Robeson"] | ||
| # remember to add yourself if you make changes | ||
| __license__ = "GPL" | ||
| __version__ = "1.8.0-dev" | ||
|
|
@@ -14,13 +15,15 @@ | |
| from numpy import asarray, isnan, log10, median | ||
| from StringIO import StringIO | ||
| from re import compile, sub | ||
| from os import walk | ||
| from os import walk, path | ||
| from os.path import join, splitext, exists, isfile, abspath | ||
|
|
||
| from skbio.io import read | ||
| from skbio.sequence import BiologicalSequence | ||
| #from skbio.parse.sequences import parse_fastq | ||
| from biom.table import Table | ||
|
|
||
| from qiime.util import get_qiime_library_version, load_qiime_config | ||
| from qiime.util import get_qiime_library_version, load_qiime_config, qiime_open | ||
| from qiime.colors import data_color_hsv | ||
|
|
||
| """Contains formatters for the files we expect to encounter in 454 workflow. | ||
|
|
@@ -601,7 +604,8 @@ def write_Fasta_from_name_seq_pairs(name_seqs, fh): | |
| raise ValueError("Need open file handle to write to.") | ||
|
|
||
| for (name, seq) in name_seqs: | ||
| fh.write("%s\n" % BiologicalSequence(seq, id=name).to_fasta()) | ||
| #fh.write("%s\n" % BiologicalSequence(seq, id=name).to_fasta()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this comment |
||
| BiologicalSequence(seq, id=name).write(fh, format='fasta') | ||
|
|
||
|
|
||
| def illumina_data_to_fastq(record_data, number_of_bases=None): | ||
|
|
@@ -895,6 +899,68 @@ def format_fastq_record(label, | |
| return "@%s\n%s\n+\n%s\n" % (label, seq, qual) | ||
|
|
||
|
|
||
| def write_synced_barcodes_fastq(joined_fp, index_fp, qual_score_variant='illumina1.8'): | ||
| """Writes new index file based on surviving assembled paired-ends. | ||
| -joined_fp : file path to paired-end assembled fastq file | ||
| -index_fp : file path to index / barcode reads fastq file | ||
| -qual_score_variant : format of fastq quality scores. Can be | ||
| \'illumina1.3\' or \'illumina1.8\' | ||
|
|
||
| This function iterates through the joined reads file and index file. | ||
| Only those index-reads within the file at index_fp, that have headers | ||
| matching those within the joined-pairs at joined_fp, are written | ||
| to file. | ||
|
|
||
| Always forces output to be: illumina1.8 | ||
|
|
||
| WARNING: Assumes reads are in the same order in both files, | ||
| except for cases in which the corresponding | ||
| read in the joined_fp file is missing (i.e. pairs | ||
| failed to assemble). | ||
|
|
||
| """ | ||
|
|
||
| # open files (handles normal / gzipped data) | ||
| jh = qiime_open(joined_fp) | ||
| ih = qiime_open(index_fp) | ||
|
|
||
| # base new index file name on joined paired-end file name: | ||
| j_path, ext = path.splitext(joined_fp) | ||
| filtered_bc_outfile_path = j_path + '_barcodes.fastq' | ||
| fbc_fh = open(filtered_bc_outfile_path, 'w') | ||
|
|
||
| # Set up iterators | ||
| index_fastq_iter = read(ih, format='fastq', variant=qual_score_variant) | ||
| joined_fastq_iter = read(jh, format='fastq', variant=qual_score_variant) | ||
|
|
||
| # Write barcodes / index reads that we observed within | ||
| # the joined paired-ends. Warn if index and joined data | ||
| # are not in order. | ||
| for joined in joined_fastq_iter: | ||
| index = index_fastq_iter.next() | ||
| while joined.id != index.id: | ||
| try: | ||
| index = index_fastq_iter.next() | ||
| except StopIteration: | ||
| raise StopIteration("\n\nReached end of index-reads file" + | ||
| " before iterating through joined paired-end-reads file!" + | ||
| " Except for missing paired-end reads that did not survive" + | ||
| " assembly, your index and paired-end reads files must be in" + | ||
| " the same order! Also, check that the index-reads and" + | ||
| " paired-end reads have identical headers. The last joined" + | ||
| " paired-end ID processed was:\n\'%s\'\n" % (joined.id)) | ||
| else: | ||
| # force output to illumina1.8 | ||
| index.write(fbc_fh, format='fastq', variant='illumina1.8') | ||
|
|
||
| ih.close() | ||
| jh.close() | ||
| fbc_fh.close() | ||
|
|
||
| return filtered_bc_outfile_path | ||
|
|
||
|
|
||
|
|
||
| HTML_LINES_INIT = """<html> | ||
| <head> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment