code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
return Input((seq_length, len(RNAplfold_PROFILES)), name=name, **kwargs)
def InputRNAStructure(seq_length, name=None, **kwargs)
Input placeholder for array returned by `encodeRNAStructure` Wrapper for: `keras.layers.Input((seq_length, 5), name=name, **kwargs)`
14.213018
12.730412
1.116462
return Input((seq_length, n_bases), name=name, **kwargs)
def InputSplines(seq_length, n_bases=10, name=None, **kwargs)
Input placeholder for array returned by `encodeSplines` Wrapper for: `keras.layers.Input((seq_length, n_bases), name=name, **kwargs)`
3.783038
3.038352
1.245095
return Input((seq_length, n_bases), name=name, **kwargs)
def InputSplines1D(seq_length, n_bases=10, name=None, **kwargs)
Input placeholder for array returned by `encodeSplines` Wrapper for: `keras.layers.Input((seq_length, n_bases), name=name, **kwargs)`
3.813198
3.025323
1.260427
return Input((seq_length, n_features), name=name, **kwargs)
def InputDNAQuantity(seq_length, n_features=1, name=None, **kwargs)
Convenience wrapper around `keras.layers.Input`: `Input((seq_length, n_features), name=name, **kwargs)`
3.556606
3.114556
1.14193
return Input((seq_length, n_bases), name=name, **kwargs)
def InputDNAQuantitySplines(seq_length, n_bases=10, name="DNASmoothPosition", **kwargs)
Convenience wrapper around keras.layers.Input: `Input((seq_length, n_bases), name=name, **kwargs)`
4.235785
3.13787
1.349892
W = self.get_weights()[0] if index is None: index = np.arange(W.shape[2]) fig = heatmap(np.swapaxes(W[:, :, index], 0, 1), plot_name="filter: ", vocab=self.VOCAB, figsize=figsize, **kwargs) # plt.show() return fig
def _plot_weights_heatmap(self, index=None, figsize=None, **kwargs)
Plot weights as a heatmap index = can be a particular index or a list of indicies **kwargs - additional arguments to concise.utils.plot.heatmap
4.863639
5.238806
0.928387
w_all = self.get_weights() if len(w_all) == 0: raise Exception("Layer needs to be initialized first") W = w_all[0] if index is None: index = np.arange(W.shape[2]) if isinstance(index, int): index = [index] fig = plt.figure(f...
def _plot_weights_motif(self, index, plot_type="motif_raw", background_probs=DEFAULT_BASE_BACKGROUND, ncol=1, figsize=None)
Index can only be a single int
3.330112
3.337621
0.99775
if "heatmap" in self.AVAILABLE_PLOTS and plot_type == "heatmap": return self._plot_weights_heatmap(index=index, figsize=figsize, ncol=ncol, **kwargs) elif plot_type[:5] == "motif": return self._plot_weights_motif(index=index, plot_type=plot_type, figsize=figsize, ncol=n...
def plot_weights(self, index=None, plot_type="motif_raw", figsize=None, ncol=1, **kwargs)
Plot filters as heatmap or motifs index = can be a particular index or a list of indicies **kwargs - additional arguments to concise.utils.plot.heatmap
2.138205
2.092632
1.021778
for pwm in pwm_list: if not isinstance(pwm, PWM): raise TypeError("element {0} of pwm_list is not of type PWM".format(pwm)) return True
def _check_pwm_list(pwm_list)
Check the input validity
2.885217
2.821064
1.022741
''' Add noise with truncnorm from numpy. Bounded (0.001,0.999) ''' # within range () # provide entry to chose which adding noise way to use if seed is not None: np.random.seed(seed) if stddev == 0: X = mean else: gen_X = truncnorm((alpha - mean) / stddev, ...
def _truncated_normal(mean, stddev, seed=None, normalize=True, alpha=0.01)
Add noise with truncnorm from numpy. Bounded (0.001,0.999)
5.60362
4.36755
1.283012
# Generate y and x values from the dimension lengths assert len(vocab) == w.shape[0] plt_y = np.arange(w.shape[0] + 1) + 0.5 plt_x = np.arange(w.shape[1] + 1) - 0.5 z_min = w.min() z_max = w.max() if vmin is None: vmin = z_min if vmax is None: vmax = z_max if d...
def heatmap(w, vmin=None, vmax=None, diverge_color=False, ncol=1, plot_name=None, vocab=["A", "C", "G", "T"], figsize=(6, 2))
Plot a heatmap from weight matrix w vmin, vmax = z axis range diverge_color = Should we use diverging colors? plot_name = plot_title vocab = vocabulary (corresponds to the first axis)
2.080767
2.07508
1.002741
# find all of the polygons in the letter (for instance an A # needs to be constructed from 2 polygons) path_strs = re.findall("\(\(([^\)]+?)\)\)", data_str.strip()) # convert the data into a numpy array polygons_data = [] for path_str in path_strs: data = np.array([ tup...
def standardize_polygons_str(data_str)
Given a POLYGON string, standardize the coordinates to a 1x1 grid. Input : data_str (taken from above) Output: tuple of polygon objects
2.873241
2.856057
1.006017
if len(let) == 2: colors = [col, "white"] elif len(let) == 1: colors = [col] else: raise ValueError("3 or more Polygons are not supported") for polygon, color in zip(let, colors): new_polygon = affinity.scale( polygon, yfact=height, origin=(0, 0, 0)) ...
def add_letter_to_axis(ax, let, col, x, y, height)
Add 'let' with position x,y and height height to matplotlib axis 'ax'.
2.570369
2.524042
1.018355
ax = ax or plt.gca() assert letter_heights.shape[1] == len(VOCABS[vocab]) x_range = [1, letter_heights.shape[0]] pos_heights = np.copy(letter_heights) pos_heights[letter_heights < 0] = 0 neg_heights = np.copy(letter_heights) neg_heights[letter_heights > 0] = 0 for x_pos, heights i...
def seqlogo(letter_heights, vocab="DNA", ax=None)
Make a logo plot # Arguments letter_heights: "motif length" x "vocabulary size" numpy array Can also contain negative values. vocab: str, Vocabulary name. Can be: DNA, RNA, AA, RNAStruct. ax: matplotlib axis
2.299727
2.339683
0.982922
ac_list = [(accuracy["train_acc_final"], accuracy["test_acc_final"] ) for accuracy, weights in res] ac = np.array(ac_list) perf = { "mean_train_acc": np.mean(ac[:, 0]), "std_train_acc": np.std(ac[:, 0]), "mean_test_acc": np.mean(ac...
def get_cv_accuracy(res)
Extract the cv accuracy from the model
2.78096
2.734432
1.017016
tokens = one_hot2token(arr) indexToLetter = _get_index_dict(vocab) return [''.join([indexToLetter[x] for x in row]) for row in tokens]
def one_hot2string(arr, vocab)
Convert a one-hot encoded array back to string
6.021876
5.956554
1.010966
# Req: all vocabs have the same length if isinstance(neutral_vocab, str): neutral_vocab = [neutral_vocab] nchar = len(vocab[0]) for l in vocab + neutral_vocab: assert len(l) == nchar assert len(seq) % nchar == 0 # since we are using striding vocab_dict = _get_vocab_dict(v...
def tokenize(seq, vocab, neutral_vocab=[])
Convert sequence to integers # Arguments seq: Sequence to encode vocab: Vocabulary to use neutral_vocab: Neutral vocabulary -> assign those values to -1 # Returns List of length `len(seq)` with integers from `-1` to `len(vocab) - 1`
4.245658
4.438102
0.956638
arr = np.zeros((len(tvec), vocab_size)) tvec_range = np.arange(len(tvec)) tvec = np.asarray(tvec) arr[tvec_range[tvec >= 0], tvec[tvec >= 0]] = 1 return arr
def token2one_hot(tvec, vocab_size)
Note: everything out of the vucabulary is transformed into `np.zeros(vocab_size)`
2.447105
2.477497
0.987733
if isinstance(neutral_vocab, str): neutral_vocab = [neutral_vocab] if isinstance(seq_vec, str): raise ValueError("seq_vec should be an iterable returning " + "strings not a string itself") assert len(vocab[0]) == len(pad_value) assert pad_value in neutral_vo...
def encodeSequence(seq_vec, vocab, neutral_vocab, maxlen=None, seq_align="start", pad_value="N", encode_type="one_hot")
Convert a list of genetic sequences into one-hot-encoded array. # Arguments seq_vec: list of strings (genetic sequences) vocab: list of chars: List of "words" to use as the vocabulary. Can be strings of length>0, but all need to have the same length. For DNA, this is: ["A", "C", "G", "T"]...
3.363976
3.244384
1.036861
return encodeSequence(seq_vec, vocab=DNA, neutral_vocab="N", maxlen=maxlen, seq_align=seq_align, pad_value="N", encode_type="one_hot")
def encodeDNA(seq_vec, maxlen=None, seq_align="start")
Convert the DNA sequence into 1-hot-encoding numpy array # Arguments seq_vec: list of chars List of sequences that can have different lengths maxlen: int or None, Should we trim (subset) the resulting sequence. If None don't trim. Note that trims wrt the align p...
5.084891
6.805484
0.747176
return encodeSequence(seq_vec, vocab=RNA, neutral_vocab="N", maxlen=maxlen, seq_align=seq_align, pad_value="N", encode_type="one_hot")
def encodeRNA(seq_vec, maxlen=None, seq_align="start")
Convert the RNA sequence into 1-hot-encoding numpy array as for encodeDNA
5.387782
5.01909
1.073458
if ignore_stop_codons: vocab = CODONS neutral_vocab = STOP_CODONS + ["NNN"] else: vocab = CODONS + STOP_CODONS neutral_vocab = ["NNN"] # replace all U's with A's? seq_vec = [str(seq).replace("U", "T") for seq in seq_vec] return encodeSequence(seq_vec, ...
def encodeCodon(seq_vec, ignore_stop_codons=True, maxlen=None, seq_align="start", encode_type="one_hot")
Convert the Codon sequence into 1-hot-encoding numpy array # Arguments seq_vec: List of strings/DNA sequences ignore_stop_codons: boolean; if True, STOP_CODONS are omitted from one-hot encoding. maxlen: Maximum sequence length. See `pad_sequences` for more detail seq_align: How to a...
3.012142
2.946077
1.022425
return encodeSequence(seq_vec, vocab=AMINO_ACIDS, neutral_vocab="_", maxlen=maxlen, seq_align=seq_align, pad_value="_", encode_type=encode_type)
def encodeAA(seq_vec, maxlen=None, seq_align="start", encode_type="one_hot")
Convert the Amino-acid sequence into 1-hot-encoding numpy array # Arguments seq_vec: List of strings/amino-acid sequences maxlen: Maximum sequence length. See `pad_sequences` for more detail seq_align: How to align the sequences of variable lengths. See `pad_sequences` for more detail ...
4.773817
5.508833
0.866575
if isinstance(gtf, str): _logger.info("Reading gtf file..") gtf = read_gtf(gtf) _logger.info("Done") _logger.info("Running landmark extractors..") # landmarks to a dictionary with a function assert isinstance(landmarks, (list, tuple, set, dict)) if isinstance(landmarks,...
def extract_landmarks(gtf, landmarks=ALL_LANDMARKS)
Given an gene annotation GFF/GTF file, # Arguments gtf: File path or a loaded `pd.DataFrame` with columns: seqname, feature, start, end, strand landmarks: list or a dictionary of landmark extractors (function or name) # Note When landmark extractor names are used, they have to be i...
3.317635
3.281051
1.01115
assert isinstance(df, pd.DataFrame) assert ["seqname", "position", "strand"] == df.columns.tolist() assert df.position.dtype == np.dtype("int64") assert df.strand.dtype == np.dtype("O") assert df.seqname.dtype == np.dtype("O") return df
def _validate_pos(df)
Validates the returned positional object
2.563419
2.515666
1.018982
# assert k >= 0 with tf.name_scope(scope, 'L1Loss', [tensor]): loss = tf.reduce_mean(tf.select(tf.abs(tensor) < k, 0.5 * tf.square(tensor), k * tf.abs(tensor) - 0.5 * k ^ 2) ) retur...
def huber_loss(tensor, k=1, scope=None)
Define a huber loss https://en.wikipedia.org/wiki/Huber_loss tensor: tensor to regularize. k: value of k in the huber loss scope: Optional scope for op_scope. Huber loss: f(x) = if |x| <= k: 0.5 * x^2 else: k * |x| - 0.5 * k^2 Returns: the L...
2.66788
2.660455
1.002791
dt = pd.read_table(ATTRACT_METADTA) dt.rename(columns={"Matrix_id": "PWM_id"}, inplace=True) # put to firt place cols = ['PWM_id'] + [col for col in dt if col != 'PWM_id'] # rename Matrix_id to PWM_id return dt[cols]
def get_metadata()
Get pandas.DataFrame with metadata about the Attract PWM's. Columns: - PWM_id (id of the PWM - pass to get_pwm_list() for getting the pwm - Gene_name - Gene_id - Mutated (if the target gene is mutated) - Organism - Motif (concsensus motif) - Len (lenght of the motif) - Experiment_de...
8.624002
6.044611
1.426726
l = load_motif_db(ATTRACT_PWM) l = {k.split()[0]: v for k, v in l.items()} pwm_list = [PWM(l[str(m)] + pseudocountProb, name=m) for m in pwm_id_list] return pwm_list
def get_pwm_list(pwm_id_list, pseudocountProb=0.0001)
Get a list of Attract PWM's. # Arguments pwm_id_list: List of id's from the `PWM_id` column in `get_metadata()` table pseudocountProb: Added pseudocount probabilities to the PWM # Returns List of `concise.utils.pwm.PWM` instances.
4.783738
4.979681
0.960652
loss_fn = kloss.deserialize(loss) def masked_loss_fn(y_true, y_pred): # currently not suppoerd with NA's: # - there is no K.is_nan impolementation in keras.backend # - https://github.com/fchollet/keras/issues/1628 mask = K.cast(K.not_equal(y_true, mask_value), K.floatx())...
def mask_loss(loss, mask_value=MASK_VALUE)
Generates a new loss function that ignores values where `y_true == mask_value`. # Arguments loss: str; name of the keras loss function from `keras.losses` mask_value: int; which values should be masked # Returns function; Masked version of the `loss` # Example ```python ...
4.68388
4.915209
0.952936
l = load_motif_db(HOCOMOCO_PWM) l = {k.split()[0]: v for k, v in l.items()} pwm_list = [PWM(_normalize_pwm(l[m]) + pseudocountProb, name=m) for m in pwm_id_list] return pwm_list
def get_pwm_list(pwm_id_list, pseudocountProb=0.0001)
Get a list of HOCOMOCO PWM's. # Arguments pwm_id_list: List of id's from the `PWM_id` column in `get_metadata()` table pseudocountProb: Added pseudocount probabilities to the PWM # Returns List of `concise.utils.pwm.PWM` instances.
4.800229
5.216824
0.920144
if self.is_trained() is False: # print("Model not fitted yet. Use object.fit() to fit the model.") return None var_res = self._var_res weights = self._var_res_to_weights(var_res) # save to the side weights["final_bias_fit"] = weights["final_bias"...
def get_weights(self)
Returns: dict: Model's trained weights.
6.685046
6.255672
1.068638
# transform the weights into our form motif_base_weights_raw = var_res["motif_base_weights"][0] motif_base_weights = np.swapaxes(motif_base_weights_raw, 0, 2) # get weights motif_weights = var_res["motif_weights"] motif_bias = var_res["motif_bias"] final...
def _var_res_to_weights(self, var_res)
Get model weights
2.774234
2.712232
1.02286
with tf.Session(graph=graph) as sess: sess.run(other_var["init"]) # all_vars = tf.all_variables() # print("All variable names") # print([var.name for var in all_vars]) # print("All variable values") # print(sess.run(all_vars)) ...
def _get_var_res(self, graph, var, other_var)
Get the weights from our graph
3.089385
2.960026
1.043702
with graph.as_default(): var = {} for key, value in var_res.items(): if value is not None: var[key] = tf.Variable(value, name="tf_%s" % key) else: var[key] = None return var
def _convert_to_var(self, graph, var_res)
Create tf.Variables from a list of numpy arrays var_res: dictionary of numpy arrays with the key names corresponding to var
2.657722
2.63548
1.008439
# other_var["tf_X_seq"]: X_seq, tf_y: y, feed_dict = {other_var["tf_X_feat"]: X_feat, other_var["tf_X_seq"]: X_seq} y_pred = sess.run(other_var[variable], feed_dict=feed_dict) return y_pred
def _predict_in_session(self, sess, other_var, X_feat, X_seq, variable="y_pred")
Predict y (or any other variable) from inside the tf session. Variable has to be in other_var
2.718786
2.631214
1.033282
y_pred = self._predict_in_session(sess, other_var, X_feat, X_seq) return ce.mse(y_pred, y)
def _accuracy_in_session(self, sess, other_var, X_feat, X_seq, y)
Compute the accuracy from inside the tf session
3.03722
3.1614
0.96072
# insert one dimension - backcompatiblity X_seq = np.expand_dims(X_seq, axis=1) return self._get_other_var(X_feat, X_seq, variable="y_pred")
def predict(self, X_feat, X_seq)
Predict the response variable :py:attr:`y` for new input data (:py:attr:`X_feat`, :py:attr:`X_seq`). Args: X_feat: Feature design matrix. Same format as :py:attr:`X_feat` in :py:meth:`train` X_seq: Sequenc design matrix. Same format as :py:attr:`X_seq` in :py:meth:`train`
7.394643
8.858438
0.834757
if self.is_trained() is False: print("Model not fitted yet. Use object.fit() to fit the model.") return # input check: assert X_seq.shape[0] == X_feat.shape[0] # TODO - check this # sequence can be wider or thinner? # assert self._param[...
def _get_other_var(self, X_feat, X_seq, variable="y_pred")
Get the value of a variable from other_vars (from a tf-graph)
4.725041
4.565965
1.034839
final_res = { "param": self._param, "unused_param": self.unused_param, "execution_time": self._exec_time, "output": {"accuracy": self.get_accuracy(), "weights": self.get_weights(), "splines": self._splines ...
def to_dict(self)
Returns: dict: Concise represented as a dictionary.
5.388653
5.09722
1.057175
if weights is None: return # layer 1 motif_base_weights_raw = np.swapaxes(weights["motif_base_weights"], 2, 0) motif_base_weights = motif_base_weights_raw[np.newaxis] motif_bias = weights["motif_bias"] feature_weights = weights["feature_weights"] ...
def _set_var_res(self, weights)
Transform the weights to var_res
2.42868
2.404389
1.010103
# convert the output into a proper form obj_dict['output'] = helper.rec_dict_to_numpy_dict(obj_dict["output"]) helper.dict_to_numpy_dict(obj_dict['output']) if "trained_global_model" in obj_dict.keys(): raise Exception("Found trained_global_model feature in diction...
def from_dict(cls, obj_dict)
Load the object from a dictionary (produced with :py:func:`Concise.to_dict`) Returns: Concise: Loaded Concise object.
5.907323
5.558915
1.062676
# convert back to numpy data = helper.read_json(file_path) return Concise.from_dict(data)
def load(cls, file_path)
Load the object from a JSON file (saved with :py:func:`Concise.save`). Returns: Concise: Loaded Concise object.
13.85389
8.767258
1.580185
# n_folds = self._n_folds # use_stored = self._use_stored_folds # n_rows = self._n_rows if use_stored is not None: # path = '~/concise/data-offline/lw-pombe/cv_folds_5.json' with open(os.path.expanduser(use_stored)) as json_file: json_dat...
def _get_folds(n_rows, n_folds, use_stored)
Get the used CV folds
3.307963
3.243745
1.019797
# TODO: input check - dimensions self._use_stored_folds = use_stored_folds self._n_folds = n_folds self._n_rows = X_feat.shape[0] # TODO: - fix the get_cv_accuracy # save: # - each model # - each model's performance # - each model's predictions # - globa...
def train(self, X_feat, X_seq, y, id_vec=None, n_folds=10, use_stored_folds=None, n_cores=1, train_global_model=False)
Train the Concise model in cross-validation. Args: X_feat: See :py:func:`concise.Concise.train` X_seq: See :py:func:`concise.Concise.train` y: See :py:func:`concise.Concise.train` id_vec: List of character id's used to differentiate the trainig samples. Returned ...
2.893247
2.84484
1.017016
# TODO: get it from the test_prediction ... # test_id, prediction # sort by test_id predict_vec = np.zeros((self._n_rows, self._concise_model._num_tasks)) for fold, train, test in self._kf: acc = self._cv_model[fold].get_accuracy() predict_vec[tes...
def get_CV_prediction(self)
Returns: np.ndarray: Predictions on the hold-out folds (unseen data, corresponds to :py:attr:`y`).
9.548344
9.029372
1.057476
accuracy = {} for fold, train, test in self._kf: acc = self._cv_model[fold].get_accuracy() accuracy[fold] = acc["test_acc_final"] return accuracy
def get_CV_accuracy(self)
Returns: float: Prediction accuracy in CV.
6.193666
6.516443
0.950467
param = { "n_folds": self._n_folds, "n_rows": self._n_rows, "use_stored_folds": self._use_stored_folds } if self._concise_global_model is None: trained_global_model = None else: trained_global_model = self._concise_glo...
def to_dict(self)
Returns: dict: ConciseCV represented as a dictionary.
3.53784
3.355264
1.054415
default_model = Concise() cvdc = ConciseCV(default_model) cvdc._from_dict(obj_dict) return cvdc
def from_dict(cls, obj_dict)
Load the object from a dictionary (produced with :py:func:`ConciseCV.to_dict`) Returns: ConciseCV: Loaded ConciseCV object.
10.723162
6.263101
1.712117
self._n_folds = obj_dict["param"]["n_folds"] self._n_rows = obj_dict["param"]["n_rows"] self._use_stored_folds = obj_dict["param"]["use_stored_folds"] self._concise_model = Concise.from_dict(obj_dict["init_model"]) if obj_dict["trained_global_model"] is None: ...
def _from_dict(self, obj_dict)
Initialize a model from the dictionary
2.882434
2.878734
1.001286
data = helper.read_json(file_path) return ConciseCV.from_dict(data)
def load(cls, file_path)
Load the object from a JSON file (saved with :py:func:`ConciseCV.save`) Returns: ConciseCV: Loaded ConciseCV object.
12.944995
5.987683
2.161937
b = background_probs2array(background_probs) b = b.reshape([1, 4, 1]) return np.log(arr / b).astype(arr.dtype)
def pwm_array2pssm_array(arr, background_probs=DEFAULT_BASE_BACKGROUND)
Convert pwm array to pssm array
5.671796
5.497758
1.031656
b = background_probs2array(background_probs) b = b.reshape([1, 4, 1]) return (np.exp(arr) * b).astype(arr.dtype)
def pssm_array2pwm_array(arr, background_probs=DEFAULT_BASE_BACKGROUND)
Convert pssm array to pwm array
5.295993
5.306325
0.998053
# read-lines if filename.endswith(".gz"): f = gzip.open(filename, 'rt', encoding='utf-8') else: f = open(filename, 'r') lines = f.readlines() f.close() motifs_dict = {} motif_lines = "" motif_name = None def lines2matrix(lines): return np.loadtxt(Strin...
def load_motif_db(filename, skipn_matrix=0)
Read the motif file in the following format ``` >motif_name <skip n>0.1<delim>0.2<delim>0.5<delim>0.6 ... >motif_name2 .... ``` Delim can be anything supported by np.loadtxt # Arguments filename: str, file path skipn_matrix: integer, number of characters to skip wh...
2.194329
2.135866
1.027372
fh = open(file_path) # ditch the boolean (x[0]) and just keep the header or sequence since # we know they alternate. faiter = (x[1] for x in groupby(fh, lambda line: line[0] == ">")) for header in faiter: # drop the ">" headerStr = header.__next__()[1:].strip() # join ...
def iter_fasta(file_path)
Returns an iterator over the fasta file Given a fasta file. yield tuples of header, sequence Code modified from Brent Pedersen's: "Correct Way To Parse A Fasta File In Python" # Example ```python fasta = fasta_iter("hg19.fa") for header, seq in fasta: ...
2.159586
2.030995
1.063314
if name_list is None: name_list = [str(i) for i in range(len(seq_list))] # needs to be dict or seq with open(file_path, "w") as f: for i in range(len(seq_list)): f.write(">" + name_list[i] + "\n" + seq_list[i] + "\n")
def write_fasta(file_path, seq_list, name_list=None)
Write a fasta file # Arguments file_path: file path seq_list: List of strings name_list: List of names corresponding to the sequences. If not None, it should have the same length as `seq_list`
2.166742
2.311967
0.937185
profiles = RNAplfold_PROFILES_EXECUTE for i, P in enumerate(profiles): print("running {P}_RNAplfold... ({i}/{N})".format(P=P, i=i + 1, N=len(profiles))) command = "{bin}/{P}_RNAplfold".format(bin=RNAplfold_BIN_DIR, P=P) file_out = "{tmp}/{P}_profile.fa".format(tmp=tmpdir, P=P) ...
def run_RNAplfold(input_fasta, tmpdir, W=240, L=160, U=1)
Arguments: W, Int: span - window length L, Int, maxiumm span U, Int, size of unpaired region
2.890429
3.011464
0.959809
assert pad_with in {"P", "H", "I", "M", "E"} def read_profile(tmpdir, P): return [values.strip().split("\t") for seq_name, values in iter_fasta("{tmp}/{P}_profile.fa".format(tmp=tmpdir, P=P))] def nelem(P, pad_width): return 1 if P is pad_with else 0 arr_...
def read_RNAplfold(tmpdir, maxlen=None, seq_align="start", pad_with="E")
pad_with = with which 2ndary structure should we pad the sequence?
6.009991
5.961494
1.008135
# extend the tmpdir with uuid string to allow for parallel execution tmpdir = tmpdir + "/" + str(uuid4()) + "/" if not isinstance(seq_vec, list): seq_vec = seq_vec.tolist() if not os.path.exists(tmpdir): os.makedirs(tmpdir) fasta_path = tmpdir + "/input.fasta" write_fasta(...
def encodeRNAStructure(seq_vec, maxlen=None, seq_align="start", W=240, L=160, U=1, tmpdir="/tmp/RNAplfold/")
Compute RNA secondary structure with RNAplfold implemented in Kazan et al 2010, [doi](https://doi.org/10.1371/journal.pcbi.1000832). # Note Secondary structure is represented as the probability to be in the following states: - `["Pairedness", "Hairpin loop", "Internal loop", "Multi loop...
3.372592
3.4988
0.963928
def _format_keras_history(history): return {"params": history.params, "loss": merge_dicts({"epoch": history.epoch}, history.history), } if use_weight: sample_weight = train[2] else: sample_weight = None # train the model logger.in...
def _train_and_eval_single(train, valid, model, batch_size=32, epochs=300, use_weight=False, callbacks=[], eval_best=False, add_eval_metrics={})
Fit and evaluate a keras model eval_best: if True, load the checkpointed model for evaluation
3.42908
3.513564
0.975955
# evaluate the model logger.info("Evaluate...") # - model_metrics model_metrics_values = model.evaluate(test[0], test[1], verbose=0, batch_size=test[1].shape[0]) # evaluation is done in a single pass to have more precise metics model_metrics = dict(...
def eval_model(model, test, add_eval_metrics={})
Evaluate model's performance on the test-set. # Arguments model: Keras model test: test-dataset. Tuple of inputs `x` and target `y` - `(x, y)`. add_eval_metrics: Additional evaluation metrics to use. Can be a dictionary or a list of functions accepting arguments: `y_true`, `y_predicted`...
3.538723
3.59899
0.983254
model_param = merge_dicts({"train_data": train_data}, param["model"], param.get("shared", {})) return model_fn(**model_param)
def get_model(model_fn, train_data, param)
Feed model_fn with train_data and param
4.892914
4.849086
1.009038
c = deepcopy(dct) assert isinstance(keys, list) for k in keys: c.pop(k) return c
def _delete_keys(dct, keys)
Returns a copy of dct without `keys` keys
4.11007
3.451814
1.190699
return {k: np.array([d[k] for d in dict_list]).mean() for k in dict_list[0].keys()}
def _mean_dict(dict_list)
Compute the mean value across a list of dictionaries
2.485774
2.24716
1.106185
lid = np.where(np.array(self.tids) == tid)[0][0] return self.trials[lid]
def get_trial(self, tid)
Retrieve trial by tid
3.999995
3.747064
1.067501
if self.kill_timeout is not None: self.delete_running(self.kill_timeout) return super(CMongoTrials, self).count_by_state_unsynced(arg)
def count_by_state_unsynced(self, arg)
Extends the original object in order to inject checking for stalled jobs and killing them if they are running for too long
6.642394
4.993965
1.330084
running_all = self.handle.jobs_running() running_timeout = [job for job in running_all if coarse_utcnow() > job["refresh_time"] + timedelta(seconds=timeout_last_refresh)] if len(running_timeout) == 0: # Nothing to stop ...
def delete_running(self, timeout_last_refresh=0, dry_run=False)
Delete jobs stalled in the running state for too long timeout_last_refresh, int: number of seconds
3.923043
3.848861
1.019274
def result2history(result): if isinstance(result["history"], list): return pd.concat([pd.DataFrame(hist["loss"]).assign(fold=i) for i, hist in enumerate(result["history"])]) else: return pd.DataFrame(result["hist...
def train_history(self, tid=None)
Get train history as pd.DataFrame
4.483337
4.308535
1.040571
def add_eval(res): if "eval" not in res: if isinstance(res["history"], list): # take the average across all folds eval_names = list(res["history"][0]["loss"].keys()) eval_metrics = np.array([[v[-1] for k, v in hist...
def as_df(self, ignore_vals=["history"], separator=".", verbose=True)
Return a pd.DataFrame view of the whole experiment
3.262137
3.24502
1.005275
assert isinstance(methods, list) if isinstance(extra_args, list): assert(len(extra_args) == len(methods)) else: extra_args = [None] * len(methods) main_args = {"model": model, "ref": ref, "ref_rc": ref_rc, "alt": alt, "alt_rc": alt_rc, "mutation_positions": mutatio...
def effect_from_model(model, ref, ref_rc, alt, alt_rc, methods, mutation_positions, out_annotation_all_outputs, extra_args=None, **argv)
Convenience function to execute multiple effect predictions in one call # Arguments model: Keras model ref: Input sequence with the reference genotype in the mutation position ref_rc: Reverse complement of the 'ref' argument alt: Input sequence with the alternative genotype in the m...
2.039656
1.943306
1.049581
market = Market(market, bitshares_instance=ctx.bitshares) t = [["time", "quote", "base", "price"]] for trade in market.trades(limit, start=start, stop=stop): t.append( [ str(trade["time"]), str(trade["quote"]), str(trade["base"]), ...
def trades(ctx, market, limit, start, stop)
List trades in a market
2.723399
2.663006
1.022679
market = Market(market, bitshares_instance=ctx.bitshares) ticker = market.ticker() t = [["key", "value"]] for key in ticker: t.append([key, str(ticker[key])]) print_table(t)
def ticker(ctx, market)
Show ticker of a market
3.469691
3.166592
1.095718
print_tx(ctx.bitshares.cancel(orders, account=account))
def cancel(ctx, orders, account)
Cancel one or multiple orders
12.983081
12.503759
1.038334
market = Market(market, bitshares_instance=ctx.bitshares) orderbook = market.orderbook() ta = {} ta["bids"] = [["quote", "sum quote", "base", "sum base", "price"]] cumsumquote = Amount(0, market["quote"]) cumsumbase = Amount(0, market["base"]) for order in orderbook["bids"]: cum...
def orderbook(ctx, market)
Show the orderbook of a particular market
1.940172
1.920292
1.010352
amount = Amount(buy_amount, buy_asset) price = Price( price, base=sell_asset, quote=buy_asset, bitshares_instance=ctx.bitshares ) print_tx( price.market.buy(price, amount, account=account, expiration=order_expiration) )
def buy(ctx, buy_amount, buy_asset, price, sell_asset, order_expiration, account)
Buy a specific asset at a certain rate against a base asset
3.951354
3.737893
1.057107
account = Account( account or config["default_account"], bitshares_instance=ctx.bitshares ) t = [["Price", "Quote", "Base", "ID"]] for o in account.openorders: t.append( [ "{:f} {}/{}".format( o["price"], o["base"][...
def openorders(ctx, account)
List open orders of an account
3.44863
3.335957
1.033775
market = Market(market) ctx.bitshares.bundle = True market.cancel([x["id"] for x in market.accountopenorders(account)], account=account) print_tx(ctx.bitshares.txbuffer.broadcast())
def cancelall(ctx, market, account)
Cancel all orders of an account in a market
9.994492
9.277437
1.07729
from tqdm import tqdm from numpy import linspace market = Market(market) ctx.bitshares.bundle = True if min < max: space = linspace(min, max, num) else: space = linspace(max, min, num) func = getattr(market, side) for p in tqdm(space): func(p, total / floa...
def spread(ctx, market, side, min, max, num, total, order_expiration, account)
Place multiple orders \b :param str market: Market pair quote:base (e.g. USD:BTS) :param str side: ``buy`` or ``sell`` quote :param float min: minimum price to place order at :param float max: maximum price to place order at :param int num: Number of orders to place ...
4.840821
5.377802
0.900149
from bitshares.dex import Dex dex = Dex(bitshares_instance=ctx.bitshares) print_tx( dex.borrow(Amount(amount, symbol), collateral_ratio=ratio, account=account) )
def borrow(ctx, amount, symbol, ratio, account)
Borrow a bitasset/market-pegged asset
5.740884
5.839172
0.983167
from bitshares.dex import Dex dex = Dex(bitshares_instance=ctx.bitshares) print_tx(dex.adjust_collateral_ratio(symbol, ratio, account=account))
def updateratio(ctx, symbol, ratio, account)
Update the collateral ratio of a call positions
5.639513
5.721285
0.985708
print_tx(ctx.bitshares.fund_fee_pool(symbol, amount, account=account))
def fundfeepool(ctx, symbol, amount, account)
Fund the fee pool of an asset
6.966337
7.454614
0.9345
print_tx( ctx.bitshares.bid_collateral( Amount(collateral_amount, collateral_symbol), Amount(debt_amount, debt_symbol), account=account, ) )
def bidcollateral( ctx, collateral_symbol, collateral_amount, debt_symbol, debt_amount, account )
Bid for collateral in the settlement fund
3.682592
3.327342
1.106767
print_tx(ctx.bitshares.asset_settle(Amount(amount, symbol), account=account))
def settle(ctx, symbol, amount, account)
Fund the fee pool of an asset
11.748738
11.784007
0.997007
if not isinstance(type, (list, tuple)): type = [type] account = Account(account, full=True) ret = {key: list() for key in Vote.types()} for vote in account["votes"]: t = Vote.vote_type_from_id(vote["id"]) ret[t].append(vote) t = [["id", "url", "account"]] for vote i...
def votes(ctx, account, type)
List accounts vesting balances
2.392692
2.437411
0.981653
if not objects: t = [["Key", "Value"]] info = ctx.bitshares.rpc.get_dynamic_global_properties() for key in info: t.append([key, info[key]]) print_table(t) for obj in objects: # Block if re.match("^[0-9]*$", obj): block = Block(obj, la...
def info(ctx, objects)
Obtain all kinds of information
2.058872
2.060214
0.999349
from bitsharesbase.operationids import getOperationNameForId from bitshares.market import Market market = Market("%s:%s" % (currency, "BTS")) ticker = market.ticker() if "quoteSettlement_price" in ticker: price = ticker.get("quoteSettlement_price") else: price = ticker.get(...
def fees(ctx, currency)
List fees
4.100859
4.078627
1.005451
ctx.blockchain.blocking = True tx = ctx.blockchain.htlc_create( Amount(amount, symbol), to, secret, hash_type=hash, expiration=expiration, account=account, ) tx.pop("trx", None) print_tx(tx) results = tx.get("operation_results", {}) if res...
def create(ctx, to, amount, symbol, secret, hash, account, expiration)
Create an HTLC contract
4.636495
4.320318
1.073184
print_tx(ctx.blockchain.htlc_redeem(htlc_id, secret, account=account))
def redeem(ctx, htlc_id, secret, account)
Redeem an HTLC contract
5.576936
5.473253
1.018944
if not is_flags_class_final(flags_class): raise TypeError('unique check can be applied only to flags classes that have members') if not flags_class.__member_aliases__: return flags_class aliases = ', '.join('%s -> %s' % (alias, name) for alias, name in flags_class.__member_aliases__.ite...
def unique(flags_class)
A decorator for flags classes to forbid flag aliases.
4.091512
3.85332
1.061815
flags_class = unique(flags_class) other_bits = 0 for name, member in flags_class.__members_without_aliases__.items(): bits = int(member) if other_bits & bits: for other_name, other_member in flags_class.__members_without_aliases__.items(): if int(other_member...
def unique_bits(flags_class)
A decorator for flags classes to forbid declaring flags with overlapping bits.
3.289966
2.857773
1.151234
if isinstance(members, str): members = ((name, UNDEFINED) for name in members.replace(',', ' ').split()) elif isinstance(members, (tuple, list, collections.Set)): if members and isinstance(next(iter(members)), str): members = ((name, UNDEFINED) for name in members) elif isin...
def process_inline_members_definition(members)
:param members: this can be any of the following: - a string containing a space and/or comma separated list of names: e.g.: "item1 item2 item3" OR "item1,item2,item3" OR "item1, item2, item3" - tuple/list/Set of strings (names) - Mapping of (name, data) pairs - any kind of iterable that yields (na...
3.0011
2.752749
1.090219
members = [] auto_flags = [] all_bits = 0 for name, data in member_definitions: bits, data = cls.flag_attribute_value_to_bits_and_data(name, data) if bits is UNDEFINED: auto_flags.append(len(members)) members.append((name, ...
def process_member_definitions(cls, member_definitions)
The incoming member_definitions contains the class attributes (with their values) that are used to define the flag members. This method can do anything to the incoming list and has to return a final set of flag definitions that assigns bits to the members. The returned member definitions can be ...
4.367011
3.766988
1.159284
if not isinstance(s, str): raise TypeError("Expected an str instance, received %r" % (s,)) return cls(cls.bits_from_simple_str(s))
def from_simple_str(cls, s)
Accepts only the output of to_simple_str(). The output of __str__() is invalid as input.
4.403147
4.151029
1.060736
if not isinstance(s, str): raise TypeError("Expected an str instance, received %r" % (s,)) return cls(cls.bits_from_str(s))
def from_str(cls, s)
Accepts both the output of to_simple_str() and __str__().
4.721707
4.495699
1.050272
try: if len(s) <= len(cls.__name__) or not s.startswith(cls.__name__): return cls.bits_from_simple_str(s) c = s[len(cls.__name__)] if c == '(': if not s.endswith(')'): raise ValueError return cls.bit...
def bits_from_str(cls, s)
Converts the output of __str__ into an integer.
2.585548
2.523479
1.024597
if cer: cer = Price(cer, quote=symbol, base="1.3.0", bitshares_instance=ctx.bitshares) print_tx( ctx.bitshares.publish_price_feed( symbol, Price(price, market), cer=cer, mssr=mssr, mcr=mcr, account=account ) )
def newfeed(ctx, symbol, price, market, cer, mssr, mcr, account)
Publish a price feed! Examples: \b uptick newfeed USD 0.01 USD/BTS uptick newfeed USD 100 BTS/USD Core Exchange Rate (CER) \b If no CER is provided, the cer will be the same as the settlement price with a 5% premium (Only if the 'market' is ...
5.565116
5.441806
1.02266
import builtins witnesses = Witnesses(bitshares_instance=ctx.bitshares) def test_price(p, ref): if math.fabs(float(p / ref) - 1.0) > pricethreshold / 100.0: return click.style(str(p), fg="red") elif math.fabs(float(p / ref) - 1.0) > pricethreshold / 2.0 / 100.0: ...
def feeds(ctx, assets, pricethreshold, maxage)
Price Feed Overview
2.241378
2.246674
0.997643
t = format_table(*args, **kwargs) click.echo(t)
def print_table(*args, **kwargs)
if csv: import csv t = csv.writer(sys.stdout, delimiter=";") t.writerow(header) else: t = PrettyTable(header) t.align = "r" t.align["details"] = "l"
6.019273
6.05725
0.99373
try: data = list(eval(d) for d in arguments) except: data = arguments ret = getattr(ctx.bitshares.rpc, call)(*data, api=api) print_dict(ret)
def rpc(ctx, call, arguments, api)
Construct RPC call directly \b You can specify which API to send the call to: uptick rpc --api assets You can also specify lists using uptick rpc get_objects "['2.0.0', '2.1.0']"
5.627521
6.917074
0.81357
print_tx(ctx.bitshares.approvecommittee(members, account=account))
def approvecommittee(ctx, members, account)
Approve committee member(s)
13.48536
14.149859
0.953038
print_tx(ctx.bitshares.disapprovecommittee(members, account=account))
def disapprovecommittee(ctx, members, account)
Disapprove committee member(s)
11.604912
12.339385
0.940477