bwa fail to load index using nextflow - mapping

I am writing a bwa mapping module using nextflow (dsl=2), modules/map_reads.nf to map single-end reads. When I execute this workflow it does not return error from the terminal and it also output bam files with the correct file names. However, I found that the bam files are not correctly mapped and I also found in .command.err an error:
[E::bwa_idx_load_from_disk] fail to locate the index files
I have checked the paths are correct and also execute shell command directly in terminal.
I appreciate any suggestions or solution to this problem.
modules/map_reads.nf
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
process mapping {
conda 'envs/bwa.yml'
publishDir 'results/mapped', mode: 'copy'
input:
tuple val(sample_id), file(fastq)
file index
output:
tuple val(sample_id), file('*.bam')
script:
"""
bwa mem $index $fastq | samtools view -b - > ${sample_id}.bam
"""
}
workflow {
fastq_data = channel.fromPath( 'data/samples/*.fastq' ).map { file -> tuple(file.baseName, file) }
index = channel.fromPath( 'data/genome.fa' )
mapping( fastq_data, index )
}
Here is my directory structure:
envs/bwa.yml
name: bwa
channels:
- bioconda
- defaults
dependencies:
- bwa
- samtools=1.9

[E::bwa_idx_load_from_disk] fail to locate the index files
BWA MEM is expecting a number of index files to be provided with it's first argument, but you've only localized the genome FASTA file:
index = channel.fromPath( 'data/genome.fa' )
BWA MEM only requires the actual index files. I.e. it doesn't require the FASTA file (or FASTA index), so you can save some time and resources by skipping the localization of the FASTA (this is especially relevant if you localize from s3 for example, since the FASTA file is often a couple of gigabytes). Also ensure you use a value channel here, so that the channel can be used an unlimited number of times:
process mapping {
conda 'envs/bwa.yml'
publishDir 'results/mapped', mode: 'copy'
input:
tuple val(sample_id), path(fastq)
path bwa_index
output:
tuple val(sample_id), path("${sample_id}.bam")
script:
def idxbase = bwa_index[0].baseName
"""
bwa mem "${idxbase}" "${fastq}" | samtools view -b - > "${sample_id}.bam"
"""
}
workflow {
fastq_data = channel.fromPath( 'data/samples/*.fastq' ).map { file ->
tuple(file.baseName, file)
}
bwa_index = file( 'data/genome.fa.{,amb,ann,bwt,pac,sa}' )
mapping( fastq_data, bwa_index )
}
Also, the reason you didn't see an error on the command line is that, by default, the return value of a pipeline is the exit status of the last command. In your BWA MEM SAMtools pipeline, the last command (i.e. samtools) completes successfully and returns exit status zero. The option you want to add is called 'pipefail', man bash:
pipefail
If set, the return value of a pipeline is the value of the
last (rightmost) command to exit with a non-zero status, or zero if
all commands in the pipeline exit successfully. This option is
disabled by default.
Usually, you can just add the following to your nextflow.config to have it applied to all processes:
process {
shell = [ '/bin/bash', '-euo', 'pipefail' ]
}

Related

Use fdfind and fzf to open files in mpv

kdialog-open-files.lua and zenity-open-files.lua are two projects that use KDE KDialog and Gnome's zenity respectively to open files in mpv. I wish to do the same using fdfind and fzf.
As illustrated in this stackoverflow answer the following works and will be our starting point:
fdfind . /path/to/Music | fzf -m | xargs -d "\n" mpv
We can use the above command to select some files and play them using mpv. However we want a dialog to be created for our file selection. To do this, we create a bash script menu_fzf.sh with the following contents:
#!/bin/bash
urxvt -name fzf_menu -e bash -c "fzf -m $* < /proc/$$/fd/0 > /proc/$$/fd/1"
(urxvt is only an example and any other suitable terminal emulator can be used in the above).
Now if we run:
fdfind . /path/to/Music | menu_fzf.sh
then a new terminal opens that lets you pick multiple files from /path/to/Music with fzf and will return the selection as output to the calling terminal. So in fact right now we could run the following
fdfind . /path/to/Music | menu_fzf.sh | xargs -d "\n" mpv
and it will play the selected files in mpv. So far so good!
The tricky part now is how to do all the above using lua scripts from within mpv. By looking at the kdialog-open-files.lua or zenity-open-files.lua it seems I need to write something like this:
utils = require 'mp.utils'
-- TODO: make the following work so that file_select correctly stores
-- the files selected using menu_fzf.sh:
file_select = utils.subprocess({
args = {'command', 'argument1', 'argument2', 'and so on'},
cancellable = false,
})
-- and then the rest of the code from kdialog-open-files.lua
However I am finding the official manual for utils.subprocess to be terse and inadequate. I have creatively tried picking command, argument1, argument2, and so on in the above, but nothing seems to work!
So I have two questions:
Can you (please) complete the above code template into a working solution?
Do you know where I can find more information on utils.subprocess? Is there a more detailed manual somewhere? Where is the source-code?
Remark: As I have never programmed in lua before I am struggling with solving question-1 above and will probably continue to struggle even if I had the source code for utils.subprocess. So really help with question-1 is of higher priority. But any help with question-2 is also great!
My failed attempts so far:
The following will append all files in current directory to playlist:
file_select = utils.subprocess({
args = {'fdfind', '.', directory},
cancellable = false,
})
The following fails:
file_select = utils.subprocess({
args = {'fdfind', '.', directory, '|', 'fzf'},
cancellable = false,
})
with error message:
[open_files] [fd error]: Search path '|' is not a directory.
[open_files] [fd error]: Search path 'fzf' is not a directory.
The following allows selecting multiple files from $HOME directory but (as expected) does not return the selection:
file_select = utils.subprocess({
args = {'urxvt','-e','fzf', '-m'},
cancellable = false,
})
The following doesn't work:
file_select = utils.subprocess({
args = {'urxvt','-e','fzf', '-m', '>', '/proc/$$/fd/1'},
cancellable = false,
})
The following opens up a new dialog with fzf but has nothing to select from:
file_select = utils.subprocess({
args = {'menu_fzf.sh'},
cancellable = false,
})
Create a bash script mpv_fzf_menu.sh with the following content:
#!/bin/bash
urxvt -name fzf_menu -e bash -c "fdfind . "$1" | fzf -m > /proc/$$/fd/1"
Create a lua file open-files.lua with the following content:
utils = require 'mp.utils'
function select_files_dmenu_fzf()
if mp.get_property("path") == nill then
directory = ""
else
directory = utils.split_path(utils.join_path(mp.get_property("working-directory"), mp.get_property("path")))
end
file_select = utils.subprocess({
args = {'mpv_fzf_menu.sh', directory},
cancellable = false,
})
end
function add_files()
select_files_dmenu_fzf()
if (file_select.status ~= 0) then return end
local first_file = true
for filename in string.gmatch(file_select.stdout, '[^\n]+') do
mp.commandv('loadfile', filename, first_file and 'replace' or 'append')
first_file = false
end
end
mp.add_key_binding("Ctrl+f", "add-files-kdialog", add_files)
(I am assuming you know what to do next: make the bash script executable and put it somewhere where bash finds it in its $PATH. Put the lua script in .config/mpv/scripts and everything should work, i.e. - when you press Ctrl+f within mpv a dialog should open to let you select files).
Remark: All the functionalities of kdialog-open-files.lua have not been implemented. But the above lua script can be easily extended. You can further make things fancy by filtering for files with the specified extension with fdfind. And you can also use the bash script independent of the lua script. If you configure the --preview option of fzf then you can get a file preview before making selection.

Parsing config file with sections in Jenkins Pipeline and get specific section

I have to parse a config with section values in Jenkins Pipeline . Below is the example config file
[deployment]
10.7.1.14
[control]
10.7.1.22
10.7.1.41
10.7.1.17
[worker]
10.7.1.45
10.7.1.42
10.7.1.49
10.7.1.43
10.7.1.39
[edge]
10.7.1.13
Expected Output:
control1 = 10.7.1.17 ,control2 = 10.7.1.22 ,control3 = 10.7.1.41
I tried the below code in my Jenkins Pipeline script section . But it seems to be incorrect function to use
def cluster_details = readProperties interpolate: true, file: 'inventory'
echo cluster_details
def Var1= cluster_details['control']
echo "Var1=${Var1}"
Could you please help me with the approach to achieve the expected result
Regarding to documentation readProperties is to read Java properties file. But not INI files.
https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readproperties-read-properties-from-files-in-the-workspace-or-text
I think to read INI file you have find available library for that,
e.g. https://ourcodeworld.com/articles/read/839/how-to-read-parse-from-and-write-to-ini-files-easily-in-java
Hi i got the solution for the problem
control_nodes = sh (script: """
manish=\$(ansible control -i inventory --list-host |sort -t . -g -k1,1 -k2,2 -k3,3 -k4,4 |awk '{if(NR>1)print}' |awk '{\$1=\$1;print}') ; \
echo \$manish
""",returnStdout: true).trim()
echo "Cluster Control Nodes are : ${control_nodes}"
def (control_ip1,control_ip2,control_ip3) = control_nodes.split(' ')
//println c1 // this also works
echo "Control 1: ${control_ip1}"
echo "Control 2: ${control_ip2}"
echo "Control 3: ${control_ip3}"
Explaination:
In the script section . I am getting the list of hostnames.Using sort i am sorting the hostname based on dot(.) delimeter. then using awk removing the first line in output. Using the later awk i am removing the leading white spaces.
Using returnStdout to save the shell variable output to jenkins property, which has list of ips separated by white space.
Now once i have the values in jenkins property variable, extracting the individual IPs using split methods.
Hope it helps.

Cannot get Description field of a Jenkins Job or Parameter

Is it possible to obtain the Job Description or the Job Parameter Description in run-time or later like the BUILD_ID or JOB_NAME?
I search for plugins or workarounds and nothing.
Thanks.
This would be Tip/workaround
https://<<yourjenkinsdomain>>/job/<<yourjobname>>/configure (will open the configuration of your job)
However
https://<<yourjenkinsdomain>>/job/<<yourjobname>>/config.xml (will give the job configuration in an xml format)
You can download this xml via curl at run time or using jenkins cli and use a grep with -B option to find description per value.
Considering you have copied the with name "config.xml"
cat config.xml | grep -B 1 "description"
Will give you description and build parameter name
Grep command
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines.
Places a line containing a group separator (--) between
contiguous groups of matches. With the -o or --only-matching
option, this has no effect and a warning is given.
Sample output :
cat config.xml | grep -B 1 "description"
<actions/>
<description>Job description : Automation </description>
--
<name>branch</name>
<description>mandatory parameter , used for automation</description>
--
Alternative :
jenkins cli has an option to set value
set-build-description Sets the description of a build.
set-build-parameter Update/set the build parameter of the current build in progress. [deprecated]
you can write a small script and get the values into variables and use them

Setting environment variables in Flutter

For example, building a client for an API, like Twitch.
In a Dart CLI binary, I could use a generic environment variable, or a Dart definition variable. For example, using both as fallbacks:
main() {
String clientId =
// dart -dCLIENT_ID='abc bin/example.dart
// This is considered "compiled-into" the application.
const String.fromEnvironment('CLIENT_ID') ??
// CLIENT_ID='abc' dart bin/example.dart
// This is considered a runtime flag.
Platform.environment['CLIENT_ID'];
// Use clientId.
}
Does Flutter have a way of setting either/both of these, specifically...
During dev time
When shipped to prod
Happy to help with some docs once I figure out how :)
Starting from Flutter 1.17 you can define compile-time variables if you want to.
To do so just use --dart-define argument during flutter run or flutter build
If you need to pass multiple key-value pairs, just define --dart-define multiple times:
flutter run --dart-define=SOME_VAR=SOME_VALUE --dart-define=OTHER_VAR=OTHER_VALUE
and then, anywhere in your code you can use them like:
const SOME_VAR = String.fromEnvironment('SOME_VAR', defaultValue: 'SOME_DEFAULT_VALUE');
const OTHER_VAR = String.fromEnvironment('OTHER_VAR', defaultValue: 'OTHER_DEFAULT_VALUE');
Also, they can be used in native layers too.
Here is an article that explains more.
For configuration a common pattern I've seen is to use separate main files instead. i.e.
flutter run -t lib/production_main.dart
and
flutter build apk -t lib/debug_main.dart
And then in those different main files set up the configurations desired.
In terms of reading ids, you can do that from arbitrary assets https://flutter.io/assets-and-images/.
I believe it is possible in Flutter to read from the environment as you suggest, however I don't know how to set those environment variables on iOS or Android.
Since I was trying to solve this as well and encountered this thread I just wanted to add this for people looking for a solution in the future... If all you're looking for is PROD/DEV environments there is now a supported way of getting if the app is in production or not:
const bool isProduction = bool.fromEnvironment('dart.vm.product');
As suggested by:
https://twitter.com/FlutterDev/status/1048278525432791041
https://github.com/flutter/flutter/issues/4014
To run your app (in flutter run)
flutter run --dart-define=EXAMPLE_API_ENDPOINT=https://api.example.com/
To release your app (in flutter build)
My app wasn't letting users log in I realized that environment variables were empty strings in the app, instead of their actual values 😅.
iOS: flutter build ipa --dart-define=EXAMPLE_API_ENDPOINT=https://api.example.com/
Android: flutter build apk --dart-define=EXAMPLE_API_ENDPOINT=https://api.example.com/
--dart-define documentation
From the flutter run --help or flutter build ipa --help, the --dart-define shows:
Additional key-value pairs that will be available as
constants from the String.fromEnvironment, bool.fromEnvironment,
int.fromEnvironment, and double.fromEnvironment constructors.
Multiple defines can be passed by repeating "--dart-define"
multiple times.
I use simple shell script to generate dart defines. In my app there are 3 build flavors: dev, staging and prod. Environment variables were defined in a regular .env file.
env/
├── dev.env
├── prod.env
└── staging.env
Here is the script to generate dart-defines from .env file.
#!/bin/bash
# scripts/generate_dart_defines.sh
case "$1" in
"dev") INPUT="env/dev.env"
;;
"staging") INPUT="env/staging.env"
;;
"prod") INPUT="env/prod.env"
;;
*)
echo "Missing arguments [dev|staging|prod]"
exit 1
;;
esac
while IFS= read -r line
do
DART_DEFINES="$DART_DEFINES--dart-define=$line "
done < "$INPUT"
echo "$DART_DEFINES"
Here is the script to trigger a build.
#!/bin/bash
# build.sh
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo -e "Missing arguments: [apk|appbundle|ios] [release|debug|profile] [dev|staging|prod]"
# invalid arguments
exit 128
fi
DART_DEFINES=$(scripts/generate_dart_defines.sh $3)
if [ $? -ne 0 ]; then
echo -e "Failed to generate dart defines"
exit 1
fi
echo -e "artifact: $1, type: $2, flavor: $3\n"
echo -e "DART_DEFINES: $DART_DEFINES\n"
eval "flutter build $1 --$2 --flavor $3 $DART_DEFINES"
The script accepts 3 arguments. First one is the artifact apk, appbundle or ios. Second one is the build type release, debug or profile. Third one is the build flavor, dev, staging or prod.
./build.sh apk release prod
Please note that you also required to configure android and ios for different build flavors separately.
https://developer.android.com/studio/build/build-variants
https://shockoe.com/ideas/development/how-to-setup-configurations-and-schemes-in-xcode/
https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ManagingSchemes.html
I do agree with the answer posted by #tatsuDn but I wanted to provide a solution that loads your environment variables from a .env file.
First create a .env file in the root folder of your project.
Ensure that you add the file to your pubspec.yaml and [git] ignore it.
Here is how your .env file should look
API_KEY=sampleapikey
# This line is a comment
# The white line above will be ignored
HEADER=sampleapiheader
ANOTHER_UNIQUE_KEY=theValueOfThisKey
KEY_CONTAINS_#=*234*5#
KEY_CONTAINS_EQUALS=IP8iwe=0&
Here is how your assets section to look like.
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/flags/
- .env
Finally, load your environment variable by reading and parsing the .env file to get a Map<String, String> that contains your key value pairs.
Future<Map<String, String>> parseStringToMap({String assetsFileName = '.env'}) async {
final lines = await rootBundle.loadString(assetsFileName);
Map<String, String> environment = {};
for (String line in lines.split('\n')) {
line = line.trim();
if (line.contains('=') //Set Key Value Pairs on lines separated by =
&&
!line.startsWith(RegExp(r'=|#'))) {
//No need to add emty keys and remove comments
List<String> contents = line.split('=');
environment[contents[0]] = contents.sublist(1).join('=');
}
}
return environment;
}
You can put a quick button in your code to test that the environment variables are being loaded properly.
ElevatedButton(
onPressed: () async {
final env = await parseStringToMap(assetsFileName: '.env');
print(env);
},
child: Text('Print Environment Variables')
),
Here is the output from the .env file above.
>>>I/flutter ( 7182): {API_KEY: sampleapikey, HEADER: sampleapiheader, ANOTHER_UNIQUE_KEY: theValueOfThisKey, KEY_CONTAINS_#: *234*5#, KEY_CONTAINS_EQUALS: IP8iwe=0&}
Notes: You will need to rerun the app (not hot reload) so that the .env assets is loaded.
You can also just load your variables in a json file[this may be helpful when you have non string environemental variables and you dont want to parse string.
To avaoid IO, it is a good Idea to just load the environment variables once and access them through out the app using service locators like GetIt.
although above answers are correct coming from python and reactjs I used dotenv and found the same for flutter to load .env file
https://pub.dev/packages/dotenv
Create a class:
import 'package:flutter/foundation.dart';
class AppUtils {
static String get clientId {
if (kDebugMode) return 'debug_id';
else if (kProfileMode) return 'profile_id';
else if (kReleaseMode) return 'production_id';
else if (kIsWeb) return 'web_mode_id';
throw ArgumentError('No mode detected');
}
}
Usage:
var id = AppUtils.clientId;

waff wiki function in ns-3 does not get parameters

In ns-3 simulator documentation they provide a simple bash function to ease your life:
function waff {
CWD="$PWD"
cd $NS3DIR
./waf --cwd="$CWD" $*
cd -
}
This function is supposed to execute the ./waf program situated in the ns-3 root folder but inside the folder you are actually situated into.
So in the case of ~/project$ waff --run first waf will run the first script in the ~/project folder.
But if I try to run any simulation by adding one parameter to the script's command like ~/project$ waff --run "first --PrintHelp" it throws an error
waf: error: no such option: --PrintHelp.
It only works when I actually run the scripts from the root folder without the waff function.
How to modify the function to make it expand the $* to an argument between double commas?
Well, I feel embarrased because the solution was way easier than expected.
If anyone using DCE has the same problem, it's as easy as quoting the $*:
./waf --cwd="$CWD" $*
with:
./waf --cwd="$CWD" "$*"
This function works for me with bash (supposed you defined the environment variable $NS3DIR) :
function waff {
CWD="$PWD"
cd $NS3DIR >/dev/null
./waf --cwd="$CWD" "$#"
cd - >/dev/null
}
Proof it works is :
$ waff --run "wifi-simple-adhoc --help"
Waf: Entering directory `/home'
Waf: Leaving directory `/home'
'build' finished successfully (2.013s)
ns3.22-wifi-simple-adhoc-debug [Program Arguments] [General Arguments]
Program Arguments:
--phyMode: Wifi Phy mode [DsssRate1Mbps]
--rss: received signal strength [-80]
--packetSize: size of application packet sent [1000]
--numPackets: number of packets generated [1]
--interval: interval (seconds) between packets [1]
--verbose: turn on all WifiNetDevice log components [false]
General Arguments:
--PrintGlobals: Print the list of globals.
--PrintGroups: Print the list of groups.
--PrintGroup=[group]: Print all TypeIds of group.
--PrintTypeIds: Print all TypeIds.
--PrintAttributes=[typeid]: Print all attributes of typeid.
--PrintHelp: Print this help message.
$ waff --run wifi-simple-adhoc --command-template=" %s --help"
Waf: Entering directory `/home'
Waf: Leaving directory `/home'
'build' finished successfully (1.816s)
ns3.22-wifi-simple-adhoc-debug [Program Arguments] [General Arguments]
Program Arguments:
--phyMode: Wifi Phy mode [DsssRate1Mbps]
--rss: received signal strength [-80]
--packetSize: size of application packet sent [1000]
--numPackets: number of packets generated [1]
--interval: interval (seconds) between packets [1]
--verbose: turn on all WifiNetDevice log components [false]
General Arguments:
--PrintGlobals: Print the list of globals.
--PrintGroups: Print the list of groups.
--PrintGroup=[group]: Print all TypeIds of group.
--PrintTypeIds: Print all TypeIds.
--PrintAttributes=[typeid]: Print all attributes of typeid.
--PrintHelp: Print this help message.

Resources