Ejemplo n.º 1
0
void
DjVuTXT::Zone::get_smallest(GList<GRect> &list, const int padding) const
{
  GPosition pos=children;
  if(pos)
    {
      do {
        children[pos].get_smallest(list,padding);
      } while (++pos);
    }
  else if(zone_parent && zone_parent->ztype >= PARAGRAPH)
    {
      const GRect &xrect=zone_parent->rect;
      if(xrect.height() < xrect.width())
        {
          list.append(GRect(rect.xmin-padding,xrect.ymin-padding,rect.width()
                            +2*padding,xrect.height()+2*padding));
        }
      else
        {
          list.append(GRect(xrect.xmin-padding,rect.ymin-padding,xrect.width()
                            +2*padding,rect.height()+2*padding));
        }
    }
  else
    {
      list.append(GRect(rect.xmin-padding,rect.ymin-padding,rect.width()
                        +2*padding,rect.height()+2*padding));
    }
}
Ejemplo n.º 2
0
/*
  This should be replaced by more convenient method of accessing gnome-keyring..
  We have very unnecessery dependecies with gnome devs here.
 */
const QStringList DesktopCouchProvider::getOAuthCredentials(void)
{
    QLog::getLogger()->log("Retrieving credentials...",QLog::INFO);
    //QStringList* creds = NULL;
    g_set_application_name("desktop-couch-qt");
    GnomeKeyringAttributeList* attributes;
    GnomeKeyringResult result;
    GList* found_list;
    GList* i;
    GnomeKeyringFound * found;

    attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute));
    gnome_keyring_attribute_list_append_string(attributes,"desktopcouch","oauth");
    result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&found_list);
    char* item;
    if (result == GNOME_KEYRING_RESULT_OK )
    {
        for ( i = found_list; i != NULL; i = i->next )
        {
            found = (GnomeKeyringFound*)i->data;
            item = g_strdup(found->secret);
            QString i(item);
            QStringList lcreds = i.split(":");
            return lcreds;
        }
    }
    QLog::getLogger()->log("Retrieving credentials failed...\n(check if Gnome-Keyring-Daemon is running)",QLog::ERROR);
    return QStringList();
}
Ejemplo n.º 3
0
void
DjVuTXT::Zone::find_zones(GList<Zone *> &list, 
                          const int string_start, const int string_end) const
{
  const int text_end=text_start+text_length;
  if(text_start >= string_start)
    {
      if(text_end <= string_end)
        {
          list.append(const_cast<Zone *>(this));
        }
      else if(text_start < string_end)
        {
          if (children.size())
            for (GPosition pos=children; pos; ++pos)
              children[pos].find_zones(list,string_start,string_end);
          else
            list.append(const_cast<Zone *>(this));
        }
    }
  else if( text_end > string_start)
    {
      if (children.size())
        for (GPosition pos=children; pos; ++pos)
          children[pos].find_zones(list,string_start,string_end);
      else
        list.append(const_cast<Zone *>(this));
    }
}
Ejemplo n.º 4
0
int qsearch_mrnas(uint x, GList<GffObj>& mrnas) {
  //binary search
  //do the simplest tests first:
  if (mrnas[0]->start>x) return 0;
  if (mrnas.Last()->start<x) return -1;
  uint istart=0;
  int i=0;
  int idx=-1;
  int maxh=mrnas.Count()-1;
  int l=0;
  int h = maxh;
  while (l <= h) {
     i = (l+h)>>1;
     istart=mrnas[i]->start;
     if (istart < x)  l = i + 1;
          else {
             if (istart == x) { //found matching coordinate here
                  idx=i;
                  while (idx<=maxh && mrnas[idx]->start==x) {
                     idx++;
                     }
                  return (idx>maxh) ? -1 : idx;
                  }
             h = i - 1;
             }
     } //while
 idx = l;
 while (idx<=maxh && mrnas[idx]->start<=x) {
    idx++;
    }
 return (idx>maxh) ? -1 : idx;
}
Ejemplo n.º 5
0
int qsearch_loci(uint x, GList<GLocus>& loci) {
 // same as above, but for GSeg lists
  //binary search
  //do the simplest tests first:
  if (loci[0]->start>x) return 0;
  if (loci.Last()->start<x) return -1;
  uint istart=0;
  int i=0;
  int idx=-1;
  int maxh=loci.Count()-1;
  int l=0;
  int h = maxh;
  while (l <= h) {
     i = (l + h) >> 1;
     istart=loci[i]->start;
     if (istart < x) l=i+1;
                else {
                   if (istart == x) { //found matching coordinate here
                        idx=i;
                        while (idx<=maxh && loci[idx]->start==x) {
                           idx++;
                           }
                        return (idx>maxh) ? -1 : idx;
                        }
                   h=i-1;
                   }
     } //while
 idx = l;
 while (idx<=maxh && loci[idx]->start<=x) {
    idx++;
    }
 return (idx>maxh) ? -1 : idx;
}
Ejemplo n.º 6
0
/* copied from xpdf/GlobalParams.cc as it was removed in XPDF 4 */
GList* getCIDToUnicodeNames(GlobalParams* globalParams) {
  GList *list = new GList();
  GString *key;
  void *value;
  GHashIter *iter = NULL;
  globalParams->cidToUnicodes->startIter(&iter);
  while (globalParams->cidToUnicodes->getNext(&iter, &key, &value)) {
       list->append(key->copy());
  }
  globalParams->cidToUnicodes->killIter(&iter);
  return list;
}
Ejemplo n.º 7
0
QCyclicGroup::QCyclicGroup(const gint size)
{
    assert(size > 0);
    GList e;

    for(int i = 0; i < size; ++i)
    {
        e.append(i);
    }

    this->createCyclic(e);
}
	InterfaceInstance *GetInterface(const char *pzModelType)
	{
		if (m_nThreadMode == 1 || m_nThreadMode == 2)
		{
			if(m_nThreadMode == 1)
			{
				// wait for the one and only
				gthread_cond_wait(&m_cond, &m_condLock); 
			}
			InterfaceInstance *pII = (InterfaceInstance *)m_lstInterfaces.First();
			pII->InUse(1);
			return pII;
		}
		if (m_nThreadMode == 3)
		{
			// find one that's not in use
			gthread_mutex_lock(&m_lock);
			InterfaceInstance *pII = 0;
			GListIterator it(&m_lstInterfaces);
			while (it())
			{
				pII = (InterfaceInstance *)it++;
				if ( !pII->InUse() )
				{
					pII->InUse(1);
					gthread_mutex_unlock(&m_lock);
					return pII;	// and return it
				}
			}

			// unlock the mutex while we create a new instance, this will take a while 
			gthread_mutex_unlock(&m_lock);
			pII = new InterfaceInstance(pzModelType);
			pII->InUse(1);
			gthread_mutex_lock(&m_lock);

			// store the instance then return it
			m_lstInterfaces.AddLast(pII);
			gthread_mutex_unlock(&m_lock);
			return pII;
		}
		else if (m_nThreadMode == 4)
		{
			return new InterfaceInstance(pzModelType);
		}

		return 0;
	}
	void AddInterface(InterfaceInstance *pI)
	{
		// m_lstInterfaces should be empty

		m_nThreadMode = pI->GetThreadMode();
		pI->InUse(0);
		gthread_mutex_lock(&m_lock);
		m_lstInterfaces.AddLast(pI);
		gthread_mutex_unlock(&m_lock);
	}
Ejemplo n.º 10
0
void cluster_mRNAs(GList<GffObj> & mrnas, GList<GLocus> & loci, int qfidx) {
	//mrnas sorted by start coordinate
	//and so are the loci
	//int rdisc=0;
		for (int t=0;t<mrnas.Count();t++) {
		GArray<int> mrgloci(false);
		GffObj* mrna=mrnas[t];
		int lfound=0; //count of parent loci
		/*for (int l=0;l<loci.Count();l++) {
			if (loci[l]->end<mrna->exons.First()->start) continue;
			if (loci[l]->start>mrna->exons.Last()->end) break; */
		 for (int l=loci.Count()-1;l>=0;l--) {
		   if (loci[l]->end<mrna->exons.First()->start) {
		       if (mrna->exons.First()->start-loci[l]->start > GFF_MAX_LOCUS) break;
		       continue;
		       }
		   if (loci[l]->start>mrna->exons.Last()->end) continue;
			//here we have mrna overlapping loci[l]
			if (loci[l]->add_mRNA(mrna)) {
				//a parent locus was found
				lfound++;
				mrgloci.Add(l); //locus indices added here, in decreasing order
			}
		}//loci loop
		//if (lfound<0) continue; //mrna was a ref duplicate, skip it
		if (lfound==0) {
			//create a locus with only this mRNA
 			 loci.Add(new GLocus(mrna, qfidx));
		    }
		 else if (lfound>1) {
			//more than one locus found parenting this mRNA, merge loci
		     lfound--;
			 for (int l=0;l<lfound;l++) {
				  int mlidx=mrgloci[l]; //largest indices first, so it's safe to remove
				  loci[mrgloci[lfound]]->addMerge(*loci[mlidx], mrna);
				  loci.Delete(mlidx);
			    }
		    }
	}//mrnas loop
	//if (rdisc>0) mrnas.Pack();
	//return rdisc;
}
Ejemplo n.º 11
0
static void
appendPath(const GURL &url, 
           GMap<GUTF8String,void *> &map,
           GList<GURL> &list)
{
  if( !url.is_empty() && !map.contains(url.get_string()) )
    {
      map[url.get_string()]=0;
      list.append(url);
    }
}
Ejemplo n.º 12
0
void collectLocusData(GList<GenomicSeqData>& ref_data) {
  int locus_num=0;
  for (int g=0;g<ref_data.Count();g++) {
    GenomicSeqData* gdata=ref_data[g];
    for (int l=0;l<gdata->loci.Count();l++) {
      GffLocus& loc=*(gdata->loci[l]);
      GHash<int> gnames(true); //gene names in this locus
      GHash<int> geneids(true); //Entrez GeneID: numbers
      for (int i=0;i<loc.rnas.Count();i++) {
        GffObj& t=*(loc.rnas[i]);
        GStr gname(t.getGeneName());
        if (!gname.is_empty()) {
           gname.upper();
           int* prevg=gnames.Find(gname.chars());
           if (prevg!=NULL) (*prevg)++;
                  else gnames.Add(gname, new int(1));
           }
        //parse GeneID xrefs, if any:
        GStr xrefs(t.getAttr("xrefs"));
        if (!xrefs.is_empty()) {
          xrefs.startTokenize(",");
          GStr token;
          while (xrefs.nextToken(token)) {
            token.upper();
            if (token.startsWith("GENEID:")) {
              token.cut(0,token.index(':')+1);
              int* prevg=geneids.Find(token.chars());
              if (prevg!=NULL) (*prevg)++;
                     else geneids.Add(token, new int(1));
              }
            } //for each xref
          } //xrefs parsing
        }//for each transcript
      locus_num++;
      loc.locus_num=locus_num;
      if (gnames.Count()>0) { //collect all gene names associated to this locus
         gnames.startIterate();
         int* gfreq=NULL;
         char* key=NULL;
         while ((gfreq=gnames.NextData(key))!=NULL) {
            loc.gene_names.AddIfNew(new CGeneSym(key,*gfreq));
            }
         } //added collected gene_names
      if (loc.gene_ids.Count()>0) { //collect all GeneIDs names associated to this locus
         geneids.startIterate();
         int* gfreq=NULL;
         char* key=NULL;
         while ((gfreq=geneids.NextData(key))!=NULL) {
           loc.gene_ids.AddIfNew(new CGeneSym(key,*gfreq));
            }
          }
      } //for each locus
  }//for each genomic sequence
}
Ejemplo n.º 13
0
//-------------------------------------------------------------------------
//	create dialog
//-------------------------------------------------------------------------
Bool GWinDialog::ShowDialog(GWinControl* pOwner)
{
	int DialogResult = IDCANCEL;

	//	add dialog to list
	g_ActiveWinDialogs.Add( this );

	//	create dialog
	DialogResult = DialogBoxParam( GApp::g_HInstance, MAKEINTRESOURCE( DialogResource() ), pOwner->Hwnd(), GetDialogCallback(), (u32)this );

	if ( DialogResult == -1 )
	{
		GDebug::CheckWin32Error();
	}

	//	remove dialog from list
	int Index = g_ActiveWinDialogs.FindIndex(this);
	g_ActiveWinDialogs.RemoveAt( Index );

	return (DialogResult == IDOK);
}
Ejemplo n.º 14
0
	bool Load(char *File)
	{
		bool Status = false;

		Langs.Empty();
		DeleteObj(Tree);
		Tree = new GXmlTag;
		if (Tree)
		{
			if (File)
			{
				GFile f;
				if (f.Open(File, O_READ))
				{
					GXmlTree t(GXT_NO_ENTITIES);
					if (t.Read(Tree, &f, 0))
					{
						CollectLangs(Tree);

						List<GLanguage> Lst;
						const char *Key = 0;
						for (bool p = Langs.First(&Key); p; p = Langs.Next(&Key))
						{
							Lst.Insert((GLanguage*)p);
						}
						Lst.Sort(Cmp, 0);

						for (GLanguage *l = Lst.First(); l; l = Lst.Next())
						{
							Inc->Insert(new LangInc(l));
						}

						Status = true;
					}
					else
					{
						LgiMsg(this, "Couldn't parse XML.", AppName);
					}
				}
				else
				{
					LgiMsg(this, "Couldn't open '%s'\n", AppName, MB_OK, File);
				}
			}
			else
			{
				LgiMsg(this, "No file.", AppName);
			}
		}

		return Status;
	}
Ejemplo n.º 15
0
static GList<GURL>
parsePATH(void)
{
  GList<GURL> retval;
  const char *path=getenv("PATH");
  if(path)
  {
    GNativeString p(path);
    int from=0;
    for(int to;(to=p.search(':',from))>0;from=to+1)
    {
      if(to > from)
      {
        retval.append(GURL::Filename::Native(p.substr(from,to-from)));
      }
    }
    if((from+1)<(int)p.length())
    {
      retval.append(GURL::Filename::Native(p.substr(from,-1)));
    }
  }
  return retval;
}
Ejemplo n.º 16
0
//-------------------------------------------------------------------------
//	default dialog callback
//-------------------------------------------------------------------------
/*static*/int CALLBACK GWinDialog::DialogCallback(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	//	get dialog with this hwnd
	GWinDialog* pDialog = NULL;
	for ( int d=0;	d<g_ActiveWinDialogs.Size();	d++ )
		if ( g_ActiveWinDialogs[d]->Hwnd() == hwndDlg )
			pDialog = g_ActiveWinDialogs[d];

	//	handle message
	switch ( message )
	{
		case WM_INITDIALOG:
			//	address of dialog is lParam
			pDialog = (GWinDialog*)lParam;
			pDialog->m_Hwnd = hwndDlg;
			pDialog->OnInit();
			return TRUE;
			break;

		case WM_COMMAND:
			//	button pressed, if TRUE returned, exit dialog
			if ( pDialog->OnButtonPress( LOWORD(wParam) ) )
			{
				EndDialog( hwndDlg, LOWORD(wParam) );
			}
			return TRUE;
			break;

		case WM_ACTIVATE:
			if ( LOWORD( wParam ) == WA_ACTIVE )
			{
				if ( pDialog->OnActivate() )
					return 0;
			}
			break;

		case WM_SETFONT:
		case WM_WINDOWPOSCHANGING:
		case WM_WINDOWPOSCHANGED:
		case WM_NCACTIVATE:
		case WM_USER:
		//case WM_CHANGEUISTATE:
		//case WM_UPDATEUISTATE:
		//case WM_QUERYUISTATE:
			break;
	};

	return FALSE;
}
Ejemplo n.º 17
0
void
DjVuTXT::get_zones(int zone_type, const Zone *parent, 
                   GList<Zone *> & zone_list) const 
   // get all the zones of  type zone_type under zone node parent
{
   // search all branches under parent
   const Zone *zone=parent;
   for( int cur_ztype=zone->ztype; cur_ztype<zone_type; ++cur_ztype )
   {
      GPosition pos;
      for(pos=zone->children; pos; ++pos)
      {
	 Zone *zcur=(Zone *)&zone->children[pos];
	 if ( zcur->ztype == zone_type )
	 {
	    GPosition zpos=zone_list;
	    if ( !zone_list.search(zcur,zpos) )
	       zone_list.append(zcur);
	 }
	 else if ( zone->children[pos].ztype < zone_type )
	    get_zones(zone_type, &zone->children[pos], zone_list);
      }
   }
}
Ejemplo n.º 18
0
void
DjVuTXT::Zone::get_smallest(GList<GRect> &list) const
{
  GPosition pos=children;
  if(pos)
    {
      do {
        children[pos].get_smallest(list);
      } while (++pos);
    }
  else
    {
      list.append(rect);
    }
}
Ejemplo n.º 19
0
// helper function for args
static void 
intList(GUTF8String coords, GList<int> &retval)
{
  int pos=0;
  while(coords.length())
  {
    int epos;
    unsigned long i=coords.toLong(pos,epos,10);
    if(epos>=0)
    {
      retval.append(i);
      const int n=coords.nextNonSpace(epos);
      if(coords[n] != ',')
        break;
      pos=n+1;
    }
  }
}
Ejemplo n.º 20
0
//创建循环群 I(rank)
void QCyclicGroup::createCyclic(const GList e)
{
    assert(e.size() > 0);

    this->m_list = e;
    GMatrix matrix;

    for(gint i = 0; i < e.size(); ++i)
    {
        GList s;

        if(i == 0)
        {
            for(gint j = 0; j < e.size(); ++j)
            {
                s.append(j);
            }
        }
        else
        {
            for(gint j = 0; j < e.size(); ++j)
            {
                if(j == 0)
                {
                    s.append(i);
                }
                else
                {
//怎么办,但是没有规则
                }
            }
        }

        for(gint j = 0; j < rank; j++)
        {
            t.append( (i+j)%rank );
        }

        matrix.append(t);
    }

    QPermuteGroup::createPermute(matrix);
}
Ejemplo n.º 21
0
int main()
{
	Grocery item; // testing default constructor
	Grocery item2("carrots", 8, false); //testing constructor with perameters
	item2.print();
	cout << endl;
	item.setGrocery("eggs", 5, true); //testing set grocery function
	item.print();
	cout << endl;
	item.changeAmount(-3);//testing changeamt function should work
	item.print();
	cout << endl;
	item.changeAmount(4);//testing changeamt function should work
	item.print();
	cout << endl;
	item.changeAmount(-100);//testing change amt function shouldn't work
	item.print();

	cout << "\nGLIST STUFF\n";
	GList one; // testing default constructor
	one.insert("bacon",12,false); // testing insert fuction
	one.insert(item); 
	one.print(); // testing print function
	one.erase("bacon",false);
	one.print();
	one.updateItem("bacon",12); // test updating item not in list
	one.print();
	one.updateItem("eggs",-1200); //test updating eggs shouldn't work
	one.print();
	one.updateItem("eggs",12); // test updating eggs should work
	one.print();

	one.insert("Ketchup",50,false); //should print under Costco
	one.insert("Kumquat",3,false); //Should print under Safeway
	one.insert("Mustard",50,true); //Should print under Costco
	one.insert("Potato",7,true); //Should print under Whole Foods
	one.printByStore();
}
Ejemplo n.º 22
0
void read_mRNAs(FILE* f, GList<GSeqData>& seqdata, GList<GSeqData>* ref_data,
	         int check_for_dups, int qfidx, const char* fname, bool only_multiexon) {
	//>>>>> read all transcripts/features from a GTF/GFF3 file
	//int imrna_counter=0;
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("00");
#endif
	int loci_counter=0;
	if (ref_data==NULL) ref_data=&seqdata;
	bool isRefData=(&seqdata==ref_data);
	                          //(f, transcripts_only)
	GffReader* gffr=new GffReader(f, true); //load only transcript annotations
	gffr->showWarnings(gtf_tracking_verbose);
	//            keepAttrs   mergeCloseExons   noExonAttrs
	gffr->readAll(!isRefData,          true,        isRefData || gtf_tracking_largeScale);
	//so it will read exon attributes only for low number of Cufflinks files
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_readAll");
#endif

	int d=parse_mRNAs(gffr->gflst, seqdata, isRefData, check_for_dups, qfidx,only_multiexon);
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_parse_mRNAs");
#endif
	if (gtf_tracking_verbose && d>0) {
	  if (isRefData) GMessage(" %d duplicate reference transcripts discarded.\n",d);
	            else GMessage(" %d redundant query transfrags discarded.\n",d);
	  }
	//imrna_counter=gffr->mrnas.Count();
	delete gffr; //free the extra memory and unused GffObjs
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_del_gffr");
#endif
	
	//for each genomic sequence, cluster transcripts
	int oriented_by_overlap=0;
	int initial_unoriented=0;
	int final_unoriented=0;
	GStr bname(fname);
	GStr s;
	if (!bname.is_empty()) {
		int di=bname.rindex('.');
		if (di>0) bname.cut(di);
		int p=bname.rindex('/');
		if (p<0) p=bname.rindex('\\');
		if (p>=0) bname.remove(0,p);
	}
	FILE* fdis=NULL;
	FILE* frloci=NULL;

	for (int g=0;g<seqdata.Count();g++) {
		//find the corresponding refseqdata with the same gseq_id
		int gseq_id=seqdata[g]->get_gseqid();
		if (!isRefData) { //query data, find corresponding ref data
			GSeqData* rdata=getRefData(gseq_id, *ref_data);
			initial_unoriented+=seqdata[g]->umrnas.Count();
			if (seqdata[g]->umrnas.Count()>0) {
			    oriented_by_overlap+=fix_umrnas(*seqdata[g], rdata, fdis);
			    final_unoriented+=seqdata[g]->umrnas.Count();
			    }
			}
		//>>>>> group mRNAs into locus-clusters (based on exon overlap)
		cluster_mRNAs(seqdata[g]->mrnas_f, seqdata[g]->loci_f, qfidx);
		cluster_mRNAs(seqdata[g]->mrnas_r, seqdata[g]->loci_r, qfidx);
		if (!isRefData) {
			cluster_mRNAs(seqdata[g]->umrnas, seqdata[g]->nloci_u, qfidx);
			}
		loci_counter+=seqdata[g]->loci_f.Count();
		loci_counter+=seqdata[g]->loci_r.Count();
//		if (refData) {
//			if (frloci==NULL) {
//				s=bname;
//				s.append(".loci.lst");
//				frloci=fopen(s.chars(), "w");
//			}
//			writeLoci(frloci, seqdata[g]->loci_f);
//			writeLoci(frloci, seqdata[g]->loci_r);
//		}//write ref loci
	}//for each genomic sequence
	if (fdis!=NULL) fclose(fdis);
	if (frloci!=NULL) fclose(frloci);
	if (initial_unoriented || final_unoriented) {
	  if (gtf_tracking_verbose) GMessage(" Found %d transfrags with undetermined strand (%d out of initial %d were fixed by overlaps)\n",
			    final_unoriented, oriented_by_overlap, initial_unoriented);
	}
	//if (fdis!=NULL) remove(s.chars()); remove 0-length file
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_cluster");
#endif
}
Ejemplo n.º 23
0
	int OnNotify(GViewI *c, int f)
	{
		switch (c->GetId())
		{
			case IDC_CMD_LINE:
			{
				LgiMsg(	this,
						"These are the command line options you can use with LrStrip. If you specify these\n"
						"then no window will be shown and the application will exit after it's completed\n"
						"it's work.\n"
						"\n"
						"Required options:\n"
						"\n"
						"    -in \'<FileName>\'\n"
						"    -out \'<FileName>\'\n"
						"    -langs \'<LangId>[, <LangId>]\'\n"
						"\n"
						"Where 'LangId' is a standard language code (like 'en' for english).",
						AppName);
				break;
			}
			case IDC_LOAD_FILE:
			{
				GFileSelect s;
				s.Parent(this);
				s.Type("Lgi Resource", "*.lr*");
				if (s.Open())
				{
					Load(s.Name());
				}
				break;
			}
			case IDOK:
			{
				GFileSelect s;
				s.Parent(this);
				s.Type("Lgi Resource", "*.lr*");
				if (s.Save())
				{
					// put together the list of langs
					Langs.Empty();

					List<LangInc> LangLst;
					Inc->GetAll(LangLst);
					for (LangInc *i = LangLst.First(); i; i = LangLst.Next())
					{
						if (i->Value())
						{
							Langs.Add(i->GetText(1), i);
						}
					}

					// overwrite check
					if (FileExists(s.Name()))
					{
						if (LgiMsg(this, "Overwrite '%s'?", AppName, MB_YESNO, s.Name()) == IDNO)
						{
							return 0;
						}
					}

					// save the file...
					if (Save(s.Name()))
					{
						LgiMsg(this, "Striped resource file written ok.", AppName);
					}
				}
				break;
			}
			case IDCANCEL:
			{
				EndModal(c->GetId());
				break;
			}
		}

		return 0;
	}
Ejemplo n.º 24
0
GList<DjVuTXT::Zone *>
DjVuTXT::find_text_in_rect(GRect target_rect, GUTF8String &text) const
   // returns a list of zones of type WORD in the nearest/selected paragraph 
{
   GList<Zone *> zone_list;
   GList<Zone *> lines;

   get_zones((int)PARAGRAPH, &page_zone, zone_list);
   // it's possible that no paragraph structure exists for reasons that  
   // 1) ocr engine is not capable 2) file was modified by user. In such case, 
   // we can only make a rough guess, i.e., select all the lines intersected with
   // target_rect
   if (zone_list.isempty())
   {
      get_zones((int)LINE, &page_zone, zone_list);
      GPosition pos;
      for(pos=zone_list; pos; ++pos)
      {
	 GRect rect=zone_list[pos]->rect;
	 int h0=rect.height()/2;
	 if(rect.intersect(rect,target_rect) && rect.height()>h0)
	    lines.append(zone_list[pos]);
      }
   } else 
   {
      GPosition pos, pos_sel=zone_list;
      float ar=0;
      for(pos=zone_list; pos; ++pos)
      {
	 GRect rect=zone_list[pos]->rect;
	 int area=rect.area();
	 if (rect.intersect(rect, target_rect))
	 {
	    float ftmp=rect.area()/(float)area;
	    if ( !ar || ar<ftmp )
	    {
	       ar=ftmp;
	       pos_sel=pos;
	    }
	 }
      }
      Zone *parag = 0;
      if ( ar>0 ) parag=zone_list[pos_sel];
      zone_list.empty();
      if ( ar>0 ) 
      {
	 get_zones((int)LINE, parag, zone_list);
	 if ( !zone_list.isempty() )
	 {
	    for(GPosition pos=zone_list; pos; ++pos)
	    {
	       GRect rect=zone_list[pos]->rect;
	       int h0=rect.height()/2;
	       if(rect.intersect(rect,target_rect) && rect.height()>h0)
		  lines.append(zone_list[pos]);
	    }
	 }
      }
   }

   zone_list.empty();
   if (!lines.isempty()) 
   {
      int i=1, lsize=lines.size();

      GList<Zone *> words;
      for (GPosition pos=lines; pos; ++pos, ++i)
      {
	 words.empty();
	 get_zones((int)WORD, lines[pos], words);

	 if ( lsize==1 )
	 {
	    for(GPosition p=words;p;++p)
	    {
	       GRect rect=words[p]->rect;
	       if(rect.intersect(rect,target_rect))
	       //if (target_rect.contains(words[p]->rect))
		  zone_list.append(words[p]);
	    }
	 } else
	 {
	    if (i==1)
	    {
	       bool start=true;
	       for(GPosition p=words; p; ++p)
	       {
		  if ( start )
		  {
		     GRect rect=words[p]->rect;
		     if(rect.intersect(rect,target_rect))
			//if (target_rect.contains(words[p]->rect))
		     {
			start=false;
			zone_list.append(words[p]);
		     }
		  } else 
		     zone_list.append(words[p]);
	       }
	    } else if (i==lsize)
	    {
	       bool end=true;
	       for(GPosition p=words.lastpos();p;--p)
	       {
		  if ( end )
		  {
		     GRect rect=words[p]->rect;
		     if(rect.intersect(rect,target_rect))
			//if(target_rect.contains(words[p]->rect) )
		     {
			end=false;
			zone_list.append(words[p]);
		     }
		  } else 
		     zone_list.append(words[p]);
	       }
	    }

	    if (i!=1 && i!=lsize )
	    {
	       for(GPosition p=words;p;++p)
		  zone_list.append(words[p]);
	    }
	 }
      }
   } 

   return zone_list;
}
Ejemplo n.º 25
0
void sort_GSeqs_byName(GList<GSeqData>& seqdata) {
  seqdata.setSorted(&cmpGSeqByName);
}
Ejemplo n.º 26
0
int parse_mRNAs(GfList& mrnas,
				 GList<GSeqData>& glstdata,
				 bool is_ref_set,
				 int check_for_dups,
				 int qfidx, bool only_multiexon) {
	int tredundant=0; //redundant transcripts discarded
	int total_kept=0;
	int total_seen=mrnas.Count();
	for (int k=0;k<mrnas.Count();k++) {
		GffObj* m=mrnas[k];
		int i=-1;
		GSeqData f(m->gseq_id);
		GSeqData* gdata=NULL;
		uint tlen=m->len();
		if (m->hasErrors() || (tlen+500>GFF_MAX_LOCUS)) { //should probably report these in a file too..
			if (gtf_tracking_verbose) 
			      GMessage("Warning: transcript %s discarded (structural errors found, length=%d).\n", m->getID(), tlen);
			continue;
			}
		if (only_multiexon && m->exons.Count()<2) {
			continue;
			}
		//GStr feature(m->getFeatureName());
		//feature.lower();
		//bool gene_or_locus=(feature.endsWith("gene") ||feature.index("loc")>=0);
		//if (m->exons.Count()==0 && gene_or_locus) {
		if (m->isDiscarded()) {
			//discard generic "gene" or "locus" features with no other detailed subfeatures
			if (!is_ref_set && gtf_tracking_verbose)
			   GMessage("Warning: discarding non-transfrag (GFF generic gene/locus container?) %s\n",m->getID());
			continue;
			}

		if (m->exons.Count()==0) {
				if (gtf_tracking_verbose && !is_ref_set)
				 GMessage("Warning: %s %s found without exon segments (adding default exon).\n",m->getFeatureName(), m->getID());
				m->addExon(m->start,m->end);
				}
		if (glstdata.Found(&f,i)) gdata=glstdata[i];
		else {
			gdata=new GSeqData(m->gseq_id);
			glstdata.Add(gdata);
			}
		
		double fpkm=0;
		double cov=0;
		double conf_hi=0;
		double conf_lo=0;

		GList<GffObj>* target_mrnas=NULL;
		if (is_ref_set) { //-- ref transcripts
		   if (m->strand=='.') {
		     //unknown strand - discard from reference set (!)
		     continue;
		     }
		   total_kept++;
		   target_mrnas=(m->strand=='+') ? &(gdata->mrnas_f) : &(gdata->mrnas_r);
		   if (check_for_dups) {
		     //check all gdata->mrnas_r (ref_data) for duplicate ref transcripts
		     int rpidx=-1;
		     GffObj* rp= is_RefDup(m, *target_mrnas, rpidx);
		     if (rp!=NULL) { //duplicate found
		      //discard one of them
		      //but let's keep the gene_name if present
		      //DEBUG:
		      //GMessage("Ref duplicates: %s = %s\n", rp->getID(), m->getID());
		      tredundant++;
		      total_kept--;
		      if (betterDupRef(rp, m)) {
		           if (rp->getGeneName()==NULL && m->getGeneName()!=NULL) {
		                  rp->setGeneName(m->getGeneName());
		                  }
		           continue;
		           }
		         else {
		           if (m->getGeneName()==NULL && rp->getGeneName()!=NULL) {
		                  m->setGeneName(rp->getGeneName());
		                  }
		           ((CTData*)(rp->uptr))->mrna=NULL;
		           rp->isUsed(false);
		           target_mrnas->Forget(rpidx);
		           target_mrnas->Delete(rpidx);
		           }
		       }
		     } //check for duplicate ref transcripts
		   } //ref transcripts
		else { //-- query transfrags
		   if (m->strand=='+') { target_mrnas = &(gdata->mrnas_f); }
		     else if (m->strand=='-') { target_mrnas=&(gdata->mrnas_r); }
		        else { m->strand='.'; target_mrnas=&(gdata->umrnas); }
		   total_kept++;
		   if (check_for_dups) { //check for redundancy
		     // check if there is a redundancy between this and another already loaded Cufflinks transcript
		     int cidx =  is_Redundant(m, target_mrnas, (check_for_dups>1));
		     if (cidx>=0) {
		        //always discard the redundant transcript with the fewer exons OR shorter
			     tredundant++;
		         total_kept--;
		    	 if (t_dominates(target_mrnas->Get(cidx),m)) {
		            //new transcript is shorter, discard it
		        	if (gtf_tracking_verbose) {
		        		GMessage(" transfrag %s discarded (made redundant by %s)\n", m->getID(), target_mrnas->Get(cidx)->getID());
		        	}
		            continue;
		        }
		        else {
		            //discard the older transfrag
		        	if (gtf_tracking_verbose) {
		        		GMessage(" transfrag %s discarded (made redundant by %s)\n", target_mrnas->Get(cidx)->getID(), m->getID());
		        	}
		            ((CTData*)(target_mrnas->Get(cidx)->uptr))->mrna=NULL;
		            target_mrnas->Get(cidx)->isUsed(false);
		            target_mrnas->Forget(cidx);
		            target_mrnas->Delete(cidx);
		            //the uptr (CTData) pointer will still be kept in gdata->ctdata and deallocated eventually
		        }
		     }
		   }// redundant transfrag check
		   if (m->gscore==0.0)   
		     m->gscore=m->exons[0]->score; //Cufflinks exon score = isoform abundance
		   //const char* expr = (gtf_tracking_largeScale) ? m->getAttr("FPKM") : m->exons[0]->getAttr(m->names,"FPKM");
		   const char* expr = m->getAttr("FPKM");
		   if (expr!=NULL) {
		       if (expr[0]=='"') expr++;
		       fpkm=strtod(expr, NULL);
		       } else { //backward compatibility: read RPKM if FPKM not found
		       //expr=(gtf_tracking_largeScale) ? m->getAttr("RPKM") : m->exons[0]->getAttr(m->names,"RPKM");
		       expr=m->getAttr("RPKM");
		       if (expr!=NULL) {
		           if (expr[0]=='"') expr++;
		           fpkm=strtod(expr, NULL);
		           }
		       }
		   //const char* scov=(gtf_tracking_largeScale) ? m->getAttr("cov") : m->exons[0]->getAttr(m->names,"cov");
		   const char* scov=m->getAttr("cov");
		   if (scov!=NULL) {
		       if (scov[0]=='"') scov++; 
		       cov=strtod(scov, NULL);
		       }
		   //const char* sconf_hi=(gtf_tracking_largeScale) ? m->getAttr("conf_hi") : m->exons[0]->getAttr(m->names,"conf_hi");
		   const char* sconf_hi=m->getAttr("conf_hi");
		   if (sconf_hi!=NULL){
		       if (sconf_hi[0]=='"') sconf_hi++;
		       conf_hi=strtod(sconf_hi, NULL);
		       }
		   //const char* sconf_lo=(gtf_tracking_largeScale) ? m->getAttr("conf_lo") : m->exons[0]->getAttr(m->names,"conf_lo");
		   const char* sconf_lo=m->getAttr("conf_lo");
		   if (sconf_lo!=NULL) {
		       if (sconf_lo[0]=='"') sconf_lo++;
		       conf_lo=strtod(sconf_lo, NULL);
		       }
		   } //Cufflinks transfrags
		target_mrnas->Add(m);
		m->isUsed(true);
		CTData* mdata=new CTData(m);
		mdata->qset=qfidx;
		gdata->tdata.Add(mdata);
		if (!is_ref_set) {
		// Cufflinks - attributes parsing
		   mdata->FPKM=fpkm;
		   mdata->cov=cov;
		   mdata->conf_hi=conf_hi;
		   mdata->conf_lo=conf_lo;
		   }
	}//for each mrna read
	if (gtf_tracking_verbose) {
		if (is_ref_set)
       GMessage(" Kept %d ref transcripts out of %d\n", total_kept, total_seen);
		else
	   GMessage(" Kept %d transfrags out of %d\n", total_kept, total_seen);
	}
 //if (mrna_deleted>0)
 //  mrnas.Pack();
 
 //return (is_ref_set ? refdiscarded : tredundant);
	return tredundant;
}
Ejemplo n.º 27
0
void
BepdfApplication::Initialize()
{
	if (!mInitialized) {
		mInitialized = true;

		// built in fonts
		BPath fontDirectory(mAppPath);
		fontDirectory.Append("fonts");

		// built in encodings
		BPath encodingDirectory(mAppPath);
		encodingDirectory.Append("encodings");

		InitXpdf(NULL, fontDirectory.Path(), encodingDirectory.Path());

		// system fonts
		BPath systemFontsPath;
		if (find_directory(B_BEOS_FONTS_DIRECTORY, &systemFontsPath) == B_OK) {
			BDirectory directory(systemFontsPath.Path());
			BEntry entry;
			while (directory.GetNextEntry(&entry) == B_OK) {
				if (!entry.IsDirectory())
					continue;
				BPath fontDirectory;
				if (entry.GetPath(&fontDirectory) != B_OK)
					continue;
				setGlobalParameter("fontDir", fontDirectory.Path());
			}
		}

		// CID fonts
		BMessage msg;
		mSettings->GetDisplayCIDFonts(msg);
		DisplayCIDFonts displayNames(msg);

		// record new names
		bool foundNewName = false;
		GList* list = getCIDToUnicodeNames(globalParams);
		for (int i = 0; i < list->getLength(); i ++) {
			GString* name = (GString*)list->get(i);
			if (displayNames.Contains(name->getCString())) {
				continue;
			}
			// record name
			displayNames.Set(name->getCString());
			foundNewName = true;
		}

		// store in settings
		if (foundNewName) {
			msg.MakeEmpty();
			displayNames.Archive(msg);
			mSettings->SetDisplayCIDFonts(msg);
		}

		// set CID fonts
		for (int i = 0; i < list->getLength(); i ++) {
		    GString* name = (GString*)list->get(i);
			BString file;
			DisplayCIDFonts::Type type;

			displayNames.Get(name->getCString(), file, type);
			if (type == DisplayCIDFonts::kUnknownType ||
				file.Length() == 0) {
				continue;
			}

			if (type == DisplayCIDFonts::kTrueType) {
				setGlobalParameter("displayCIDFontTT", name->getCString(), file.String());
			} else {
				setGlobalParameter("displayCIDFontT1", name->getCString(), file.String());
			}
		}

		deleteGList(list, GString);
	}
}
Ejemplo n.º 28
0
int main(int argc, char * const argv[]) {
 GArgs args(argc, argv, 
   "debug;merge;cluster-only;help;force-exons;no-pseudo;MINCOV=MINPID=hvOUNHWCVJMKQNSXTDAPRZFGLEm:g:i:r:s:t:a:b:o:w:x:y:d:");
 args.printError(USAGE, true);
 if (args.getOpt('h') || args.getOpt("help")) {
    GMessage("%s",USAGE);
    exit(1);
    }
 debugMode=(args.getOpt("debug")!=NULL);
 decodeChars=(args.getOpt('D')!=NULL);
 forceExons=(args.getOpt("force-exons")!=NULL);
 NoPseudo=(args.getOpt("no-pseudo")!=NULL);
 mRNAOnly=(args.getOpt('O')==NULL);
 //sortByLoc=(args.getOpt('S')!=NULL);
 addDescr=(args.getOpt('A')!=NULL);
 verbose=(args.getOpt('v')!=NULL);
 wCDSonly=(args.getOpt('C')!=NULL);
 validCDSonly=(args.getOpt('V')!=NULL);
 altPhases=(args.getOpt('H')!=NULL);
 fmtGTF=(args.getOpt('T')!=NULL); //switch output format to GTF
 bothStrands=(args.getOpt('B')!=NULL);
 fullCDSonly=(args.getOpt('J')!=NULL);
 spliceCheck=(args.getOpt('N')!=NULL);
 bool matchAllIntrons=(args.getOpt('K')==NULL);
 bool fuzzSpan=(args.getOpt('Q')!=NULL);
 if (args.getOpt('M') || args.getOpt("merge")) {
    doCluster=true;
    doCollapseRedundant=true;
    }
   else {
    if (!matchAllIntrons || fuzzSpan) {
      GMessage("%s",USAGE);
      GMessage("Error: -K or -Q options require -M/--merge option!\n");
      exit(1);
      }
    }
 if (args.getOpt("cluster-only")) {
    doCluster=true;
    doCollapseRedundant=false;
    if (!matchAllIntrons || fuzzSpan) {
      GMessage("%s",USAGE);
      GMessage("Error: -K or -Q options have no effect with --cluster-only.\n");
      exit(1);
      }
    }
 if (fullCDSonly) validCDSonly=true;
 if (verbose) { 
     fprintf(stderr, "Command line was:\n");
     args.printCmdLine(stderr);
     }

 fullattr=(args.getOpt('F')!=NULL);
 if (args.getOpt('G')==NULL) 
    noExonAttr=!fullattr;
   else {
     noExonAttr=true;
     fullattr=true;
     }
 if (NoPseudo && !fullattr) {
	 noExonAttr=true;
	 fullattr=true;
 }
 ensembl_convert=(args.getOpt('L')!=NULL);
 if (ensembl_convert) {
    fullattr=true;
    noExonAttr=false;
    //sortByLoc=true;
    }
    
 mergeCloseExons=(args.getOpt('Z')!=NULL);
 multiExon=(args.getOpt('U')!=NULL);
 writeExonSegs=(args.getOpt('W')!=NULL);
 tracklabel=args.getOpt('t');
 GFastaDb gfasta(args.getOpt('g'));
 //if (gfasta.fastaPath!=NULL)
 //    sortByLoc=true; //enforce sorting by chromosome/contig
 GStr s=args.getOpt('i');
 if (!s.is_empty()) maxintron=s.asInt();
 
 FILE* f_repl=NULL;
 s=args.getOpt('d');
 if (!s.is_empty()) {
   if (s=="-") f_repl=stdout;
     else {
       f_repl=fopen(s.chars(), "w");
       if (f_repl==NULL) GError("Error creating file %s\n", s.chars());
       }
   }
 
 rfltWithin=(args.getOpt('R')!=NULL);
 s=args.getOpt('r');
 if (!s.is_empty()) {
   s.trim();
   if (s[0]=='+' || s[0]=='-') {
     rfltStrand=s[0];
     s.cut(0,1);
     }
   int isep=s.index(':');
   if (isep>0) { //gseq name given
      if (rfltStrand==0 && (s[isep-1]=='+' || s[isep-1]=='-')) {
        isep--;
        rfltStrand=s[isep];
        s.cut(isep,1);
        }
      if (isep>0) 
          rfltGSeq=Gstrdup((s.substr(0,isep)).chars());
      s.cut(0,isep+1);
      }
   GStr gsend;
   char slast=s[s.length()-1];
   if (rfltStrand==0 && (slast=='+' || slast=='-')) {
      s.chomp(slast);
      rfltStrand=slast;
      }
   if (s.index("..")>=0) gsend=s.split("..");
                    else gsend=s.split('-');
   if (!s.is_empty()) rfltStart=(uint)s.asInt();
   if (!gsend.is_empty()) {
      rfltEnd=(uint)gsend.asInt();
      if (rfltEnd==0) rfltEnd=MAX_UINT;
      }
   } //gseq/range filtering
 else {
   if (rfltWithin)
     GError("Error: option -R requires -r!\n");
   //if (rfltWholeTranscript)
   //  GError("Error: option -P requires -r!\n");
   }
 s=args.getOpt('m');
 if (!s.is_empty()) {
   FILE* ft=fopen(s,"r");
   if (ft==NULL) GError("Error opening reference table: %s\n",s.chars());
   loadRefTable(ft, reftbl);
   fclose(ft);
   }
 s=args.getOpt('s');
 if (!s.is_empty()) {
   FILE* fsize=fopen(s,"r");
   if (fsize==NULL) GError("Error opening info file: %s\n",s.chars());
   loadSeqInfo(fsize, seqinfo);
   fclose(fsize);
   }

 openfw(f_out, args, 'o');
 //if (f_out==NULL) f_out=stdout;
 if (gfasta.fastaPath==NULL && (validCDSonly || spliceCheck || args.getOpt('w')!=NULL || args.getOpt('x')!=NULL || args.getOpt('y')!=NULL))
  GError("Error: -g option is required for options -w, -x, -y, -V, -N, -M !\n");

 openfw(f_w, args, 'w');
 openfw(f_x, args, 'x');
 openfw(f_y, args, 'y');
 if (f_y!=NULL || f_x!=NULL) wCDSonly=true;
 //useBadCDS=useBadCDS || (fgtfok==NULL && fgtfbad==NULL && f_y==NULL && f_x==NULL);
 
 int numfiles = args.startNonOpt();
 //GList<GffObj> gfkept(false,true); //unsorted, free items on delete
 int out_counter=0; //number of records printed
 while (true) {
   GStr infile;
   if (numfiles) {
          infile=args.nextNonOpt();
          if (infile.is_empty()) break;
          if (infile=="-") { f_in=stdin; infile="stdin"; }
               else 
                 if ((f_in=fopen(infile, "r"))==NULL)
                    GError("Error: cannot open input file %s!\n",infile.chars());
          }
        else 
          infile="-";
   GffLoader gffloader(infile.chars());
   gffloader.transcriptsOnly=mRNAOnly;
   gffloader.fullAttributes=fullattr;
   gffloader.noExonAttrs=noExonAttr;
   gffloader.mergeCloseExons=mergeCloseExons;
   gffloader.showWarnings=(args.getOpt('E')!=NULL);
   gffloader.noPseudo=NoPseudo;
   gffloader.load(g_data, &validateGffRec, doCluster, doCollapseRedundant, 
                             matchAllIntrons, fuzzSpan, forceExons);
   if (doCluster) 
     collectLocusData(g_data);
   if (numfiles==0) break;
   }
   
 GStr loctrack("gffcl");
 if (tracklabel) loctrack=tracklabel;
 g_data.setSorted(&gseqCmpName);
 GffPrintMode exonPrinting;
 if (fmtGTF) {
	 exonPrinting = pgtfAny;
 } else {
	 exonPrinting = forceExons ? pgffBoth : pgffAny;
 }
 bool firstGff3Print=!fmtGTF;
 if (doCluster) {
   //grouped in loci
   for (int g=0;g<g_data.Count();g++) {
     GenomicSeqData* gdata=g_data[g];
     int gfs_i=0;
     for (int l=0;l<gdata->loci.Count();l++) {
       GffLocus& loc=*(gdata->loci[l]);
       //check all non-replaced transcripts in this locus:
       int numvalid=0;
       int idxfirstvalid=-1;
       for (int i=0;i<loc.rnas.Count();i++) {
         GffObj& t=*(loc.rnas[i]);
         if (f_out) {
          while (gfs_i<gdata->gfs.Count() && gdata->gfs[gfs_i]->start<=t.start) {
             GffObj& gfst=*(gdata->gfs[gfs_i]);
             if ((gfst.udata&4)==0) { //never printed
               gfst.udata|=4;
               if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
               if (gfst.exons.Count()==0 && gfst.children.Count()==0 && forceExons)
                gfst.addExon(gfst.start,gfst.end);
               gfst.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
               }
             ++gfs_i;
          }
         }
         GTData* tdata=(GTData*)(t.uptr);
         if (tdata->replaced_by!=NULL) {
            if (f_repl && (t.udata & 8)==0) {
               //t.udata|=8;
               fprintf(f_repl, "%s", t.getID());
               GTData* rby=tdata;
               while (rby->replaced_by!=NULL) {
                  fprintf(f_repl," => %s", rby->replaced_by->getID());
                  rby->rna->udata|=8;
                  rby=(GTData*)(rby->replaced_by->uptr);
                  }
               fprintf(f_repl, "\n");
               }
            continue;
            }
         if (process_transcript(gfasta, t)) {
             t.udata|=4; //tag it as valid
             numvalid++;
             if (idxfirstvalid<0) idxfirstvalid=i;
             }
         }
       if (f_out && numvalid>0) {
         GStr locname("RLOC_");
         locname.appendfmt("%08d",loc.locus_num);
         if (!fmtGTF) {
           if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
           fprintf(f_out,"%s\t%s\tlocus\t%d\t%d\t.\t%c\t.\tID=%s;locus=%s",
                    loc.rnas[0]->getGSeqName(), loctrack.chars(), loc.start, loc.end, loc.strand,
                     locname.chars(), locname.chars());
           //const char* loc_gname=loc.getGeneName();
           if (loc.gene_names.Count()>0) { //print all gene names associated to this locus
              fprintf(f_out, ";genes=%s",loc.gene_names.First()->name.chars());
              for (int i=1;i<loc.gene_names.Count();i++) {
                fprintf(f_out, ",%s",loc.gene_names[i]->name.chars());
                }
              }
           if (loc.gene_ids.Count()>0) { //print all GeneIDs names associated to this locus
              fprintf(f_out, ";geneIDs=%s",loc.gene_ids.First()->name.chars());
              for (int i=1;i<loc.gene_ids.Count();i++) {
                fprintf(f_out, ",%s",loc.gene_ids[i]->name.chars());
                }
              }
           fprintf(f_out, ";transcripts=%s",loc.rnas[idxfirstvalid]->getID());
           for (int i=idxfirstvalid+1;i<loc.rnas.Count();i++) {
              fprintf(f_out, ",%s",loc.rnas[i]->getID());
              }
           fprintf(f_out, "\n");
           }
         //now print all valid, non-replaced transcripts in this locus:
         for (int i=0;i<loc.rnas.Count();i++) {
           GffObj& t=*(loc.rnas[i]);
           GTData* tdata=(GTData*)(t.uptr);
           if (tdata->replaced_by!=NULL || ((t.udata & 4)==0)) continue;
           t.addAttr("locus", locname.chars());
           out_counter++;
           if (fmtGTF) t.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
               else {
                if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
                //print the parent first, if any
                if (t.parent!=NULL && ((t.parent->udata & 4)==0)) {
                    GTData* pdata=(GTData*)(t.parent->uptr);
                    if (pdata && pdata->geneinfo!=NULL) 
                         pdata->geneinfo->finalize();
                    t.parent->addAttr("locus", locname.chars());
                    t.parent->printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
                    t.parent->udata|=4;
                    }
                t.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
                }
            }
          } //have valid transcripts to print
       }//for each locus
     //print the rest of the isolated pseudo/gene/region features not printed yet
     if (f_out) {
      while (gfs_i<gdata->gfs.Count()) {
         GffObj& gfst=*(gdata->gfs[gfs_i]);
         if ((gfst.udata&4)==0) { //never printed
           gfst.udata|=4;
           if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
           if (gfst.exons.Count()==0 && gfst.children.Count()==0 && forceExons)
             gfst.addExon(gfst.start,gfst.end);
           gfst.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
           }
         ++gfs_i;
      }
     }
    } //for each genomic sequence
   }
  else {
   //not grouped into loci, print the rnas with their parents, if any
   int numvalid=0;
   for (int g=0;g<g_data.Count();g++) {
     GenomicSeqData* gdata=g_data[g];
     int gfs_i=0;
     for (int m=0;m<gdata->rnas.Count();m++) {
        GffObj& t=*(gdata->rnas[m]);
        if (f_out) {
         while (gfs_i<gdata->gfs.Count() && gdata->gfs[gfs_i]->start<=t.start) {
            GffObj& gfst=*(gdata->gfs[gfs_i]);
            if ((gfst.udata&4)==0) { //never printed
              gfst.udata|=4;
              if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
              if (gfst.exons.Count()==0 && gfst.children.Count()==0 && forceExons)
               gfst.addExon(gfst.start,gfst.end);
              gfst.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
              }
            ++gfs_i;
         }
        }
        GTData* tdata=(GTData*)(t.uptr);
        if (tdata->replaced_by!=NULL) continue;
        if (process_transcript(gfasta, t)) {
           t.udata|=4; //tag it as valid
           numvalid++;
           if (f_out) {
             if (tdata->geneinfo) tdata->geneinfo->finalize();
             out_counter++;
             if (fmtGTF) t.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
               else {
                if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
                //print the parent first, if any
                if (t.parent!=NULL && ((t.parent->udata & 4)==0)) {
                    GTData* pdata=(GTData*)(t.parent->uptr);
                    if (pdata && pdata->geneinfo!=NULL) 
                         pdata->geneinfo->finalize();
                    t.parent->printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
                    t.parent->udata|=4;
                    }
                t.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
                }
             }//GFF/GTF output requested
           } //valid transcript
        } //for each rna
     //print the rest of the isolated pseudo/gene/region features not printed yet
     if (f_out) {
      while (gfs_i<gdata->gfs.Count()) {
         GffObj& gfst=*(gdata->gfs[gfs_i]);
         if ((gfst.udata&4)==0) { //never printed
           gfst.udata|=4;
           if (firstGff3Print) { printGff3Header(f_out, args);firstGff3Print=false; }
           if (gfst.exons.Count()==0 && gfst.children.Count()==0 && forceExons)
            gfst.addExon(gfst.start,gfst.end);
           gfst.printGxf(f_out, exonPrinting, tracklabel, NULL, decodeChars);
           }
         ++gfs_i;
      }
     }
    } //for each genomic seq
   } //not clustered
 if (f_repl && f_repl!=stdout) fclose(f_repl);
 seqinfo.Clear();
 //if (faseq!=NULL) delete faseq;
 //if (gcdb!=NULL) delete gcdb;
 GFREE(rfltGSeq);
 FRCLOSE(f_in);
 FWCLOSE(f_out);
 FWCLOSE(f_w);
 FWCLOSE(f_x);
 FWCLOSE(f_y);
 }
Ejemplo n.º 29
0
int
DjVuPalette::compute_palette(int maxcolors, int minboxsize)
{
  if (!hist)
    G_THROW( ERR_MSG("DjVuPalette.no_color") );
  if (maxcolors<1 || maxcolors>MAXPALETTESIZE)
    G_THROW( ERR_MSG("DjVuPalette.many_colors") );
  
  // Paul Heckbert: "Color Image Quantization for Frame Buffer Display", 
  // SIGGRAPH '82 Proceedings, page 297.  (also in ppmquant)
  
  // Collect histogram colors
  int sum = 0;
  int ncolors = 0;
  GTArray<PData> pdata;
  { // extra nesting for windows
    for (GPosition p = *hist; p; ++p)
    {
      pdata.touch(ncolors);
      PData &data = pdata[ncolors++];
      int k = hist->key(p);
      data.p[0] = (k>>16) & 0xff;
      data.p[1] = (k>>8) & 0xff;
      data.p[2] = (k) & 0xff;
      data.w = (*hist)[p];
      sum += data.w;
    }
  }
  // Create first box
  GList<PBox> boxes;
  PBox newbox;
  newbox.data = pdata;
  newbox.colors = ncolors;
  newbox.boxsize = 256;
  newbox.sum = sum;
  boxes.append(newbox);
  // Repeat spliting boxes
  while (boxes.size() < maxcolors)
    {
      // Find suitable box
      GPosition p;
      for (p=boxes; p; ++p)
        if (boxes[p].colors>=2 && boxes[p].boxsize>minboxsize) 
          break;
      if (! p)
        break;
      // Find box boundaries
      PBox &splitbox = boxes[p];
      unsigned char pmax[3];
      unsigned char pmin[3];
      pmax[0] = pmin[0] = splitbox.data->p[0];
      pmax[1] = pmin[1] = splitbox.data->p[1];
      pmax[2] = pmin[2] = splitbox.data->p[2];
      { // extra nesting for windows
        for (int j=1; j<splitbox.colors; j++)
        {
          pmax[0] = umax(pmax[0], splitbox.data[j].p[0]);
          pmax[1] = umax(pmax[1], splitbox.data[j].p[1]);
          pmax[2] = umax(pmax[2], splitbox.data[j].p[2]);
          pmin[0] = umin(pmin[0], splitbox.data[j].p[0]);
          pmin[1] = umin(pmin[1], splitbox.data[j].p[1]);
          pmin[2] = umin(pmin[2], splitbox.data[j].p[2]);
        }
      }
      // Determine split direction and sort
      int bl = pmax[0]-pmin[0]; 
      int gl = pmax[1]-pmin[1];
      int rl = pmax[2]-pmin[2];
      splitbox.boxsize = (bl>gl ? (rl>bl ? rl : bl) : (rl>gl ? rl : gl));
      if (splitbox.boxsize <= minboxsize)
        continue;
      if (gl == splitbox.boxsize)
        qsort(splitbox.data, splitbox.colors, sizeof(PData), gcomp);
      else if (rl == splitbox.boxsize)
        qsort(splitbox.data, splitbox.colors, sizeof(PData), rcomp);
      else
        qsort(splitbox.data, splitbox.colors, sizeof(PData), bcomp);
      // Find median
      int lowercolors = 0;
      int lowersum = 0;
      while (lowercolors<splitbox.colors-1 && lowersum+lowersum<splitbox.sum)
        lowersum += splitbox.data[lowercolors++].w;
      // Compute new boxes
      newbox.data = splitbox.data + lowercolors;
      newbox.colors = splitbox.colors - lowercolors;
      newbox.sum = splitbox.sum - lowersum;
      splitbox.colors = lowercolors;
      splitbox.sum = lowersum;
      // Insert boxes at proper location
      GPosition q;
      for (q=p; q; ++q)
        if (boxes[q].sum < newbox.sum)
          break;
      boxes.insert_before(q, newbox);
      for (q=p; q; ++q)
        if (boxes[q].sum < splitbox.sum)
          break;
      boxes.insert_before(q, boxes, p);
    }
  // Fill palette array
  ncolors = 0;
  palette.empty();
  palette.resize(0,boxes.size()-1);
  { // extra nesting for windows
    for (GPosition p=boxes; p; ++p)
    {
      PBox &box = boxes[p];
      // Compute box representative color
      float bsum = 0;
      float gsum = 0;
      float rsum = 0;
      for (int j=0; j<box.colors; j++)
        {
          float w = (float)box.data[j].w;
          bsum += box.data[j].p[0] * w;
          gsum += box.data[j].p[1] * w;
          rsum += box.data[j].p[2] * w;
        }
      PColor &color = palette[ncolors++];
      color.p[0] = (unsigned char) fmin(255, bsum/box.sum);
      color.p[1] = (unsigned char) fmin(255, gsum/box.sum);
      color.p[2] = (unsigned char) fmin(255, rsum/box.sum);
      color.p[3] = ( color.p[0]*BMUL + color.p[1]*GMUL + color.p[2]*RMUL) / SMUL;
    }
  }
  // Save dominant color
  PColor dcolor = palette[0];
  // Sort palette colors in luminance order
  qsort((PColor*)palette, ncolors, sizeof(PColor), lcomp);
  // Clear invalid data
  colordata.empty();
  delete pmap;
  pmap = 0;
  // Return dominant color
  return color_to_index_slow(dcolor.p);
}
Ejemplo n.º 30
0
void GffLoader::load(GList<GenomicSeqData>& seqdata, GFValidateFunc* gf_validate, 
                          bool doCluster, bool doCollapseRedundant, 
						  bool matchAllIntrons, bool fuzzSpan, bool forceExons) {
	GffReader* gffr=new GffReader(f, this->transcriptsOnly, false); //not only mRNA features, not sorted
	gffr->showWarnings(this->showWarnings);
	//           keepAttrs   mergeCloseExons  noExonAttr
	gffr->readAll(this->fullAttributes,    this->mergeCloseExons,  this->noExonAttrs);
	GVec<int> pseudoAttrIds;
	GVec<int> pseudoFeatureIds;
	if (this->noPseudo) {
		GffNameList& fnames = gffr->names->feats;
		for (int i=0;i<fnames.Count();i++) {
			char* n=fnames[i]->name;
			if (startsWith(n, "pseudo")) {
				pseudoFeatureIds.Add(fnames[i]->idx);
			}
		}
		GffNameList& attrnames = gffr->names->attrs;
		for (int i=0;i<attrnames.Count();i++) {
			char* n=attrnames[i]->name;
			char* p=strifind(n, "pseudo");
			if (p==n || (p==n+2 && tolower(n[0])=='i' && tolower(n[1])=='s')) {
				pseudoAttrIds.Add(attrnames[i]->idx);
			}
		}
	}

	//int redundant=0; //redundant annotation discarded
	if (verbose) GMessage("   .. loaded %d genomic features from %s\n", gffr->gflst.Count(), fname.chars());
	//int rna_deleted=0;
	//add to GenomicSeqData, adding to existing loci and identifying intron-chain duplicates
	for (int k=0;k<gffr->gflst.Count();k++) {
		GffObj* m=gffr->gflst[k];
		if (strcmp(m->getFeatureName(), "locus")==0 &&
				m->getAttr("transcripts")!=NULL) {
			continue; //discard locus meta-features
		}
		if (this->noPseudo) {
			bool is_pseudo=false;
			for (int i=0;i<pseudoFeatureIds.Count();++i) {
				if (pseudoFeatureIds[i]==m->ftype_id) {
					is_pseudo=true;
					break;
				}
			}
			if (is_pseudo) continue;
			for (int i=0;i<pseudoAttrIds.Count();++i) {
				char* attrv=NULL;
				if (m->attrs!=NULL) attrv=m->attrs->getAttr(pseudoAttrIds[i]);
				if (attrv!=NULL) {
					char fc=tolower(attrv[0]);
					if (fc=='t' || fc=='y' || fc=='1') {
						is_pseudo=true;
						break;
					}
				}
			}
			if (is_pseudo) continue;
			//last resort:
			//  scan all the attribute values for "pseudogene" keyword (NCBI does that for "product" attr)
			/*
			 if (m->attrs!=NULL) {
				 for (int i=0;i<m->attrs->Count();++i) {
					 GffAttr& a=*(m->attrs->Get(i));
					 if (strifind(a.attr_val, "pseudogene")) {
						 is_pseudo=true;
						 break;
					 }
				 }
			 }
			 if (is_pseudo) continue;
			 */
		} //pseudogene detection requested
		char* rloc=m->getAttr("locus");
		if (rloc!=NULL && startsWith(rloc, "RLOC_")) {
			m->removeAttr("locus", rloc);
		}
		/*
     if (m->exons.Count()==0 && m->children.Count()==0) {
       //a non-mRNA feature with no subfeatures
       //add a dummy exon just to have the generic exon checking work
       m->addExon(m->start,m->end);
       }
		 */
		if (forceExons) {  // && m->children.Count()==0) {
			m->exon_ftype_id=gff_fid_exon;
		}
		//GList<GffObj> gfadd(false,false); -- for gf_validate()?
		if (gf_validate!=NULL && !(*gf_validate)(m, NULL)) {
			continue;
		}
		m->isUsed(true); //so the gffreader won't destroy it
		int i=-1;
		GenomicSeqData f(m->gseq_id);
		GenomicSeqData* gdata=NULL;
		if (seqdata.Found(&f,i)) gdata=seqdata[i];
		else { //entry not created yet for this genomic seq
			gdata=new GenomicSeqData(m->gseq_id);
			seqdata.Add(gdata);
		}
		/*
		for (int k=0;k<gfadd.Count();k++) {
			bool keep=placeGf(gfadd[k], gdata, doCluster, doCollapseRedundant, matchAllIntrons, fuzzSpan);
			if (!keep) {
				gfadd[k]->isUsed(false);
				//DEBUG
				GMessage("Feature %s(%d-%d) is going to be discarded..\n",gfadd[k]->getID(), gfadd[k]->start, gfadd[k]->end);
			}
		}
		*/
		bool keep=placeGf(m, gdata, doCluster, doCollapseRedundant, matchAllIntrons, fuzzSpan);
		if (!keep) {
			m->isUsed(false);
			//DEBUG
			//GMessage("Feature %s(%d-%d) is going to be discarded..\n",m->getID(), m->start, m->end);
		}
	} //for each read gffObj
	//if (verbose) GMessage("  .. %d records from %s clustered into loci.\n", gffr->gflst.Count(), fname.chars());
	if (f!=stdin) { fclose(f); f=NULL; }
	delete gffr;
}