Skip to content

Commit

Permalink
Merge pull request #81 from simonvh/seed
Browse files Browse the repository at this point in the history
set random seed for clustering, closes #80
  • Loading branch information
simonvh authored Dec 17, 2018
2 parents 2670114 + 6e22faa commit 0f4c28f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions fluff/commands/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def heatmap(args):
dynam = args.graphdynamics
fontsize = args.textfontsize
colorbar = args.colorbar

seed = args.seed

# Check for mutually exclusive parameters
if dynam:
if merge_mirrored:
Expand Down Expand Up @@ -147,7 +148,8 @@ def load_data(featurefile, amount_bins, extend_dyn_up, extend_dyn_down, rmdup, r
clus,
cluster_type=cluster_type,
numclusters = args.numclusters,
dist=METRIC)
dist=METRIC,
random_state=seed)

if cluster_type == "k":
if not dynam and merge_mirrored:
Expand Down
2 changes: 1 addition & 1 deletion fluff/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### CONSTANTS ###
FL_VERSION = "3.0.2"
FL_VERSION = "3.0.3"

######## HEATMAP #############
DEFAULT_BINSIZE = 25
Expand Down
8 changes: 6 additions & 2 deletions fluff/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def parse_cmds():
help="pick specific data files to use for clustering",
default=None,
type=str)

clu_grp.add_argument("-S",
dest="seed",
help="random seed (int) to use for K-means clustering",
default=None,
type=int)
dap_grp = p.add_argument_group(title='Data processing')
dap_grp.add_argument("-r",
dest="rpkm",
Expand Down Expand Up @@ -362,4 +366,4 @@ def main():
main()
except KeyboardInterrupt:
sys.stderr.write("User interrupted me! ;-) Bye!\n")
sys.exit(0)
sys.exit(0)
4 changes: 2 additions & 2 deletions fluff/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def mirror_clusters(data, labels, cutoff=0.01):
return (None, None)


def cluster_profile(cluster_data, cluster_type="k", numclusters=3, dist="euclidean"):
def cluster_profile(cluster_data, cluster_type="k", numclusters=3, dist="euclidean", random_state=None):
"""Cluster profiles for heatmap
Takes a matrix and clusters either with kmeans or hierarchical clustering.
Expand Down Expand Up @@ -227,7 +227,7 @@ def cluster_profile(cluster_data, cluster_type="k", numclusters=3, dist="euclide
print("K-means clustering")
## K-means clustering

k = KMeans(n_clusters=numclusters)
k = KMeans(n_clusters=numclusters, random_state=random_state)
labels = k.fit(cluster_data).labels_
ind = labels.argsort()

Expand Down

0 comments on commit 0f4c28f

Please sign in to comment.