0

Having a sets of matched files in a folder, the name of each pair of files is like this with a basename, for instance

LP6005334-DNA_H01_vs_LP6005333-DNA_H01.passed.somatic.indels.vcf.parsed.txt

and

LP6005334-DNA_H01_vs_LP6005333-DNA_H01.passed.somatic.indels.vcf_fixed_vcf.txt.hg19_multianno.txt

How I can extract columns 5th and 6th from files with passed.somatic.indels.vcf.parsed in their file name and append these columns to the matched file (passed.somatic.indels.vcf_fixed_vcf.txt.hg19_multianno) returning an output .txt with the basename (LP6005334-DNA_H01_vs_LP6005333-DNA_H01)

For cutting the columns I done

[

fi1d18@cyan01 folder]$ for f in *.passed.somatic.indels.vcf.parsed.txt; do awk '{print $5,$6}' $f > $out
> done;
-bash: $out: ambiguous redirect

Hereafter I don't know how to find the matched find and append the cut columns to that

This is the link of a pair of these files

https://www.dropbox.com/s/y4jx1rznswqz6dq/LP6008460-DNA_G03_vs_LP6008340-DNA_C05__pv.1.7__rg.grch37_g1k__al.bwa_mem__.passed.somatic.indels.vcf_fixed_vcf.txt.hg19_multianno.txt?dl=0

and

1 Answer 1

2

It depends how your files are delimited, but you should be able to use something like

for f in *.vcf.parsed.txt; do 
  cut -f3,4 "$f" | paste "${f%.parsed.txt}_fixed_vcf.txt.hg19_multianno.txt" - > "${f%%.*}.txt"
done

The expansions ${f%.parsed.txt} and ${f%%.*} remove, respectively, the shortest and longest "dot suffixes" from the looped filename.


For the file pair

LP6008336-DNA_H02_vs_LP6008333-DNA_H02.snp.pass.txt                     
LP6008336-DNA_H02_vs_LP6008333-DNA_H02.snp.pass.txt.hg19_multianno.txt

which don't conform to the naming convention in your original question, you will need to change the pattern matches accordingly

ex.

for f in *.pass.txt; do
    cut -f60,61 "$f" | paste "$f.hg19_multianno.txt" - > "${f%%.*}.txt"; 
done
6
  • 1
    @Angel are the files named exactly as mentioned in your question? You seem to be inconsistent about whether they have a .txt extension or not. Jan 17, 2020 at 16:59
  • 1
    @Angel I really strongly urge you to get used to using .vcf as the file extension and not .txt. As I told you over at Bioinformatics, the extension is usually irrelevant on Linux systems, but there are some tools that expect a .vcf or .vcf.gz extension.
    – terdon
    Jan 17, 2020 at 17:13
  • 1
    @Angel I really strongly urge you to get used to using .vcf as the file extension and not .txt. As I told you over at Bioinformatics, the extension is usually irrelevant on Linux systems, but there are some tools that expect a .vcf or .vcf.gz extension.
    – terdon
    Jan 17, 2020 at 17:13
  • 1
    @Angel I have updated the answer with the clarified filenames Jan 17, 2020 at 18:02
  • 1
    @Angel if you change the naming convention of the files, then you will need to adjust the command to match - see updated answer Jan 18, 2020 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .