Tag Archives: Desired Output

Read sequence file into linked list in C.

By yifangt

Sounds like a homework, but not! This is only for self study. I know the better way would be in perl which is too slow if the file is too big (normally ~15GB), but I am trying to pick up C said to be more faster and use less memory. Can someone help me with my code? Here’s the file (which is a typical fastq format—mean every four lines as a unit): infile.txt

Code:

@Mseq1
AGCTG
+
XX%%A
@Mseq2
AGCGG
-
&X#%A
@Mseq3
AGCCG
+
#X%#A


Desired Output: outfile.txt

Code:

@Mseq1 AGCTG + XX%%A
@Mseq2 AGCGG - &X#%A
@Mseq3 AGCCG + #X%#A


Code:

#include
#include
#include

struct node
{
char readName[251];
char readSeq[251];
char strand;
char readQual[251];
struct node *next;
};

int main ()
{
FILE *fp;
int count;
char *line;
count = 1;
char filename[30] = "infile.txt";
struct node *read, *pre, *p;
struct node *first = NULL;

fp = fopen (filename, "r");

while (fgets (line, sizeof (line), fp) != NULL) /* read a line */
{
read = (struct node *) malloc (sizeof (struct node));
while (count % 4 == 1)
{
strcpy (read->readName, line);
}
count++;
while (count % 4 == 2)
{
strcpy (read->readSeq, line);
}
count++;
while (count % 4 == 3)
{
strcpy (read->strand, line);
}
count++;
while (count % 4 == 0)
{
strcpy (read->readQual, line);
}
count++;
read->next = NULL;
pre = p = first;

while (p != NULL)
{
pre = p;
p = p->next;
}
if (pre != NULL)
pre->next = read;
else
first = read;

fclose (fp);

...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Using and passing arguments to shuf within awk

By DerSeb

Hello all,

I would like to output a random number within a range for every line using awk and shuf. I think I’m almost there, but I don’t know how to pass arguments to shuf within my awk script:

Input

Code:

1 12190 12227
1 12595 12721
1 13403 13639
1 14362 14829
1 14970 15038


awk:

Code:

awk '{ a = (shuf -i $2"-"$3 -n 1)}{print $1,a}' Input


Desired Output (with second column being a random number between field 2 and 3 of input file):

Code:

1 12211
1 12659
1 13411
1 14705
1 15021


Al I get so far is

Code:

1 012190-122271
1 012595-127211
1 013403-136391
1 014362-148291
1 014970-150381


Any help would be greatly appreciated!

Seb

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums