Skip to content

Calling .index in function embedDistanceMatrix requires input to be a DataFrame. #2

Open
@kmayerb

Description

@kmayerb

utils/embedding.py

Lines 63 to 69 in b61935a

def embedDistanceMatrix(dmatDf, method='kpca', n_components=2, **kwargs):
"""Two-dimensional embedding of sequence distances in dmatDf,
returning Nx2 x,y-coords: tsne, isomap, pca, mds, kpca, sklearn-tsne"""
if isinstance(dmatDf, pd.DataFrame):
dmat = dmatDf.values
else:
dmat = dmatDf

Note that the upper portion of the function is meant to accomodate either numpy.array or pd.DataFrame passed to dmatDf, but if numpy array is supplied then L111 will raise an error:

xyDf = pd.DataFrame(xy[:, :n_components], index=dmatDf.index, columns=np.arange(n_components))

Example

embedDistanceMatrix(dmatDf = pd.DataFrame(tr.pw_beta[0:10,:][:,0:10]), method = "mds")

👍

embedDistanceMatrix(dmatDf = tr.pw_beta[0:10,:][:,0:10], method = "mds")

👎

AttributeError: 'numpy.ndarray' object has no attribute 'index'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions