def test_srnabench(self): """testing reading seqbuster files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.importer import srnabench annotate("data/examples/srnabench", srnabench.read_file, create=False)
def main(**kwargs): kwargs = parse_cl(sys.argv[1:]) initialize_logger(kwargs['args'].out, kwargs['args'].debug, kwargs['args'].print_debug) logger = mylog.getLogger(__name__) start = time.time() if "gff" in kwargs: logger.info("Run annotation") reader(kwargs["args"]) elif "stats" in kwargs: logger.info("Run stats.") stats(kwargs["args"]) elif "compare" in kwargs: logger.info("Run compare.") compare(kwargs["args"]) elif "simulator" in kwargs: logger.info("Run simulation") simulate(kwargs["args"]) elif "counts" in kwargs: logger.info("Run convert of GFF to TSV containing expression") convert_gff_counts(kwargs["args"]) elif "export" in kwargs: logger.info("Run export of GFF into other format.") isomirs.convert(kwargs["args"]) elif "validator" in kwargs: logger.info("Run validator.") validator.check_multiple(kwargs["args"]) elif "query" in kwargs["args"]: logger.info("Not yet ready: This will allow queries to GFF files.") logger.info('It took %.3f minutes' % ((time.time()-start)/60))
def main(**kwargs): kwargs = parse_cl(sys.argv[1:]) initialize_logger(kwargs['args'].out, kwargs['args'].debug, kwargs['args'].print_debug) logger = mylog.getLogger(__name__) start = time.time() if "gff" in kwargs: logger.info("Run annotation") reader(kwargs["args"]) elif "stats" in kwargs: logger.info("Run stats.") stats(kwargs["args"]) elif "compare" in kwargs: logger.info("Run compare.") compare(kwargs["args"]) elif "simulator" in kwargs: logger.info("Run simulation") simulate(kwargs["args"]) elif "counts" in kwargs: logger.info("Run convert of GFF to TSV containing expression") convert_gff_counts(kwargs["args"]) elif "export" in kwargs: logger.info("Run export of GFF into other format.") isomirs.convert(kwargs["args"]) elif "validator" in kwargs: logger.info("Run validator.") validator.check_multiple(kwargs["args"]) elif "query" in kwargs["args"]: logger.info("Not yet ready: This will allow queries to GFF files.") logger.info('It took %.3f minutes' % ((time.time() - start) / 60))
def test_collapse(self): """testing GFF function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.bam import bam bam_fn = "data/aligments/collapsing-isomirs.sam" annotate(bam_fn, bam.read_bam) return True
def test_optimir(self): """testing reading optimir files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.importer import optimir annotate("data/examples/optimir/synthetic_100_full.gff3", optimir.read_file, create=False)
def test_seqbuster(self): """testing reading seqbuster files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.importer import seqbuster print("\nperfect\n") annotate("data/examples/seqbuster/reads20.mirna", seqbuster.read_file) print("\naddition\n") annotate("data/examples/seqbuster/readsAdd.mirna", seqbuster.read_file)
def test_prost(self): """testing reading prost files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.mirna import fasta precursors = fasta.read_precursor("data/examples/annotate/hairpin.fa", "hsa") fn = "data/examples/prost/prost.example.txt" from mirtop.importer import prost reads = prost.read_file(fn, precursors, "miRBasev21", "data/examples/annotate/hsa.gff3") annotate("data/example/prost/prost.example.txt", reads, True)
def main(**kwargs): kwargs = parse_cl(sys.argv[1:]) initialize_logger(kwargs['args'].out, kwargs['args'].debug, kwargs['args'].print_debug) logger = mylog.getLogger(__name__) start = time.time() if "annotate" in kwargs: logger.info("Run annotation") mirna.miraligner(kwargs["args"]) elif "simulator" in kwargs: logger.info("Run simulation") simulate(kwargs["args"]) logger.info('It took %.3f minutes' % ((time.time() - start) / 60))
def test_prost(self): """testing reading prost files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.mirna import fasta precursors = fasta.read_precursor("data/examples/annotate/hairpin.fa", "hsa") fn = "data/examples/prost/prost.example.txt" from mirtop.importer import prost reads = prost.read_file( fn, precursors, "miRBasev21", "data/examples/annotate/hsa.gff3") annotate("data/example/prost/prost.example.txt", reads, True)
def test_counts(self): """testing convert_gff_counts in convert.py function""" from mirtop.libs import logger from mirtop.gff.convert import convert_gff_counts import argparse logger.initialize_logger("test counts", True, True) logger = logger.getLogger(__name__) args = argparse.Namespace() args.hairpin = "data/examples/annotate/hairpin.fa" args.sps = "hsa" args.gtf = "data/examples/annotate/hsa.gff3" args.gff = 'data/examples/synthetic/let7a-5p.gtf' args.out = 'data/examples/synthetic' args.add_extra = True convert_gff_counts(args) os.remove(os.path.join(args.out, "expression_counts.tsv")) return True
def main(**kwargs): kwargs = parse_cl(sys.argv[1:]) initialize_logger(kwargs['args'].out, kwargs['args'].debug, kwargs['args'].print_debug) logger = mylog.getLogger(__name__) start = time.time() if "gff" in kwargs: logger.info("Run annotation") reader(kwargs["args"]) elif "simulator" in kwargs: logger.info("Run simulation") simulate(kwargs["args"]) elif "check" in kwargs["args"]: logger.info("Not yet ready: This will check GFF files.") elif "query" in kwargs["args"]: logger.info("Not yet ready: This will allow queries to GFF files.") elif "convert" in kwargs["args"]: logger.info( "Not yet ready: This will output tabular format from GFF files.") logger.info('It took %.3f minutes' % ((time.time() - start) / 60))
def test_alignment(self): """testing alignments function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.mirna import fasta, mapper precursors = fasta.read_precursor("data/examples/annotate/hairpin.fa", "hsa") matures = mapper.read_gtf_to_precursor( "data/examples/annotate/hsa.gff3") # matures = mirtop.mirna.read_mature("data/examples/annotate/mirnas.gff", "hsa") def annotate(fn, precursors, matures): from mirtop.bam import bam from mirtop.gff import body reads = bam.read_bam(fn, precursors) ann = bam.annotate(reads, matures, precursors) gff = body.create(ann, "miRBase21", "example", fn + ".gff3", "#") print "\nlast1D\n" annotate("data/aligments/let7-last1D.sam", precursors, matures) #mirna TGAGGTAGTAGGTTGTATAGTT #seq AGAGGTAGTAGGTTGTA print "\n1D\n" annotate("data/aligments/let7-1D.sam", precursors, matures) #mirna TGAGGTAG-TAGGTTGTATAGTT #seq TGAGGTAGGTAGGTTGTATAGTTA print "\nlast7M1I\n" annotate("data/aligments/let7-last7M1I.sam", precursors, matures) #mirna TGAGGTAGTAGGTTGTATAGTT #seq TGAGGTAGTAGGTTGTA-AGT print "\nmiddle1D\n" annotate("data/aligments/let7-middle1D.sam", precursors, matures) #mirna TGAGGTAGTAGGTTGTATAGTT #seq TGAGGTAGTAGGTTGTATAGTT print "\nperfect\n" annotate("data/aligments/let7-perfect.sam", precursors, matures) #mirna TGAGGTAGTAGGTTGTATAGTT #seq TGAGGTAGTAGGTTGTATAG (3tt 3TT) print "\ntriming\n" annotate("data/aligments/let7-triming.sam", precursors, matures)
def test_srnabench(self): """testing reading seqbuster files function""" from mirtop.libs import logger logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) from mirtop.mirna import fasta, mapper precursors = fasta.read_precursor("data/examples/annotate/hairpin.fa", "hsa") matures = mapper.read_gtf_to_precursor( "data/examples/annotate/hsa.gff3") def annotate(fn, precursors, matures): from mirtop.importer import srnabench from mirtop.bam import bam reads = srnabench.read_file(fn, precursors) ann = bam.annotate(reads, matures, precursors) return True print "\nsRNAbench\n" annotate("data/examples/srnabench/reads.annotation", precursors, matures)
def test_collapse(self): """testing GFF function""" from mirtop.libs import logger from mirtop.mirna import mapper, fasta from mirtop.gff import body, header logger.initialize_logger("test", True, True) logger = logger.getLogger(__name__) precursors = fasta.read_precursor("data/examples/annotate/hairpin.fa", "hsa") # depend on https://github.com/miRTop/mirtop/issues/6 matures = mapper.read_gtf_to_precursor( "data/examples/annotate/hsa.gff3") # matures = mirtop.mirna.read_mature("data/examples/annotate/mirnas.gff", "hsa") from mirtop.bam import bam bam_fn = "data/aligments/collapsing-isomirs.sam" reads = bam.read_bam(bam_fn, precursors) ann = bam.annotate(reads, matures, precursors) fn = bam_fn + ".gff" h = header.create(bam_fn, ["example"], "miRBase21") gff = body.create(ann, "miRBase21", "example", fn, header) print gff return True
import mirtop.libs.logger as mylog logger = mylog.getLogger(__name__) def create(reads, database, sample, fn, header): """Read https://github.com/miRTop/mirtop/issues/9""" seen = set() lines = [] seen_ann = {} # print >>out_handle, "seq\tname\tfreq\tchrom\tstart\tend\tmism\tadd\tt5\tt3\ts5\ts3\tDB\tprecursor\tambiguity\tName" out_handle = open(fn, 'w') print >> out_handle, header filter_precursor = 0 filter_score = 0 for r, read in reads.iteritems(): hits = set() [ hits.add(mature.mirna) for mature in read.precursors.values() if mature.mirna ] hits = len(hits) for p, iso in read.precursors.iteritems(): if len(iso.subs) > 3 or not iso.mirna: continue filter_precursor += 1 if (r, iso.mirna) not in seen: seen.add((r, iso.mirna)) chrom = iso.mirna if not chrom: chrom = p # count = _get_freq(r)
from Bio import pairwise2 from Bio.Seq import Seq from collections import defaultdict from mirtop.mirna.keys import CODE2NT, NT2CODE import mirtop.libs.logger as mylog logger = mylog.getLogger(__name__) class hits: """"Class with alignment information.""" def __init__(self): self.sequence = "" self.idseq = "" self.precursors = defaultdict(isomir) self.score = [] self.best_hits = [] # maybe sam object? self.counts = 0 def set_sequence(self, seq): self.sequence = seq self.idseq = make_id(seq) def set_precursor(self, precursor, isomir): self.precursors[precursor] = isomir def remove_precursor(self, precursor): del self.precursors[precursor]