Following simple code to list files in a directory is from here:
(Directory name: '.')
allFilesMatching: '*.st'
do: [ :f | (f name) displayNl ]
However, it is not working and giving following error:
$ gst mysrc.st
Object: Directory error: did not understand #name:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Directory class(Object)>>doesNotUnderstand: #name: (SysExcept.st:1448)
UndefinedObject>>executeStatements (firstline.st:1)
I am working on GNU Smalltalk version 3.2.5 on Debian Stable Linux.
Where is the problem and how can it be solved?
I don't know who has written it on the rosettacode, but the #name: selector is incorrect (does not exist in the Directory class). If you check the Directory class you won't find such selector there. Instead you will find a #working: selector. The selector has a description:
working: dirName
Change the current working directory to dirName.
Your code will then look like this:
(Directory working: '.') allFilesMatching: '*.st' do: [ :f |
(f name) displayNl
]
Related
I have written a snakemake code to run bwa_map. Fastq files are with different folder name and different sample name (paired end). It shows error as 'SAMPLES' is not defined. Please help.
Error:
$snakemake --snakefile rnaseq.smk mapped_reads/EZ-123-B_IGO_08138_J_2_S101_R2_001.bam -np
*NameError in line 2 of /Users/singhh5/Desktop/tutorial/rnaseq.smk:
name 'SAMPLES' is not defined
File "/Users/singhh5/Desktop/tutorial/rnaseq.smk", line 2, in *
#SAMPLE DIRECTORY
fastq
Sample_EZ-123-B_IGO_08138_J_2
EZ-123-B_IGO_08138_J_2_S101_R1_001.fastq.gz
EZ-123-B_IGO_08138_J_2_S101_R2_001.fastq.gz
Sample_EZ-123-B_IGO_08138_J_4
EZ-124-B_IGO_08138_J_4_S29_R1_001.fastq.gz
EZ-124-B_IGO_08138_J_4_S29_R2_001.fastq.gz
#My Code
expand("~/Desktop/{sample}/{rep}.fastq.gz", sample=SAMPLES)
rule bwa_map:
input:
"data/genome.fa",
"fastq/{sample}/{rep}.fastq"
conda:
"env.yaml"
output:
"mapped_reads/{rep}.bam"
threads: 8
shell:
"bwa mem {input} | samtools view -Sb -> {output}"
The specific error you are seeing is because the variable SAMPLES isn't set to anything before you use it in expand.
Some other issues you may run into:
Output file is missing the {sample} wildcard.
The value of threads isn't passed into bwa or samtools
You should place your expand into the input directive of the first rule in your snakefile, typically called all to properly request the files from bwa_map.
You aren't pairing your reads (R1 and R2) in bwa.
You should look around stackoverflow or some github projects for similar rules to give you inspiration on how to do this mapping.
I'm trying to implement the touch command from the unix command line, but it seems that my last line throws an exception: ** Exception: ~/.todo: openFile: does not exist (No such file or directory)
main = touch "~/.todo"
touch :: FilePath -> IO ()
touch name = do
exists <- doesFileExist name
unless exists $ appendFile name ""
If there is any OS specific behavior, I'm testing from macOS Sierra.
I feel as if this error is strange in that the documentation for openFile states that
If the file does not exist and it is opened for output, it should be created as a new file.
Any suggestions as to how to fix this?
Edit: According to #chi, the touch command should always open the file, even if it already exists, because it will then update the file's last modified date.
touch :: FilePath -> IO ()
touch name = appendFile name ""
Use touchFile from the unix package (System.Posix.Files.ByteString).
appendFile name "" does not work like touch; appendFile is a no-op when the string to append is empty.
You can confirm this by running stat on the file before and after and comparing the modification times.
In the future please paste all the code you are using that creates the error. This includes both the imports and the invocation. In your case it seems you are running something with a shell expansion character:
*Main> touch "~/foobar"
*** Exception: ~/foobar: openFile: does not exist (No such file or directory)
The ~ is typically expanded by a shell (there also exists a C library that can do that rewriting for you). Most languages actually interpret that as a literal part of the path... but the ~ directory probably doesn't exist or that symbol might not even be valid depending on your platform.
Instead try a valid file path:
*Main> touch "/tmp/thisfile"
*Main>
Leaving GHCi.
% ls -l /tmp/thisfile
-rw-rw-r--. 1 theuser theuser 0 Feb 3 12:51 /tmp/thisfile
I'm trying to read a filepath from a config file and then read from that directory. I can't find a way to make it work though, because for some reason change-dir never goes to an absolute filepath. Here's a transcript of me trying to make it work on the CLI.
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! test
== %C/Users/thompson/Downloads/
>> change-dir test
** Access Error: Cannot open /C/rscratch/C/Users/thompson/Downloads/
** Near: change-dir test
It's failing because Rebol does not see
%C/Users/thompson/Downloads/
as an absolute path - it is missing the magic leading slash, so is seen as a relative path. Absolute path is this:
%/C/Users/thompson/Downloads/
So easy fix, if you are sure you do not have that leading slash:
>> test: pick read/lines %test.ini 1
== "test: C/Users/thompson/Downloads/"
>> test: find test " "
== " C/Users/thompson/Downloads/"
>> test: next test
== "C/Users/thompson/Downloads/"
>> test: to file! join "/" test
There are many ways how get to an absolute Rebol file path,
the Rebol way
test: "test: %/C/Users/thompson/Downloads/"
select load test [test:]
the linux way
test: "test: /C/Users/thompson/Downloads/"
to-file trim find/tail test "test:"
the Windows way
test: "test: C:/Users/thompson/Downloads/"
to-rebol-file trim find/tail test "test:"
You will always get %/C/Users/thompson/Downloads/
Found an effective workaround.
changeDirAbsolute: func [input] [
change-dir %/
change-dir input
]
If anyone has a more elegant solution I'm open to hearing it!
In Rebol, because code is data and data is code, you can represent your .ini files by Rebol code. Incidentally, I and many others who are not Windows-centric prefer to use .cfg as the extension for these types of files. .ini refers to "initialization" which in many minds refers to the booting of a system, but could also refer to the starting of a program. .cfg is a little more precise in that it is a configuration file for a program.
With that said, try this instead:
test.cfg:
test: %/c/users/thompson/downloads
Then, you can simply do this from within your program:
>> do %test.cfg
That will automatically populate the filepath into the word 'test.
In non-Windows based operating systems, most often a filepath starts with a / when it refers to the root level of the filesystem. If it doesn't start with a /, it is a relative path (starting from the current directory).
I hope this helps!
Sorry, I'm new to sbt and the "sbt-native-packager". What I need to do is to map whole directories to the .zip file and change the output path.
This how I've done my mapping of the directory:
mappings in Universal <++= (packageBin in Compile, baseDirectory ) map { (_, baseDirectory) =>
val dir = baseDirectory / "migrations"
(dir.***) pair relativeTo(dir.getParentFile)
}
The mapping works perfectly fine, but I need to have a specific folder structure in the resulting .zip file.
In this example this directory is mapped to ".../target/stage/universal/migrations" but I need it to be mapped into a folder "db" like this: ".../target/stage/db/universal/migrations"
Many thanks in advance!
For mapping complete directories there are some MappingHelpers you can use. Your code can be simplified to
mappings in Universal ++= directory(baseDirectory.value / "migrations")
Regarding your second question, how to change the output folder. The question is not quite correct, as it should be: "how to change the destination path of a mapping". The universal packaging is a bit special as the target ouput looks like the resulting package.
Native packager uses mappings (sequence of File -> String tuples) that define a file and the corresponding output path in the resulting package. So if you want to change
# current
./target/stage/universal/migrations
# expected
./target/stage/db/universal/migrations
I assume you want the migrations in your zip file in a db folder like this
/ # zip root
bin/ # start scripts
db/ # migrations go here
conf/ # configuration files
lib/ # jars
In order to accomplish this you have to change the destination string. This would look something like this ( not tested ):
mappings in Universal ++= contentOf(baseDirectory.value / "migrations").map {
case (file, dest) => file -> s"db/$dest"
}
cheers,
Muki
Often I get the following error message when certifying ACL2 books:
| ACL2 Error in ( INCLUDE-BOOK "something" ...): The ttag :FAST-CAT
| associated with file /elided/acl2/books/std/string\
| s/fast-cat.lisp is not among the set of ttags permitted in the current
| context, specified as follows:
| NIL.
| See :DOC defttag.
What's wrong?
One needs to add a <something>.acl2 file (typically cert.acl2 works just fine) to the directory that contains the book you're trying to certify. This <something>.acl2 file needs to direct cert.pl that ttags are okay to use, e.g., with the following code:
(in-package "ACL2")
; cert-flags: ? t :ttags :all