Scroll to navigation

MIRTOP(1) mirtop MIRTOP(1)

NAME

mirtop - mirtop Documentation

LOGO COMPETITION

Looking for a logo, enter the competition here. Deadline 07/07/2018. Win a t-shirt and stickers if your logo is selected!

We got a logo: https://github.com/miRTop/mirtop/tree/master/artwork # Installation

## bioconda

conda install mirtop -c bioconda

## pypi

pip install mirtop

## update to develop version from pip

` pip install --upgrade --no-deps git+https://github.com/miRTop/mirtop.git#egg=mirtop `

## install develop version

Thes best solution is to install conda to get an independent environment.

``
` wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh

bash Miniconda-latest-Linux-x86_64.sh -b -p ~/mirtop_env

export PATH=$PATH:~/mirtop_env

conda install -c bioconda bioconda bedtools samtools pip nose pysam pandas dateutil pyyaml pybedtools biopython setuptools

git clone http://github.com/miRTop/mirtop cd mirtop git fetch origin dev git checkout dev

python setup.py develop

``

`

# Quick Start

## Importer

### From Bam files to GFF3

` git clone mirtop cd mirtop/data `

You can use the example data. Here the reads have been mapped to the precursor sequences.

` mirtop gff -sps hsa --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 -o test_out sim_isomir.bam `

### From seqbuster::miraligner files to GFF3

miRNA annotation generated from [miraligner](https://github.com/lpantano/seqbuster) tool:

` mirtop gff --format seqbuster --sps hsa --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 -o test_out examples/seqbuster/reads.mirna `

### From sRNAbench files to GFF3

miRNA annotation generated from [sRNAbench](http://bioinfo2.ugr.es:8080/ceUGR/srnabench/) tool:

` mirtop gff --format sranbench -sps hsa --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 -o test_out srnabench examples/srnabench `

### From PROST! files to GFF3

miRNA annotation generated from [PROST!]() tool. Export isomiRs tab from excel file to a tabular text format file.

` mirtop gff --format prost -sps hsa --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 -o test_out examples/prost/prost.example.txt `

### From isomiR-SEA files to GFF3

miRNA annotation generated from [isomiR-SEA]() tool.

` mirtop validate examples/gff/correct_file.gff `

## Operations

### Validator

To validate your mirGFF3 file and make sure if follows the current format:

` mirtop gff --format isomirsea -sps hsa --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 -o test_out examples/isomir-sea/tagMir-all.gff `

### Get statistics from GFF

Get number of isomiRs and miRNAs annotated in the GFF file by isomiR category.

` cd mirtop/data mirtop stats -o test_out example/gff/correct_file.gff `

### Compare GFF file with reference

Compare the sequences from two or more GFF files. The first one will be used as the reference data.

` cd mirtop/data mirtop compare -o test_out example/gff/correct_file.gff example/gff/alternative.gff `

### Updates mirGFF3

Updates older versions with the most current one.

` cd mirtop/data mirtop update -o test_out_mirs examples/versions/version1.0.gff `

## Export

### Export file to isomiRs format

To be compatible with [isomiRs](https://bioconductor.org/packages/release/bioc/html/isomiRs.html) bioconductor package use:

` cd mirtop/data mirtop export -o test_out_mirs --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 examples/gff correct_file.gff `

### Export file to FASTA format

` cd mirtop/data mirtop export -o test_out_mirs --format fasta -d -vd --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 examples/gff/correct_file.gff `

### Export file to VCF format

` cd mirtop/data mirtop export -o test_out_mirs --format vcf --hairpin examples/annotate/hairpin.fa --gtf examples/a nnotate/hsa.gff3 examples/gff/correct_file.gff `

### Get count file

This file it is useful to load into R as a matrix. It contains the minimal information about each sequence and the count data in columns for each samples.

` cd mirtop/data mirtop counts -o test_out_mirs --hairpin examples/annotate/hairpin.fa --gtf examples/annotate/hsa.gff3 examples/synthetic/let7a-5p.gtf ` # Output

## GFF command

The mirtop gff generates the GFF3 adapter format to capture miRNA variations. The output is explained [here](https://github.com/miRTop/incubator/blob/master/format/definition.md).

## Stats command

The mirtop stats generates a table with different statistics for each type of isomiRs:

  • total counts
  • average counts
  • total sequences

It generates as well a JSON file with the same information to be integrated easily with QC tools like [MultiQC](https://multiqc.info/).

## Compare command

The mirtop compare generates a tabular file with information about the difference and similarities. The first file in the command line will be considered the reference and the following files will be compared to the reference. Each line of the output has the following information for each file:

  • sample
  • idu
  • seq
  • tag: E if not in reference, D detected in both, M missing in target file
  • same_mirna: if the sequence map to the same miRNA in the reference and target file
  • one column for each isomiR type with the following tags: FP (variation not in reference), TP (variation in both), FN (variation not in target file)

## Counts command

The mirtop counts generates a tabular file with the following columns:

  • unique identifier
  • read sequence
  • miRNA name
  • Variant attribute from GFF3 column
  • One column for each isomiR type showing the exact variation
  • One column for each sample with the counts for that sequence

## Export command

The mirtop export generates different files from a mirGFF3 file:


# Structure of the code
mirtop/bam * __bam.py__
read_bam: reads BAM files with pysamtools and store in a key - value object



__filter.py__ * tune: if option --clean is on, filter according generic rules * clean_hits: get the top hits

mirtop/gff * __init.py__ wraps the conversion process to GFF3 * __body.py__ create will create the line according GFF format established.
read_gff_line: Inside a for loop to read line of the file. It'll return and structure key:value dictionary for each column.



  • __header.py__ generate header and read header section.
  • __check.py__ checks header and single lines to be valid according GFF format (NOT IMPLEMENTED)
  • __stats.py__ GFF stats counting number of isomiR, their total and average expression
  • __query.py__ accept SQlite queries after option -q ""
  • __convert.py__ * create_counts table of counts * allow filtering by attribute * allow collapse by miRNA/isomiR type
  • __filter.py__, parse from query (NOT IMPLEMENTED)

mirtop/mirna * __fasta.py__:
read_precursor fasta file: key - value



  • __realign.py__: * hits: class that defines hits * isomir: class that defines each sequence * cigar_correction: function that use CIGAR to make sequence to miRNA alignemt * read_id and make_id: shorter ID for sequences * make_cigar: giving an alignment return the CIGAR of it * reverse_complement: return the reverse complement of a sequence * align: uses biopython to align two sequences of the same size * expand_cigar: from a 12M to MMMMMMMMMMMM * cigar2snp: from CIGAR code to list of changes with position and reference and target nts
  • __mapper.py__: * read_gtf file: map genomic miRNA position to precursos position, then it needs genomic position for the miRNA and the precursor. Return would be like {mirna: [start, end]}
  • __annotate.py__: * annotate: read isomiRs and populate all attributes related to isomiRs


  • seqbuster.py
  • prost.py
  • srnabench.py
  • isomirsea.py


isomirs.py: export file to match [isomiRs BioC package](https://github.com/lpantano/isomiRs).


data/examples/ * check gff files: example of correct, invalid, warning GFF files * check BAM file * check mapping from genome position to precursor position, example of +/- strand. Using mirtop/mirna/map.read_gtf. * check clean option: sequence mapping to multiple precursors/mirna, get the best score. Using mirtop/bam/filter.clean_hits.



To add new sub-commands, modify the following:

mirtop/lib/parse.py * query: TODO * transform: TODO * create: TODO * check: TODO

# Examples of contributions

## How to add a new sub-command

You need first to clone and install the tool in [develop mode](installation.html)

Let's say that you want to add a new operation to mirtop, for instance, similar to the stats command to work with sGFF3 files. Assume a test function for this example to just read the file and print Hello GFF3.

Create the folder inside mirtop/test. The create to empty files named:

  • test.py
  • __init__.py



Modify the test.py file with this content:

``
` from mirtop.gff.body import read_gff_line

import mirtop.libs.logger as mylog logger = mylog.getLogger(__name__)

_test(fn) logger.info("Hello GFF3: %s" % fn)

logger.debug("I am going to read this file: %s" % fn) for line in fn:
read_gff_line(line)



``

`


``
` def add_subparser_test(subparsers):
parser = subparsers.add_parser("test", help="test function") parser.add_argument("files", nargs="*", help="GFF/GTF files.") parser = _add_debug_option(parser) return parser


``

`

Add the function name to parse_cl function, at the end of the sub_cmds array.

``

    

`

"stats": add_subparser_stats, "compare": add_subparser_compare, "target": add_subparser_target, "simulator": add_subparser_simulator, "counts": add_subparser_counts, "export": add_subparser_export, "test": add_subparser_test }


``

`

To get the function re-directed from the command line when you use the sub_cmd name, add a line to the command_line.py file, adding another else statement:

``

    

`

elif "test" in kwargs: logger.info("Run test.") test(kwargs["args"])


``

`

The function you use to link to the operation added need to be imported at the beginning. Let's say that the test function is at mirtop/test/test.py:

` from mirtop.test import test `

Try the new operation:

` mirtop test data/examples/correct_file.gff `

## Add a unit test

## for the internal function

Add to the end of test/test_functions.py, but inside class FunctionsTest(unittest.TestCase): this code:

``

    

`

@attr(fn_test=True) def test_function_test(self):

from mirtop import test test._test("data/examples/gff/correct_file.gff")



``

`

## for the sub-command

Add to the end of test/test_function.py, but inside class AutomatedAnalysisTest(unittest.TestCase): this code:

``

    

`

@attr(cmd_test=True) def test_srnaseq_annotation_bam(self):

"""Run test analysis """ with make_workdir():
"test", "../../data/examples/gff/correct_file.gff"]

print("") print(" ".join(clcode)) subprocess.check_call(clcode)






``

`

## test the unit

nose is needed: pip install nose

Run the function test from the top parent folder:

` ./run_test.sh fn_test `

Run the command test from the top parent folder:

` ./run_test.sh cmd_test `

DOCUMENTATION FOR THE CODE

bam

Read bam files

Read bam file and perform realignment of hits
bam_fn: a BAM file with alignments to the precursor
being sequences. Come from mirtop.mirna.fasta.read_precursor().

clean: Use mirtop.filter.clean_hits() to remove lower score hits.

keys are read_id and values are mirtop.realign.hits



Select only best matches from a list of hits from the same read.
reads: dictionary as:

>>> {'read_id': mirtop.realign.hits, ...}
    

Returns:

reads: same than input but with best hits only.



The actual fn that will realign the sequence to find the nt changes at 5', 3' sequence and nt variations.
seq (str): sequence of the read.

precursor (str): sequence of the precursor.

start (int): start position of sequence on the precursor, +1.

cigar (str): similar to SAM CIGAR attribute.


Returns:

list with:
subs (list): substitutions

add (list): nt added to the end

cigar (str): updated cigar






exporter

Read GFF files and output isomiRs compatible format

Main function to convert from GFF3 to isomiRs Bioc Package.

Reads a GFF file to produces output file containing Expression counts

mirtop.libs.parse.add_subparser_counts().

UID miRNA Variant Sample1 Sample2 ... Sample N



Read GFF files and output FASTA format

Main function to convert from GFF3 to FASTA format.
See mirtop.libs.parse.add_subparser_export().



'cigar(str)': CIGAR standard of a compressed alignment representation, this CIGAR omits the '1' integer. 'readseq(str)': the read sequence 'refseq(str)': the reference sequence 'pos(str)': the start current position 'var5p(int)': extra nucleotides not in the reference miRNA (5p strand) 'var3p(int)': extra nucleotides not in the reference miRNA (3p strand) 'parent_ini_pos(int)': the start position of the parent miRNA 'parent_end_pos(int)': the last position of the parent miRNA 'hairpin(str)': the string of the hairpin for all the miRNA
'key_pos(str list)': a list with the positions of the variants. 'key_var(str list)': a list with the variant keys found. 'ref(str)': reference base(s). 'alt(str)': altered base(s).


Main function to convert from GFF3 to VCF.
See mirtop.libs.parse.add_subparser_export().



'mirgff3(str)': File with mirGFF3 format that will be converted 'precursor(str)': Fasta format sequences of all miRNA hairpins 'gtf(str)': Genome coordinates 'vcffile': name of the file to be saved
Nothing is returned, instead, a VCF file is generated


gff

GFF reader and creator helpers


and map the precursors coordinates to the genomic coordinates
line(str): string GFF line. mapper(dict): dict with mirna-precursor-genomic coordinas from
mirna.mapper.read_gtf_to_mirna function.


(line): string with GFF line with updated chr, star, end, strand


Create GFF/GTF line from read_gff_line

Read GTF/GFF file and load into annotate, chrom counts, sample, line

Read GFF/GTF line and return dictionary with fields

Read string in variants attribute.
attrb(str): string in Variant attribute.
(gff_dict): dictionary with:

>>> {'iso_3p': -3, ...}
    



Return nucleotides changes for each variant type using Variant attribute, precursor sequences and mature position.

Compare multiple GFF files to a reference

From a list of GFF files produce comparison with a reference set.
mirtop.libs.parse.add_subparser_compare(). First file will be considered the reference set.

(out_file): comparison of the GFF files with the reference.


Read GFF into UID:Variant
fn (str): GFF file.
srna (dict): dict with >>> {'UID': 'iso_snp:-2,...'}


Helpers to define the header fo the GFF file

Create header for GFF file.
samples (list): character list with names for samples

database (str): name of the database.

custom (str): extra lines.

filter (list): character list with filter definition.

header (str): header string.


Read samples from the header of a GFF file.
fn(str): GFF file to read.
(list): character list with sample names.


Extract mirGFF3 version

For dictionary with sample as keys and values as lines merge them into one GFF file.
dts(dict): dictionary as >>> {'file': {'mirna': {start: gff_list}}}. gff_list has the format as defined in mirtop.gff.body.read().

samples(list): character list with sample names.

merged_lines (nested dicts):gff_list has the format as defined in mirtop.gff.body.read().


Produce stats from GFF3 format

From a list of GFF files produce general isomiRs stats.
mirtop.libs.parse.add_subparser_stats().

(stdout) or (out_file): GFF general stats.


Update gff3 files to newest version

Update previous GFF3 versions.
mirtop.libs.parse.add_subparser_update().

(out_file): most updated GFF3 file.


Update file from file version to current version

Check GFF3 format.
mirtop.libs.parse.add_subparser_validator().

(std_out): warnings or errors of the files showing issues with the format.


importer

Read isomiR GFF files


Custom header for isomiR-SEA importer.
fn (str): file name with isomiR-SEA GFF output
(str): isomiR-SEA header string.


Read isomiR-SEA file and convert to mirtop GFF format.
fn(str): file name with isomiR-SEA output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

defined in mirtop.gff.body.read().



Read prost! files

Custom header for PROST! importer.
(str): PROST! header string.


Read PROST! file and convert to mirtop GFF format.
fn(str): file name with PROST output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

reads: dictionary where keys are read_id and values are mirtop.realign.hits


Read seqbuster files

Custom header for seqbuster importer.
(str): seqbuster header string.


Read seqbuster file and convert to mirtop GFF format.
fn(str): file name with seqbuster output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

reads: dictionary where keys are read_id and values are mirtop.realign.hits


Read sRNAbench files

Read sRNAbench file and convert to mirtop GFF format.
fn(str): file name with sRNAbench output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

defined in mirtop.gff.body.read().



Read isomiR GFF files from optimir tool

Read OptimiR file and convert to mirtop GFF format.
fn(str): file name with isomiR-SEA output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

defined in mirtop.gff.body.read().



Read Manatee files

Read Manatee file and convert to mirtop GFF format.
fn(str): file name with Manatee output information.

database(str): database name.

See mirtop.libs.parse.add_subparser_gff().

defined in mirtop.gff.body.read().



libs

Centralize running of external commands, providing logging and tracking. Integrated from bcbio package with some changes.

Find bash full path

Find command in session

Run the provided command, logging details and checking for errors.

Helpers to work with fastq files

txt, fq and fastq extensions understanding compression with gzip: .gzip and .gz (copy from bcbio)
in_file(str): file name.
(boolean): Yes or Not.


(from bcbio package)
in_file(str): file name.
(File): file handler.


(copy from bcbio)
fn(str): file name.
base, ext(str, str): basename and extension.


Function to parse the subcommands arguments.

utils from http://www.github.com/chapmanb/bcbio-nextgen.git

Change dir temporaly using with:

>>> with chdir(temporal):

do_something()

Check if a file exists and is non-empty.

Create folder if not exitsts

Remove file skipping

mirna

Read bam files

Using coordinates, mismatches and realign to annotate isomiRs
dict object that comes from mirotp.bam.bam.read_bam()
dict object that comers from mirtop.mirna.read_mature()
that comes from mirtop.mirna.fasta.read_precursor()
verbosity state

dictionary where keys are read_id and values are mirtop.realign.hits



Read precursor fasta file

Load precursor file for that species
precursor(str): file name with fasta sequences
It'll do a header_sequence.find(sps).

values are precursor sequences.



Read database information

GTF file with the miRNA and precursor coordinates to be able to parse BAM files with genomic coordinates.


Guess database name from GFF file.

database(str): name of the database

TODO: this needs to be generic to other databases.




Load GTF file with precursor positions on genome Return dict with key being precursor name and value a dict of mature miRNA with relative position to precursor.

map_dict(dict):

>>> {'parent': {mirna: [start, end]}}
    


Load GTF file with precursor positions on genome Return dict with key being precursor name and value a dict of mature miRNA with relative position to precursor. For miRBase and similar GFF3 files.

map_dict(dict):

>>> {'parent': {mirna: [start, end]}}
    


Load GTF file with precursor positions on genome Return dict with key being precursor name and value a dict of mature miRNA with relative position to precursor. For MirGeneDB and similar GFF3 files.

map_dict(dict):

>>> {'parent': {mirna: [start, end]}}
    


Pairwise alignments between two sequenes. https://medium.com/towards-data-science/pairwise-sequence-alignment-using-biopython-d1a9d0ba861f
x(str): short sequence.

y(str): long sequence.

local(boolean): local or global alignment.

aligned_x(hit): alignment information, socre and positions.


the mature from get_mature_sequence, and the variant GFF annotation: get a list of substitutions
sequence(str): read sequence.
mirtop.mirna.realing.get_mature_sequence().

variants(str): string from Variant attribute in GFF file.

snp(list): [[pos, target, reference]]


From a CIGAR string and reference sequence detect mistmatches positions and reference and target nucleotides.
cigar(str): CIGAR string.

reference(str): reference sequence.

snp(list): position of mismatches (indels included) as:

>>> [pos, seq_nt, ref_nt]
    


Read from CIGAR in BAM file to define mismatches.
cirgarLine(str): CIGAR string from BAM file.

query(str): read sequence.

target(str): target sequence.

(list): [query_nts, target_nts]


From short CIGAR version to long CIGAR version where each character is each nts in the sequence.
cigar(str): CIGAR string.

>>> 10MA3M
    
cigar_long(str): CIGAR long.

>>> MMMMMMMMMMAMMM
    


get mature sequence with +/- 4 flanking nts.
precursor(str): long sequence.

mature(list): [start, end].

exact(boolean): not add 4+/- flanking nts.

nt(int): number of nts to get.

(str): mature sequence.


"Class with alignment information.

This function check whether the sequence is valid or not.
seq(str): string acting as a sequence.
boolean: whether is or not a valid nucleotide sequence.


Class to represent isomiRs information.
Create tabular line from variant fields.

Create Variant attribute.

Create simple identifier from variant fields.

Get score from variant fields.

Define whether element is isomiR or not.



Function that will create CIGAR string from aligment between read and reference sequence.
seq(str): read sequence.

mature(str): short sequence.

short(str): CIGAR string.


Create a unique identifier for the sequence from the nucleotides, replacing 5 nts for a unique sequence.

It uses the code from mirtop.mirna.keys().

Inspired by MINTplate: https://cm.jefferson.edu/MINTbase https://github.com/TJU-CMC-Org/MINTmap/tree/master/MINTplates

seq(str): nucleotides sequences.
idName(str): unique identifier for the sequence.


Read a unique identifier for the sequence and convert it to the nucleotides, replacing an unique code for 5 nts.

It uses the code from mirtop.mirna.keys().

Inspired by MINTplate: https://cm.jefferson.edu/MINTbase https://github.com/TJU-CMC-Org/MINTmap/tree/master/MINTplates

idu(str): unique identifier for the sequence.
seq(str): nucleotides sequences.


Get reverse complement of a sequences
seq(str): sequence.

>>> GCAT
    
(str): reverse complemente sequence:

>>> ATGC
    


+/- indicated by iso_3p. Pos option is 0-base-index

position(int): >>> 3


(str): nucleotide involved in the variant:

>>> A
    



+/- indicated by iso_5p. Pos option is 0-base-index

position(int): >>> 3


(str): nucleotide involved in the variant:

>>> T
    



+/- indicated by iso_3p. Pos option is 0-base-index

position(int): >>> 3


(str): nucleotide involved in the variant:

>>> TT
    



Create vcf file of changes for all samples. PASS will be ones with > 3 isomiRs supporting the position and > 30% of reads, otherwise LOW

Make position at precursor scale

Liftover from precursor to genome

Print vcf line following rules.

classes

"Class with alignment information.

Class to represent isomiRs information.
Create tabular line from variant fields.

Create Variant attribute.

Create simple identifier from variant fields.

Get score from variant fields.

Define whether element is isomiR or not.



AUTHOR

Lorena Pantano, Thomas Desvignes, Karen EIlbeck, Ioannis Vlachos, Bastian Fromm, Marc K. Halushka, Michael Hackenberg, Gianvito Urgese

COPYRIGHT

2021, Lorena Pantano, Thomas Desvignes, Karen EIlbeck, Ioannis Vlachos, Bastian Fromm, Marc K. Halushka, Michael Hackenberg, Gianvito Urgese

June 30, 2021 0.3