fastq-pair

Match up paired end fastq files quickly and efficiently.

https://github.com/linsalrob/fastq-pair

Science Score: 41.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Match up paired end fastq files quickly and efficiently.

Basic Info
Statistics
  • Stars: 150
  • Watchers: 4
  • Forks: 33
  • Open Issues: 7
  • Releases: 1
Created almost 9 years ago · Last pushed about 2 years ago
Metadata Files
Readme Changelog License Citation

README.md

Edwards Lab DOI Build Status

FASTQ PAIR

Rewrite paired end fastq files to make sure that all reads have a mate and to separate out singletons.

This code does one thing: it takes two fastq files, and generates four fastq files. That's right, for free it doubles the number of fastq files that you have!!

Usually when you get paired end read files you have two files with a /1 sequence in one and a /2 sequence in the other (or a /f and /r or just two reads with the same ID). However, often when working with files from a third party source (e.g. the SRA) there are different numbers of reads in each file (because some reads fail QC). Spades, bowtie2 and other tools break because they demand paired end files have the same number of reads.

This program solves that problem.

It rewrites the files with the sequences in order, with matching files for the two files provided on the command line, and then any single reads that are not matched are place in two separate files, one for each original file.

This code is designed to be fast and memory efficient, and works with large fastq files. It does not store the whole file in memory, but rather just stores the locations of each of the indices in the first file provided in memory.

Speed and efficiency considerations

The most efficient way to use this code is to provide the smallest file first (though it doesn't matter which way you provide the files), and then to manipulate the -t parameter on the command line. The code implementation is based on a hash table and the size of that table is the biggest way to make this code run faster. If you set the hash table size too low, then the data structure quickly fills up and the performance degrades to what we call O(n). On the other hand if you set the table size too big, then you waste a lot of memory, and it takes longer to initialize the data structures safely.

The optimal table size is basically somewhere around the number of sequences in your fastq files. You can quickly find out how many sequences there are in your fastq file:

wc -l fastq_filename The number of sequences will be the number printed here, divided by 4.

Note: If you get an error that looks like "We cannot allocate the memory for a table size of -436581356. Please try a smaller value for -t"

you are probably suffering from an integer overflow, so try reducing the value you are providing to the -t option. See issue 12 for more details.

If you are not sure, you can run this code with the -p parameter. Before it prints out the matched pairs of sequences, it will print out the number of sequences in each "bucket" in the table. If this number is more than about a dozen you need to increase the value you provide to -t. If most of the entries are zero, then you should decrease the size of -t.

As an aside, this code is also really slow if none of your sequences are paired. You should most likely use this after taking a peek at your files and making sure there are at least some paired sequences in your files!

Installing fastq_pair

We recommend installing fastq-pair using bioconda

mamba install -c bioconda fastq-pair

or in its own environment:

mamba create --name fastq-pair -c bioconda fastq-pair

Installing from source

To install the code, grab the github repository, then make a build directory: $xslt mkdir build && cd build cmake3 .. make && sudo make install There are more instructions on the installation page.

Running fastq_pair

fastq_pair takes two primary arguments. The name of the two fastq files that you want to pair up.

$xslt fastq_pair file1.fastq file2.fastq

You can also change the size of the hash table using the -t parameter:

$xslt fastq_pair -t 50021 file1.fastq file2.fastq

You can also print out the number of elements in each bucket using the -p parameter:

$xslt fastq_pair -p -t 100 file1.fastq file2.fastq

Testing fastq_pair

In the test directory there are two fastq files that you can use to test fastq_pair. There are 250 sequences in the left file and 75 sequences in the right file. Only 50 sequences are common between the two files.

You can test the code with:

$xslt fastq_pair -t 1000 test/left.fastq test/right.fastq

This will make four files in the test/ directory: - left.fastq.paired.fq - left.fastq.single.fq - right.fastq.paired.fq - right.fastq.single.fq

The paired files have 50 sequences each, and the two single files have 200 and 25 sequences (left and right respectively).

A note about gzipped fastq files

Unfortunately fastq_pair doesn't work with gzipped files at the moment, because it relies heavily on random access of the file stream. That is complex with gzipped files, especially when the uncompressed file exceeds available memory (which is exactly the situation that fastq_pair was designed to handle).

Therefore, at this time, fastq_pair does not support gzipped files. You need to uncompress the files before using fastq_pair.

If you really need to use gzipped files, and can accept slightly worse performance, then we have some alternative approaches written in Python that you can try.

Testing for gzipped files (issue #6)

We take a peek at the first couple of bytes in the file to see if the file is gzip compressed. Per the standard, the files should start 0x1F and 0x8B as the first two bytes. There is a small tester for the gzip program, called test_gzip.c, that takes a single argument and reports whether it is gzipped or not. You can compile that tester with the command:

gcc -std=gnu99 -o testgz ./test_gzip.c is_gzipped.c

We now test both files and exit (hopefully gracefully) if either is gzip compressed. The easiest solution is to uncompress your files, and we recommend and love pigz because it is awesome!

Citing fastq_pair

Please see the CITATION file for the current citation for fastq-pair

Owner

  • Name: Rob Edwards
  • Login: linsalrob
  • Kind: user
  • Location: Adelaide, Australia
  • Company: Flinders University

Professor of CS and Biology Writing bioinformatics code to study viruses, phages, and metagenomes.

Citation (CITATION.md)

# Citing fastq-pair

If you use fastq-pair, please cite: 

fastq-pair: efficient synchronization of paired-end fastq files. 2019. Robert A Edwards and John A Edwards. [bioRxiv 552885](https://www.biorxiv.org/content/10.1101/552885v1); doi: https://doi.org/10.1101/552885

```
@article {Edwards552885,
	author = {Edwards, Robert and Edwards, John A},
	title = {fastq-pair: efficient synchronization of paired-end fastq files},
	elocation-id = {552885},
	year = {2019},
	doi = {10.1101/552885},
	publisher = {Cold Spring Harbor Laboratory},
	abstract = {Paired end DNA sequencing provides additional information about the sequence data that is used in sequence assembly, mapping, and other downstream bioinformatics analysis. Paired end reads are usually provided as two fastq-format files, with each file representing one end of the read. Many commonly used downstream tools require that the sequence reads appear in each file in the same order, and reads that do not have a pair in the corresponding file are placed in a separate file of singletons. Although most sequencing instruments capable of generating paired end reads produce files where each read has a corresponding mate, many downstream bioinformatics manipulations break the one-to-one correspondence between reads, and paired-end sequence files loose synchronicity, and contain either unordered sequences or sequences in one or other file without a mate. Trivial solutions to this problem require reading one or both of the DNA sequence files into memory but quickly become limited by computational resources for moderate to large sized sequence files that are common nowadays. Here, we introduce a fast and memory efficient solution, written in C for portability, that synchronizes paired-end fastq files for subsequent analysis and places unmatched reads into singleton files. The application fastq-pair is freely available from https://github.com/linsalrob/fastq-pair and is released under the MIT license.},
	URL = {https://www.biorxiv.org/content/early/2019/02/19/552885},
	eprint = {https://www.biorxiv.org/content/early/2019/02/19/552885.full.pdf},
	journal = {bioRxiv}
}
```

GitHub Events

Total
  • Issues event: 2
  • Watch event: 12
  • Issue comment event: 1
  • Fork event: 1
Last Year
  • Issues event: 2
  • Watch event: 12
  • Issue comment event: 1
  • Fork event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 45
  • Total Committers: 2
  • Avg Commits per committer: 22.5
  • Development Distribution Score (DDS): 0.044
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Robert Edwards r****s@g****m 43
John Edwards j****0@g****m 2

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 24
  • Total pull requests: 3
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 20 days
  • Total issue authors: 20
  • Total pull request authors: 2
  • Average comments per issue: 1.92
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 2
  • Average time to close issues: about 2 months
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • bsiranosian (2)
  • tseemann (2)
  • linsalrob (1)
  • jemunro (1)
  • rezenman (1)
  • monsanto-pinheiro (1)
  • codecreatede (1)
  • vitorlimac2 (1)
  • MikeHala (1)
  • otradnaya (1)
  • mshpak76 (1)
  • rohitjainnference (1)
  • wshuai294 (1)
  • essere (1)
  • ysu2015 (1)
Pull Request Authors
  • f-huber (2)
  • johned0 (1)
Top Labels
Issue Labels
Pull Request Labels