File: writeimages.cpp

package info (click to toggle)
piler 0~20140707-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 360 kB
  • sloc: cpp: 5,369; makefile: 39
file content (50 lines) | stat: -rwxr-xr-x 1,599 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "piler2.h"

static void WriteHit(FILE *f, const HitData &Hit, const PILE_INDEX_TYPE *PileIndexes)
	{
	const int TargetFrom = Hit.TargetFrom;
	const int QueryFrom = Hit.QueryFrom;

	int TargetContigFrom;
	const char *TargetLabel = GlobalToContig(TargetFrom, &TargetContigFrom);

	int QueryContigFrom;
	const char *QueryLabel = GlobalToContig(QueryFrom, &QueryContigFrom);

	const int TargetLength = Hit.TargetTo - TargetFrom + 1;
	const int QueryLength = Hit.QueryTo - QueryFrom + 1;

	const int QueryPileIndex = PileIndexes[QueryFrom];
	const int TargetPileIndex = PileIndexes[TargetFrom];

	const int QueryContigTo = QueryContigFrom + QueryLength - 1;
	const int TargetContigTo = TargetContigFrom + TargetLength - 1;

	const char Strand = Hit.Rev ? '-' : '+';

// GFF fields are:
// <seqname> <source> <feature> <start> <end> <score> <strand> <frame> [attributes] [comments]
//     0         1         2        3      4      5        6       7         8           9
	fprintf(f, "%s\tpiler\thit\t%d\t%d\t0\t%c\t.\tTarget %s %d %d ; Piles %d %d\n",
	  QueryLabel,
	  QueryContigFrom + 1,
	  QueryContigTo + 1,
	  Strand,
	  TargetLabel,
	  TargetContigFrom + 1,
	  TargetContigTo + 1,
	  QueryPileIndex,
	  TargetPileIndex);
	}

void WriteImages(const char *FileName, const HitData *Hits, int HitCount,
  const PILE_INDEX_TYPE *PileIndexes)
	{
	FILE *f = OpenStdioFile(FileName, FILEIO_MODE_WriteOnly);
	for (int HitIndex = 0; HitIndex < HitCount; ++HitIndex)
		{
		const HitData &Hit = Hits[HitIndex];
		WriteHit(f, Hit, PileIndexes);
		}
	fclose(f);
	}