Last active
June 10, 2023 06:33
-
-
Save rebekah/1a7470de8665935eae8281c1776eb88e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S scala-cli shebang | |
import java.io.{ File, FileInputStream, FileWriter, BufferedWriter } | |
import scala.io.BufferedSource | |
/** | |
* MEME File Example | |
* | |
* ... | |
* MOTIF Hsapiens-jaspar2022-MAX::MYC-MA0059.1 | |
* letter-probability matrix: alength= 4 w= 11 nsites= 45 E=0.000000 | |
* 0.3333333333 0.0476190476 0.4285714286 0.1904761905 | |
* 0.7142857143 0.0476190476 0.1904761905 0.0476190476 | |
* 0.0952380952 0.4285714286 0.4285714286 0.0476190476 | |
* | |
* MOTIF Hsapiens-jaspar2022-PPARG-MA0066.1 | |
* letter-probability matrix: alength= 4 w= 20 nsites= 45 E=0.000000 | |
* 0.1071428571 0.2857142857 0.5000000000 0.1071428571 | |
* 0.1071428571 0.0000000000 0.0000000000 0.8928571429 | |
* 0.6785714286 0.0000000000 0.3214285714 0.0000000000 | |
* 0.0000000000 0.0357142857 0.9642857143 0.0000000000 | |
* ... | |
*/ | |
val memeFilein = new File("jaspar2022-human.txt") | |
val memeReader = new BufferedSource(new FileInputStream(memeFilein)) | |
/** | |
* Transcription Factor File Example | |
* | |
* ... | |
* ZBTB7B | |
* MEF2D | |
* ETV3 | |
* USF1 | |
* ATF6 | |
* PBX1 | |
* POU2F1 | |
* TBX19 | |
* PRRX1 | |
* ... | |
*/ | |
val tFsFilein = new File("tfMicroglia.txt") | |
val tFsReader = new BufferedSource(new FileInputStream(tFsFilein)) | |
val fileWriter = new FileWriter("writeToMe.txt") | |
val bufferedWriter = new BufferedWriter(fileWriter) | |
val memeFileLines = memeReader.getLines.toList | |
val tFs = tFsReader.getLines.toList | |
def processMemeList(processed: List[String], unprocessed: List[String], keep: Boolean): List[String] = { | |
unprocessed match { | |
case Nil => processed | |
case x::xs => { | |
val newProcessed = processed :+ x | |
if x.contains("MOTIF") then { | |
val transcriptionFactor = x.split("-")(2) | |
if tFs.contains(transcriptionFactor) then { | |
processMemeList(newProcessed, xs, true) | |
} else { | |
processMemeList(processed, xs, false) | |
} | |
} else { | |
keep match { | |
case true => processMemeList(newProcessed, xs, true) | |
case false => processMemeList(processed, xs, false) | |
} | |
} | |
} | |
} | |
} | |
processMemeList(List[String]().empty, memeFileLines, true) | |
.foreach{line => bufferedWriter.write(line + "\n")} | |
bufferedWriter.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment