# Proch::N50 {version}
[![CPAN](https://img.shields.io/badge/CPAN-Proch::N50-1abc9c.svg)](https://metacpan.org/pod/Proch::N50)
[![Kwalitee](https://cpants.cpanauthors.org/release/PROCH/Proch-N50-{version}.svg)](https://cpants.cpanauthors.org/release/PROCH/Proch-N50-{version})
[![Version](https://img.shields.io/cpan/v/Proch-N50.svg)](https://metacpan.org/pod/Proch::N50)
[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/perl-fastx-reader/README.html)
[![Tests](https://img.shields.io/badge/Tests-Grid-1abc9c.svg)](https://www.cpantesters.org/distro/P/Proch-N50.html)

### A simple Perl module to calculate N50 of a FASTA or FASTQ file

The updated documentation is in the *[Meta::CPAN page](https://metacpan.org/pod/Proch::N50)*.

The module ships the **n50** program to calculate the N50 of FASTA/FASTQ files ([documentation](https://metacpan.org/pod/distribution/Proch-N50/bin/n50)).

### Installation

Via CPANminus:
```
#If you don't have 'cpanm' already installed:
curl -L http://cpanmin.us | perl - App::cpanminus

cpanm Proch::N50
```

Via Miniconda:

```
conda install -y -c bioconda n50
```

### Using the **n50** program

See more examples [in the CPAN page](https://metacpan.org/pod/distribution/Proch-N50/bin/n50).

```
# Will return only the N50 (useful for scripts)

n50 file.fasta

N50=$(n50 file.fasta)

n50 -x *.fasta

```


### Short synopsis of the module

```perl
use Proch::N50 qw(getStats getN50);
my $filepath = '/path/to/assembly.fasta';
 
# Get N50 only: getN50(file) will return an integer
print "N50 only:\t", getN50($filepath), "\n";
 
# Full stats
my $seq_stats = getStats($filepath);
print Data::Dumper->Dump( [ $seq_stats ], [ qw(*FASTA_stats) ] );
# Will print:
# %FASTA_stats = (
#               'N50' => 65,
#               'dirname' => 'data',
#               'size' => 130,
#               'seqs' => 6,
#               'filename' => 'small_test.fa',
#               'status' => 1
#             );
 
# Get also a JSON object
my $seq_stats_with_JSON = getStats($filepath, 'JSON');
print $seq_stats_with_JSON->{json}, "\n";
# Will print:
# {
#    "seqs" : 6,
#    "status" : 1,
#    "filename" : "small_test.fa",
#    "N50" : "65",
#    "dirname" : "data",
#    "size" : 130
# }
```
