Example #1
0
def umi_visualization(bams, chrom, start, end, output, coor):
    doc = genomeview.Document(1000)
    global umi_colors
    umi_colors = {}
    # genome
    source = genomeview.FastaGenomeSource(REF_FA)
    gv = genomeview.GenomeView(chrom, max(0, start), end, "+", source)
    axis = genomeview.Axis()
    gv.add_track(axis)
    label_track = genomeview.track.TrackLabel('{}:{}-{}'.format(
        chrom, start, end))
    gv.tracks.insert(0, label_track)
    for bam in bams:
        # VCF/BAM track
        name = bam.split('/')[-1]
        if bam[-7:] == '.vcf.gz':  # VCF track
            variant_track = VCFTrack(bam, name, chrom, start, end)
            gv.add_track(variant_track)
        else:  # bam track
            track = genomeview.PairedEndBAMTrack(bam, name=name)
            #track = genomeview.SingleEndBAMTrack(bam, name=name)
            gv.add_track(track)
            track.nuc_colors = {
                "A": "blue",
                "C": "orange",
                "G": "green",
                "T": "black",
                "N": "gray"
            }
            track.quick_consensus = False
            # format
            global count, colors
            count, frag_draw, umi_draw, umi_all, any_umi = stats_umi(
                bam, chrom, start, end)

            if len(coor.split(':')) == 3:
                colors = ColorIter(umi_draw)  # color generater
                umi_ar = list(count.keys())
                for umi in umi_ar:
                    umi_n = count[umi]
                    if umi_n > 1 and umi not in umi_colors:
                        umi_colors[umi] = colors.next_color()
                track.color_fn = color_by_umi
                track.include_read_fn = filter_by_umi  # exculde reads out of
            else:
                colors = ColorIter(len(any_umi))  # color generater
                for umi in any_umi:
                    umi_colors[umi] = colors.next_color()
                track.include_read_fn = filter_by_coor  # exculde reads out of
                track.color_fn = color_by_umi
                #track.color_fn = lambda x: "lightgray"
    doc.elements.append(gv)
    genomeview.save(doc, '{}.svg'.format(output))
Example #2
0
def test_view_without_source():
    import genomeview

    doc = genomeview.Document(900)
    
    view = genomeview.GenomeView("chr4", 96549060, 96549060+1000, "+")
    doc.add_view(view)

    bam_track_hg002 = genomeview.SingleEndBAMTrack("data/quick_consensus_test.bam", name="HG002")
    bam_track_hg002.draw_mismatches = False
    view.add_track(bam_track_hg002)

    axis_track = genomeview.Axis()
    view.add_track(axis_track)

    genomeview.save(doc, "results/temp_without_source.svg")


    with pytest.raises(AssertionError):
        bam_track_hg002.draw_mismatches = True
        genomeview.save(doc, "results/temp_without_source_error.svg")
Example #3
0
import genomeview

dataset_paths = [
    "data/pacbio.chr1.bam", "data/illumina.chr1.bam",
    "/Users/nspies/Downloads/hg19.refseq.sorted.bed.gz"
]
reference = "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz"

chrom = "chr1"
start = 224368899
end = 224398899

doc = genomeview.visualize_data(dataset_paths, chrom, start, end, reference)

genomeview.save(doc, "example.svg")

# import genomeview.track

# chrom = "14"
# start = 66901400

# genome_path = "data/chr14.fa"

# doc = genomeview.Document(950)
# source = genomeview.FastaGenomeSource(genome_path)

# gv = genomeview.genomeview.GenomeView("bam", chrom, start, start+10000, "+", source)

# # Add the coordinate axis at the top
# axis = genomeview.axis.Axis("axis")
# gv.add_track(axis)
Example #4
0
def test_bed():
    file_paths = ["data/genes.sorted.bed.gz"]

    doc = genomeview.visualize_data(file_paths, "chr3", 179500230, 179800230)
    genomeview.save(doc, "results/bed_view.svg")
Example #5
0
def test_bed2(which_bed):
    file_paths = ["data/{}.bed".format(which_bed)]

    doc = genomeview.visualize_data(file_paths, "chr3", 179500230, 179800230)
    genomeview.save(doc, "results/{}_view.svg".format(which_bed))
Example #6
0
def test_arrows(reference_path):
    for i in [100, 1000, 2000, 5000]:
        print(i)
        doc = genomeview.visualize_data(["data/illumina.bam"], "chr4", 96549060, 96549060+i, reference_path)
        genomeview.save(doc, "results/temp_{}.png".format(i))
Example #7
0
def test_export_to_png(bam_doc):
    genomeview.save(bam_doc, "results/temp.png")
Example #8
0
def test_save_to_svg(bam_doc):
    genomeview.save(bam_doc, "results/temp.svg")