def plot_plasmid_features( plasmid_length: int, features: List[Dict[str, Any]], figure_width: int = 5, palette: Optional[Palette] = None, ) -> Tuple[SubplotBase, Tuple[Any, Any]]: """Plots features in a circular dna sequence. Args: plasmid_length (int): Number of nucleotide bases of the plasmid sequence features (List[Dict[str, Any]]): Features as obtained from TeselaGen DNA Sequence object figure_width (int, optional): Width size of figure. Defaults to 5. palette (Optional[Palette], optional): A SecretColors color palette. \ Defaults to None, meaning `Palette("material")` will be used. Returns: Tuple[AxesSubplot, Tuple[Any, Any]]: Axes and a tuple with Graphic features data """ # Define random color palette if palette is None: palette = Palette("material") colors = palette.cycle() # From 'forward' create a 'strand' field if does not exist if 'strand' not in features[0]: features = deepcopy(features) for feat in features: feat.update({'strand': 1 * feat['forward']}) # Create feat objects plot_feats = [ GraphicFeature( start=feat['start'], end=feat['end'], strand=feat['strand'], label=feat['name'], color=next(colors), ) for i, feat in enumerate(features) ] # Make graphic record and plot record = CircularGraphicRecord(sequence_length=plasmid_length, features=plot_feats) ax, _ = record.plot(figure_width=figure_width) # return ax, (features_levels, labels_data) return record.plot(ax)
def draw_by_dfv(): from dna_features_viewer import GraphicFeature, CircularGraphicRecord import matplotlib.pyplot as plt _feat = lambda name, it: GraphicFeature(it[0], it[1], +1, name) features = [_feat(name, it) for name, it in zip(names, intervals)] record = CircularGraphicRecord(phase_1 + phase_2, features) import ipdb ipdb.set_trace()
def test_by_hand(tmpdir): """Test building a GraphicRecord "by hand" """ features = [ GraphicFeature(start=5, end=20, strand=+1, color="#ffd700", label="Small feature"), GraphicFeature( start=20, end=500, strand=+1, color="#ffcccc", label="Gene 1 with a very long name", ), GraphicFeature(start=400, end=700, strand=-1, color="#cffccc", label="Gene 2"), GraphicFeature(start=600, end=900, strand=+1, color="#ccccff", label="Gene 3"), ] # PLOT AND EXPORT A LINEAR VIEW OF THE CONSTRUCT record = GraphicRecord(sequence_length=1000, features=features) record.plot(figure_width=5, with_ruler=False) # lazy, just for coverage ax, _ = record.plot(figure_width=5) target_file = os.path.join(str(tmpdir), "by_hand.png") ax.figure.savefig(target_file) # PLOT AND EXPORT A CIRCULAR VIEW OF THE CONSTRUCT circular_rec = CircularGraphicRecord(sequence_length=1000, features=features) ax2, _ = circular_rec.plot(figure_width=4) ax2.figure.tight_layout() target_file = os.path.join(str(tmpdir), "by_hand_circular.png") ax2.figure.savefig(target_file, bbox_inches="tight")
print(miR.name) print(str(mir_seed)) for utr in SeqIO.parse(utr_Database, "fasta"): pos = 0 for seq in window(str(utr.seq), len(str(mir_seed))): if (hamming2(str(seq.upper()), str(mir_seed.back_transcribe().reverse_complement())) <= nb_max_mismatch): f1.write(utr.id + "\t" + str(pos) + "\t" + str(pos + len(str(mir_seed))) + "\t" + miR.id + "\t" + str( hamming2( str(seq.upper()), str(mir_seed.back_transcribe(). reverse_complement()))) + "\t" + "+" + "\t" + str(seq.upper()) + "\n") features.append( GraphicFeature(start=pos, end=pos + len(str(mir_seed)), strand=+1, color="#ccccff", label=re.sub(r'mmu-', '', miR.id))) pos = pos + 1 #print(pos) f1.close() record = CircularGraphicRecord(sequence_length=1100, features=features) # record.plot(figure_width=2) plt.show()
), GraphicFeature( start=20, end=500, strand=+1, color="#ffcccc", label="Gene 1 with a very long name", ), GraphicFeature( start=400, end=700, strand=-1, color="#cffccc", label="Gene 2" ), GraphicFeature( start=600, end=900, strand=+1, color="#ccccff", label="Gene 3" ), ] # PLOT AND EXPORT A LINEAR VIEW OF THE CONSTRUCT record = GraphicRecord(sequence_length=1000, features=features) ax, _ = record.plot(figure_width=5) ax.figure.savefig("graphic_record_defined_by_hand.png") # PLOT AND EXPORT A CIRCULAR VIEW OF THE CONSTRUCT circular_rec = CircularGraphicRecord(sequence_length=1000, features=features) ax2, _ = circular_rec.plot(figure_width=4) ax2.figure.tight_layout() ax2.figure.savefig( "graphic_record_defined_by_hand_circular.png", bbox_inches="tight" )