差分
このページの2つのバージョン間の差分を表示します。
20220928_invertebrate_grouping_script_finished [2022/09/28 06:32] – 作成 133.11.50.163 | 20220928_invertebrate_grouping_script_finished [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ``` | ||
- | //node grouping.js inputFilePath | ||
- | //read species file | ||
- | var fs = require(" | ||
- | var arg=process.argv.splice(2); | ||
- | file=arg[0] | ||
- | //var data = fs.readFileSync('/ | ||
- | var data = fs.readFileSync(file); | ||
- | //change the data to 1D-array | ||
- | var arr = data.toString().trim().split(" | ||
- | |||
- | arr.sort(); | ||
- | var processList=[] | ||
- | var speciesNumber=arr.length | ||
- | var saveList=[] | ||
- | |||
- | //change the data to 2D-array | ||
- | for (var species=0; species< | ||
- | processList[species]=arr[species].split(";" | ||
- | } | ||
- | |||
- | var countNumber=speciesNumber | ||
- | |||
- | //COUNTING the words, and separate the list | ||
- | var round=0 | ||
- | do{ | ||
- | var counttmp=[] | ||
- | var wordListtmp=[] | ||
- | for (var s=0; s< | ||
- | var existchecker=" | ||
- | for (i=0; | ||
- | if (processList[s][round]===wordListtmp[i]){ | ||
- | existchecker=" | ||
- | var posilog=i | ||
- | } | ||
- | } | ||
- | if (existchecker==" | ||
- | counttmp[posilog]=counttmp[posilog]+1 | ||
- | } | ||
- | else{ | ||
- | wordListtmp.push(processList[s][round]) | ||
- | counttmp.push(1) | ||
- | } | ||
- | } | ||
- | //get nost counted word | ||
- | var countNumbertmp=0 | ||
- | for (var j=0; j< | ||
- | if(countNumbertmp< | ||
- | countNumbertmp=counttmp[j] | ||
- | var indexOfCountNumber=j | ||
- | } | ||
- | var mostCountedWord=wordListtmp[indexOfCountNumber] | ||
- | } | ||
- | //separate the species list if need | ||
- | if (countNumbertmp!==countNumber){ | ||
- | //separate the list to save list and process list | ||
- | var savelisttmp=[] | ||
- | var processListtmp=[] | ||
- | processNumber=processList.length | ||
- | for (var k=0; | ||
- | if (mostCountedWord!==processList[k][round]){ | ||
- | savelisttmp.push(processList[k]) | ||
- | } | ||
- | else{ | ||
- | processListtmp.push(processList[k]) | ||
- | } | ||
- | } | ||
- | if (savelisttmp.length!==0){ | ||
- | saveList.push(savelisttmp) | ||
- | } | ||
- | processList=processListtmp | ||
- | } | ||
- | countNumber=countNumbertmp | ||
- | var time=round+1 | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | // | ||
- | round=round+1 | ||
- | } | ||
- | while (countNumber> | ||
- | |||
- | |||
- | //get final separate list and counts | ||
- | var separatedList=[] | ||
- | separatedList.push(processList) | ||
- | for (var q=0; q< | ||
- | separatedList.push(saveList[q]) | ||
- | } | ||
- | |||
- | var separatedCountList=[] | ||
- | for (var t=0; t< | ||
- | separatedCountList[t]=separatedList[t].length | ||
- | } | ||
- | |||
- | |||
- | |||
- | |||
- | //GROUPING | ||
- | var operationseparatedCountList=separatedCountList | ||
- | var operationseparatedList=separatedList | ||
- | do{ | ||
- | var groupinglisttmp=[] | ||
- | console.log(" | ||
- | var groupingtmp=[] | ||
- | console.log(" | ||
- | var d=speciesNumber | ||
- | var positionsaver=0 | ||
- | for(var i=0; | ||
- | var a=operationseparatedCountList[i] | ||
- | var b=operationseparatedCountList[i+1] | ||
- | var c=a+b | ||
- | if (c<d){ | ||
- | d=c | ||
- | positionsaver=i | ||
- | } | ||
- | } | ||
- | console.log(" | ||
- | console.log(positionsaver) | ||
- | console.log(" | ||
- | for (var j=0; | ||
- | groupinglisttmp.push(operationseparatedList[j]) | ||
- | console.log(operationseparatedList[j].length) | ||
- | console.log(" | ||
- | } | ||
- | for (var s=0; | ||
- | groupingtmp.push(operationseparatedList[positionsaver][s]) | ||
- | } | ||
- | for (var s=0; | ||
- | groupingtmp.push(operationseparatedList[positionsaver+1][s]) | ||
- | } | ||
- | groupinglisttmp.push(groupingtmp) | ||
- | console.log(" | ||
- | console.log(groupingtmp.length) | ||
- | console.log(" | ||
- | for (var j=positionsaver+2; | ||
- | groupinglisttmp.push(operationseparatedList[j]) | ||
- | console.log(operationseparatedList[j].length) | ||
- | console.log(" | ||
- | } | ||
- | |||
- | if (groupinglisttmp[-1]=undefined){ | ||
- | groupinglisttmp.pop() | ||
- | } | ||
- | operationseparatedCountList=[] | ||
- | for (var t=0; t< | ||
- | operationseparatedCountList[t]=groupinglisttmp[t].length | ||
- | } | ||
- | console.log(" | ||
- | console.log(groupinglisttmp.length) | ||
- | console.log(operationseparatedCountList.length) | ||
- | console.log(operationseparatedCountList) | ||
- | operationseparatedList=groupinglisttmp | ||
- | |||
- | } | ||
- | while(operationseparatedCountList.length> | ||
- | |||
- | |||
- | |||
- | console.log(" | ||
- | console.log(" | ||
- | console.log(separatedCountList) | ||
- | |||
- | var groupingresult=operationseparatedList | ||
- | console.log(" | ||
- | for(var i=0; | ||
- | console.log(groupingresult[i].length) | ||
- | } | ||
- | console.log(groupingresult.length) | ||
- | |||
- | // output file | ||
- | var str="" | ||
- | var strSingleLine="" | ||
- | for (var i=0; | ||
- | var colormark=i+1 | ||
- | for (var j=0; | ||
- | strSingleLine=groupingresult[i][j].toString(); | ||
- | strSingleLine=strSingleLine+' | ||
- | str=str+strSingleLine | ||
- | } | ||
- | } | ||
- | str=str.replace(/,/ | ||
- | fs.writeFile(" | ||
- | if(err){ | ||
- | return console.log(err) | ||
- | } | ||
- | }) | ||
- | |||
- | //find commonness | ||
- | var commonness="" | ||
- | for (var g=0; | ||
- | var commonnessWordPosi=0 | ||
- | var commonnessWordCount=0 | ||
- | var commonnessWordTemp="" | ||
- | console.log(" | ||
- | var commonnessStrTemp="" | ||
- | var commonnessTemp="" | ||
- | do{ | ||
- | commonnessWordCount=0 | ||
- | commonnessWordTemp=groupingresult[g][0][commonnessWordPosi] | ||
- | console.log(commonnessWordTemp) | ||
- | if (commonnessStrTemp=="" | ||
- | commonnessStrTemp=commonnessWordTemp | ||
- | } | ||
- | else{ | ||
- | commonnessStrTemp=commonnessStrTemp+";" | ||
- | } | ||
- | |||
- | for (var species=0; | ||
- | if (groupingresult[g][species][commonnessWordPosi]==commonnessWordTemp){ | ||
- | commonnessWordCount=commonnessWordCount+1 | ||
- | } | ||
- | } | ||
- | console.log(commonnessWordCount) | ||
- | commonnessWordPosi=commonnessWordPosi+1 | ||
- | if (commonnessWordCount!=groupingresult[g].length){ | ||
- | console.log(commonnessStrTemp) | ||
- | //the last word is not common word, so remove it. | ||
- | commonnessTemp=commonnessStrTemp.substring(0, | ||
- | console.log(commonnessTemp) | ||
- | commonness=commonness+(g+1)+' | ||
- | } | ||
- | | ||
- | } | ||
- | while (commonnessWordCount==groupingresult[g].length) | ||
- | } | ||
- | fs.writeFile(" | ||
- | if(err){ | ||
- | return console.log(err) | ||
- | } | ||
- | }) | ||
- | ``` |