2
$\begingroup$

I have some bed alike files but don't have chr term in the fisrt column, that I want to add chr and its corresponding chromosome number, I'm wondering how can I do that in bash!

head dat.tsv
9901    10000   0.186130156985236
10001   10100   244.668091357092
10101   10200   367.420929888855
10201   10300   179.801731647738
10301   10400   141.551984387272
10401   10500   92.5066880216621
10501   10600   92.3205578646769
10601   10700   127.96448292735
10701   10800   74.6381929510795
10801   10900   62.6327978255318
$\endgroup$
2
  • 2
    $\begingroup$ Thanks for including an input file. Please show what you would like the output to look like after the chr term has been correctly added. $\endgroup$
    – gringer
    Commented Mar 24 at 10:52
  • 4
    $\begingroup$ I think the biggest problem is that it's not clear how you/we would know what chromosome numbers go with each row. $\endgroup$ Commented Mar 25 at 16:40

2 Answers 2

1
$\begingroup$

You could use the following perl one-liner, however if genome you are using contains more than one chromosome you need to figure out which lines get which chromosome chr1, chr2. If it's single chrosome like E.coli, usually name of chromosome is "chr".

perl -npe "s/(.*)/chr\t\1/" dat.tsv
$\endgroup$
-1
$\begingroup$

I appreciate your responses.

Using the R dplyr package after using bedtools, I was able to deal with this problem. Using the makewindows function from bedtool, I first obtain a 100 bp window.

The full_join function from the dplyr R package then allows me to obtain a satisfactory result.

I was looking for a script that only uses bash.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.