Which script?
This is not an answer - please delete and post this as a comment to a script you're having problems.
Basically: you have to copy/paste code into the file; compile; use linux tools to get wanted information
What is the easiest way of converting a fixed step wig file to a variable step wig file?
The following C program seems to work:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc,char** argv)
{
int span=1;
int start=0;
int step=0;
char line[BUFSIZ];
while(fgets(line,BUFSIZ,stdin)!=NULL)
{
if(strncmp(line,"fixedStep",9)==0)
{
span=1;
fputs("variableStep",stdout);
char* saveptr=NULL;
char* token=line;
char* ptr;
while((ptr=strtok_r(token," \n\t", &saveptr))!=NULL)
{
char* key=ptr;
char* value=strchr(ptr,'=');
if(value==NULL)
{
token=saveptr;
continue;
}
*value=0;
value++;
if(strcmp(key,"chrom")==0)
{
printf(" %s=%s",key,value);
}
else if(strcmp(key,"span")==0)
{
span=atoi(value);
}
else if(strcmp(key,"start")==0)
{
start=atoi(value);
}
else if(strcmp(key,"step")==0)
{
step=atoi(value);
}
token=saveptr;
}
printf(" span=%d\n",span);
continue;
}
printf("%d\t%s",start,line);
start+=step;
}
return 0;
}
Compile:
gcc -O3 -Wall -ofix2var source.c
Example:
$ curl -s "http://hgdownload.cse.ucsc.edu/goldenPath/hg18/phastCons28way/vertebrate/chr9_random.pp.gz" | gunzip -c | ./fix2var | head
variableStep chrom=chr9_random span=1
3 0.000
4 0.000
5 0.000
6 0.000
7 0.000
8 0.000
9 0.000
10 0.000
11 0.000
This was placing a 0/t in front of the track line. I also edited it to not print lines with density 0, since being able to omit these are the one advantage of variable step.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc,char** argv)
{
int span=1;
int start=0;
int step=0;
char line[BUFSIZ];
while(fgets(line,BUFSIZ,stdin)!=NULL)
{
if(strncmp(line,"track",5)==0)
{
printf("%s",line);
continue;
}
if(strncmp(line,"fixedStep",9)==0)
{
span=1;
fputs("variableStep",stdout);
char* saveptr=NULL;
char* token=line;
char* ptr;
while((ptr=strtok_r(token," \n\t", &saveptr))!=NULL)
{
char* key=ptr;
char* value=strchr(ptr,'=');
if(value==NULL)
{
token=saveptr;
continue;
}
*value=0;
value++;
if(strcmp(key,"chrom")==0)
{
printf(" %s=%s",key,value);
}
else if(strcmp(key,"span")==0)
{
span=atoi(value);
}
else if(strcmp(key,"start")==0)
{
start=atoi(value);
}
else if(strcmp(key,"step")==0)
{
step=atoi(value);
}
token=saveptr;
}
printf(" span=%d\n",span);
continue;
}
if(strncmp(line,"0",1)!=0)
{
printf("%d\t%s",start,line);
}
start+=step;
}
return 0;
}
Hello, Could somebody please clarify how to run this script? I am trying to follow the "example" above with but is not working. I was able to compile the c program with no problems but then I got stuck into how is the correct way to run the program. thanks alfonso
Which script?
This is not an answer - please delete and post this as a comment to a script you're having problems.
Basically: you have to copy/paste code into the file; compile; use linux tools to get wanted information
Log in to answer this question.