I have 2 txt files that contain 500 DNA sequences each. Both files use 2 hard returns to separate the sequences like so:
ATCGATCT...
ATCGATCT...
ATCGATCT...
I want to parse these two files into the Classify function such that each item in the txt file is assigned a class, Gene1
and Gene2
. I have already separated the two classes of DNA in their respective txt files.
Because of this, I was thinking I can classify all the items in txt1
as Gene1
and all the items in txt2
as Gene2
. As for how to do this, I am not sure. Does Mathematica allow parsing of items from a txt file into the Classify function?
I was hoping it would be a simple line of code such as this:
c = Classify[{Import["txt1.txt"]} -> "Gene1", {Import["txt2.txt"]} -> "Gene2"]
c = Classify[Join@@Map[Thread[StringSplit[Import["txt"<>#<>".txt"], "\n"]-> "Gene"<>#]&, ToString/@Range[2]]]
? $\endgroup$<>#
symbols in[Import["txt" <> # <> ".txt"], "\n"] -> "Gene" <> #] &, ToString /@ Range[2]]
means. Also, why are you using@Range[2]
? $\endgroup$<>
is Mathematica shorthand forStringJoin
and#
is shorthand forSlot
in aFunction
(worth looking all these terms up in the docs as understanding them will be very helpful moving forward). Pro-tip: you can select a symbol and use Command-Shift-F (or Control-F1 on Windows) to look up what it does. $\endgroup$Import["txt"<>#<>".txt"], "\n"]
. Does"\n"
tell the function that 1 hard enter signifies the separation between each item in the txt file? I am also not sure where I input the filepath for the 2 txt files. I thought I enter the filepaths in the"txt"
sections like soImport["C:\\filepath\\test1.txt"<>#<>"C:\\filepath\\test2.txt"]
, but this gives me aFile not found during import
error. Thank you for your help in advance! $\endgroup$