Victoria Offord

Victoria Offord

As a Prinicipal Bioinformatician in Experimental Cancer Genetics at the Wellcome Sanger Institute, I develop and run pipelines for saturation mutagenesis, CRISPR screens, RNA-Seq and variant calling.

Location UK

Activity

  • @FaryalYousaf if you paste the script contents, happy to have a look and help debug.

  • Yes, but you would need to give the path to its location.

  • Hi Ege, great question. Yes, you could put it in quotes e.g. 'apple pie' and this should allow for spaces in the user input.

  • Hi Ege, yes, these are covered in more depth in step 2.12. We also skim across it in one of the script comments in 2.11.

  • These need to be considered in relation to your script command. Everything that follows your script (separated by a space) can be considered a positional argument - i.e. when we have "apple pear orange" following our script, apple is the first item ($1), pear is the second item ($2) and orange would be the third item ($3). When we use those predefined...

  • Yes, but you'll want to be cautious and make sure each nested if-else closes where you expect it to. May be worth considering a case statement instead.

  • I'm not sure I've come across anything specifically for comments, but it is possible to change the terminal palette - that will depend on the terminal application. Here is an example for ubuntu (https://itsfoss.com/change-terminal-color-ubuntu/) - there will be similar walkthroughs online for Windows or OSX.

  • A directory is the equivalent of a folder (i.e. a place where you can store objects like files). An argument typically relates to a command and is equivalent to a parameter that you want the program to take in and act on. A directory itself cannot be an argument, but the path to a directory can be a value supplied to an argument.

  • Depends on where you look for the answer - folks seem to debate this. Wikipedia has it as 'print working directory'.

  • Aha! Yes, so those code snippets need to be saved in a file and then executed as a script.

  • @TimothyBAMGBOSE Do you have this at the start of the script?

    #!/usr/bin/env bash

  • @StigPaul - good questions!

    One potential caveat might be if you try setting the value of the global variable in a script or elsewhere, it can be tricky to track back if things go wrong.

    You can use 'unset' followed by the variable name (i.e. unset MY_NAME) to remove/unset the variable.

    Whether it's saved after restart will depend on where you set...

  • @TimothyBAMGBOSE if you copy the contents of the script and the command used to run it into the comments I can have a look and see :)

  • Great question! Unix is quite broadly applicable - not limited to bioinformatics :)

  • @MG I'd assume that without setting a value for temperature, it is always meeting this condition "temperature -lt min_temperature" which gives "Too cold" as a response.

  • @Amie-LouiseHartington I can promise that even a seasoned coder will make syntax errors...and lose hours looking for that one rogue comma or whitespace! I don't know about others, but I often find that it's in making those errors I learn the most :) Great to hear you're learning loads - hope you'll enjoy week 3!

  • You will need to run the function within the bash script only. There are ways to export functions for use in your terminal (outside of a script) but they aren't covered as part of this course :)

  • @YasmienKhodary we'll go into that in more detail in step 2.12 :)

  • @WessalHanout these are covered in more detail in step 2.12 :)

  • @RuthReyes @ZainabKashim-Bello happy to help debug if you copy and paste the script you created with nano :)

  • Looks like Very Good has a space which is confusing the script. Try providing it encased in quotation marks e.g. "Very Good" which should stop it being interpreted as two separate values. Let us know how you get on!

  • Great questions! An argument is a value we provide the script when we execute it on the command line. That value may be stored in a positional variable e.g. $1 or $2. In this script we're reassigning the value to a variable with a more descriptive name (temperature). In this case, temperature is a variable (something assigned a value) in the same way...

  • To access the exported variable in the environment/outside of the script, you would likely need to source the script itself.

  • Absolutely! It's not essential to use .sh as the extension, but as Abdullah rightly says, it's a useful indicator of what's inside the file (and its purpose).

  • It's not essential, but it's probably good practice - especially as you might share your script with someone else who has multiple interpreters installed. :)

  • Good question! It allows you to execute the script without having to add `bash` to the start of your command.

  • @ArkashaSadhewa we don't have to, but it does look cleaner for the user/person seeing it on the command line.

  • Great question!

    Wikipedia has a comparison of the most common shells here:
    https://en.wikipedia.org/wiki/Comparison_of_command_shells

    I'd recommend Bash as it's the default on most Linux distributions and you'll be more likely to find support for it from other informaticians.

  • @RitaHoldhus exactly :)

    Typing 'man echo' (without the quotes) on the command line will give you the manual/documentation for the echo command and explain the various options available.

    There's a good explanation here: https://www.gnu.org/software/bash/manual/html_node/Escape-Character.html

    Common examples would be:

    \n = new line
    \r = carriage...

  • There may be some commands/syntax shared between shells, so it is possible, but probably not recommended.

  • Hi @AsandaGambu, if you copy the contents of the script into the comments, we can try to help debug :)

  • It looks like there may be a missing '/'. Does changing the shebang to /usr/bin/env work?

  • In many ways it's probably personal preference. But the former is probably preferable in situations where you want your scripts accessible on your PATH - for example you could put scripts in a `bin` (or other named) directory, make them executable and then run them without having to either be in that directory or specify their full path. An example of how this...

  • It looks like there may be a rogue quotation mark. Did you want to copy paste your script contents into the comments and we can try to debug?

  • Hi @DianaValencia, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @SARAIMORALESRAMIREZ, , thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @BaoChiWong, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @VITÓRIARODRIGUESGUIMARÃESALVES, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @KylieBalotin, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @PageneckChikondowa, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @AlexandraMilliken, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @SayakaOgawa, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @DayanaNormaAlonsoPalacio, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @KeeleyO'Grady, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @FasilKebede, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @KellyanneT, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @JessicaGumerson, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @KateLines, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @DanielAlpízarPedraza, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @MadeleineAase-Remedios, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @RuthBennett, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • Hi @ElmiraAhmedova, thanks for your comment on our course. We would love to use it to demonstrate the impact of the course. May we have your permission to do this?

  • @JonelleVillar but, could you use functions and within the same script to give you the same flexibility and reduce code duplication?

  • @LucpahNekati you can run 'cat fruits.sh' and then paste the contents of the script into the chat here.

    @SiyabulelaMagugu you'll want to use chmod +x to update the permissions on your script file.

  • @LaszloHegymegi spotted the issue exactly. The -p option requires an argument which means the order needs to be -sp and not -ps.

  • Exactly :) Unless you add them to your profile, they will only persist in your current terminal session.

  • Did you run this as a script?

  • Yes, you'll want to use chmod to change the file permissions if you're wanting to run it with the './<script>' notation

  • @FranziskaMeiners if you want to run ./hello.sh you'll first need to change the file permissions to make it executable with 'chmod +x hello.sh'

  • The syntax and commands may differ between shells. For example, in this course we are writing Bash scripts and so should be using the Bash shell/interpreter.

  • Most scripts (of any language) would likely benefit from some degree of progress tracking.
    Say, for example, we run a script which we expect to finish in an hour. We could go off for some meetings and come back 2 hours later....and the script is still running. How do we know if it's just taking longer than expected or whether something has gone wrong?...

  • @MayteE good spot! They probably should be!

  • @LucpahNekati did you want to pop the contents of fruits.sh on the chat and we can try to help debug?

  • @AlexandraIrrgang are you using a bash shell?

  • @MarziaFaranda that's the shebang which goes at the top of the script and is essentially the location of the bash interpreter. You'll want to put the contents of the script above in a script file and then execute the script rather than running the script contents directly on the command line.

  • @HannahTrivett unfortunately there will be some commands and syntax that will only work with the bash shell.

  • @SayakaOgawa sure :) So one current example I'm working on at the moment has a large matrix of data, >100,000 rows. Now, I could computationally loop and do my calculations sequentially across all of those rows. But, for the calculation I'm doing, it would take a really long time.
    Instead, I've divided that matrix into n chunks, say 20,000 rows. These are...

  • In theory, each is the inverse of the other so it shouldn't matter too much which you use. I tend to use whichever makes the code more readable.

    For example, let's imagine grep doesn't exist. I have a file with 20 fruits in it, one per line and I want to know if peaches is in that list and stop when we find it.

    If you want to use a while loop, it...

  • If you do an 'ls -l' on the Diamonds.csv file, what does that return?

  • @AbelGarcíaDíaz you'll want to combine this with if...else statements. It might help to have a look at the next step and then give this another go as part of a script.

  • @MagdaBenavides you can set username or password as any value, you'll just need to change the values you give the script on the command line when it prompts you.

  • It looks like you may be running the contents of the script with the shebang in the terminal directly which won't work. You'll want to create a new file with nano (or another text editor), add the script contents to that script file and then run the script file.

  • Good question :) Mainly I'd say be careful with the path i.e. /usr/bin which may (but likely won't) vary across systems.

  • To use the './' you'll first need to make the script executable (i.e. change the file permissions) with 'chmod +x'. Until then, the script doesn't have the right permissions to be run as the system expects it to be executable.

    When you run it with 'bash script.sh', the system runs bash and then the script as a command-line argument which doesn't have the...

  • @BrianaPizzano spot on! So the first line is the shebang and it's to tell the system how we want to execute our script - i.e. not a comment.

  • Hi @BrianaPizzano in the example we're using 'chmod +x' which will make the script executable at the user, group and owner level. So this would make it executable for all users. If it helps, you can check to see how the permissions are changing by using 'ls -l' on the file or directory of interest.

  • @AnnaHammond did you want to pop your script contents and how you're running it in the chat and we can try to help debug?

  • Do you have Bash installed and are you using it to run your scripts?

  • It might be worth having a look through some of the comments from fellow learners, there's a couple of insights for this in them.

  • @AlemaoCarpinteyro sounds like it's working as expected :). The shebang will be at the top of your script but not in the script output. The only thing we'd expect to show in your terminal (in this example) is the string (i.e. Hello world!) after the echo command

  • @Sarah-LeeBekaert in the next sections we step through some examples. A common use is checking whether a file exists before reading it or running other applications that use it as an input.

  • @PeteDayananda this worked OK for me. It might be worth double checking you're using the Bash shell.

  • Hi everyone,

    Just a quick note, the conditional expressions you'll be looking at in this step won't work independently and should be used in conjunction with If and If Else statements in the next step.

    Hope this helps!

    Victoria

  • @AinaMoen you'll want to take a look at the next section to be able to use the conditional expressions in conjunction with if statements.

  • Well spotted! We're looking at updating this step so we only reference fruit (and not script). :)

  • @EsterC-J you'll want to create a script (e.g. fruit.sh) using nano which contains the following:

    #!/usr/bin/env bash

    echo "The first fruit is: $1"
    echo "The second fruit is: $2"
    echo "The third fruit is: $3"
    echo "All fruits are: $@"

    When you've saved the script, you can then run it (assuming it was saved as fruit.sh) with:

    chmod +x...

  • @IsabellaB for this step, we're letting the user define the variables when they run the script:

    ./fruit.sh apple pear orange

    We use preset argument variable notation (e.g. $1) to capture the command line input. So with the command above, $1 becomes apple. Equally we could have had:

    ./fruit.sh peach plum grape

    Where $1 becomes peach.

  • @IsabellaB when we use "\n" we're asking for a new line, somewhat like using Enter on the keyboard.

  • @PeteDayananda it might be worth popping the full script contents in the chat which will help us debug.

  • It may be worth checking whether you're using the Bash shell.

  • Generally, decimal and integers shouldn't need quotation marks.

  • @HelenAkinlami not to worry, FutureLearn lets you to go back over the steps from Week 1 which should allow you to catch up :)

  • @RabMcC glad to see this drives others nuts too!

  • @BenjamínValderrama the conditional expressions need to be used with conditional statements. Does looking at the next section help? If not, can you show us the script you're using?

  • @AlexxS the permissions will stay the same when you edit the file.

  • When you set a global variable, you should be able to access it wherever you are on the filesystem. However, to get it to persist across sessions you'll add it to one of the system files such as /etc/profile, ~/.bash_profile, ~/.bashrc.

  • Some will be stored in /etc/environment like the PATH variable, others may be stored in your ~/.bashrc or process-linked. You can display environment variables using the 'env' command.

  • @JamesMunro by default, newly generated files will have only basic permissions (644 I believe). Updating the shebang to #!/usr/bin/env zsh should do the trick. You'll not see any difference in the output. Changing the file extension is more to remind you which shell you're using, it won't change which interpreter is handling the script (unless you also change...

  • @DeclanFlynn In theory, as long as you have permissions on the file or directory you can write and edit files almost anywhere on the filesystem.